feat(scheduler): add complete run lifecycle APIs#320
Conversation
|
PR Title: feat(scheduler): add complete run lifecycle APIs Commit: 本次PR增加了完整的调度器运行生命周期管理,核心变化包括:
整体代码结构清晰,测试覆盖较充分,但存在个别可靠性和边界处理问题需要关注。 |
|
PR Title: feat(scheduler): add complete run lifecycle APIs Commit: 该 PR 是一个术语修正提交,将 CLI 中调度器运行相关 flag 的说明与错误信息里的 "Deprecated" 统一改为 "Unsupported for complete scheduler runs"。 修改范围:
整体评估:这是一次纯粹的消息/命名重构,行为未发生实质性变化。所有字符串替换在三个文件内保持一致,测试覆盖也同步跟进,未发现遗漏或编译风险。 |
| RunID string `json:"run_id"` | ||
| } | ||
|
|
||
| func encodeSchedulerRunCursor(projectID, agentName string, run domain.LoaderRunSummary) string { |
There was a problem hiding this comment.
encodeSchedulerRunCursor 忽略 json.Marshal 错误,可能导致生成无效分页游标
encodeSchedulerRunCursor 在编码游标时使用了 payload, _ := json.Marshal(...) 忽略 json.Marshal 的错误。虽然当前结构体在正常情况下不会序列化失败,但如果未来字段发生变化(例如引入不可序列化的类型),base64.RawURLEncoding.EncodeToString 可能会收到 nil 或空字节切片,生成无效的空游标字符串,导致分页中断且难以排查。
Problem code:
Changed code at pkg/agentcompose/api/scheduler_run_cursor.go:21-25
Recommendation:
显式检查 json.Marshal 的错误,并在出错时返回空字符串或记录日志,避免静默生成无效游标:
payload, err := json.Marshal(...)
if err != nil {
return ""
}
return base64.RawURLEncoding.EncodeToString(payload)
| } | ||
|
|
||
| func (s *schedulerRunSupervisor) Get(ctx context.Context, loaderID, runID string) (domain.LoaderRunSummary, error) { | ||
| if s.deps.Store == nil { |
There was a problem hiding this comment.
scheduler_run_supervisor.execute 未使用 defer 清理 goroutine,panic 时导致 channel 阻塞和资源泄露
execute 方法在 goroutine 中直接调用 s.deps.Execute,之后手动 close(active.done) 和 s.unregister。如果 Execute 发生 panic(或未来引入 panic recovery),active.done 不会被关闭,Run 和 Stop 调用者将永久阻塞在 <-active.done 上;同时该活跃运行记录也永远无法从 s.active 中移除,造成内存泄露。
Problem code:
Changed code at pkg/loaders/scheduler_run_supervisor.go:130-136
Recommendation:
在 execute 中使用 defer 确保 active.done 始终被关闭、unregister 始终被执行。例如:
defer cleanup()
defer close(active.done)
defer s.unregister(prepared.Run.ID, active)
或者使用 defer + recover 组合,捕获 panic 后将 active.err 设置为 panic 信息,再关闭 channel 和清理注册表。
Summary
scheduler.agent()invocation an independent project run identityValidation
go test -count=1 ./cmd/agent-compose ./pkg/agentcompose/api ./pkg/storage/configstorego test -race -count=1 ./pkg/loadersgo test -count=1 ./cmd/agent-compose -run 'TestCLISchedulerExecutionRejectsUnsupportedFlags|TestRunComposeSchedulerTriggerRejectsUnsupportedPrompt|TestNormalizeComposeSchedulerTriggerOptionsPayload|TestE2ECLIHelpCoversUserWorkflowCommands'go build ./cmd/agent-compose