refactor(cron): split main and detached dispatch#57482
Conversation
Greptile SummaryThis PR refactors the cron and agent task-lifecycle wiring in two complementary directions: (1) it introduces a Key points:
Confidence Score: 5/5Safe to merge — all findings are P2 style/observability concerns with no impact on runtime correctness. All detected issues are P2: one duplicated helper function and one silently-dropped field that is a no-op in practice. No logic regressions, security issues, or data-integrity problems were found. The refactoring is well-structured and backed by new unit and integration tests. src/cron/service/timer.ts and src/cron/service/ops.ts share a duplicated createCronTaskRunId helper that should be extracted.
|
| Filename | Overview |
|---|---|
| src/tasks/task-executor.ts | New thin façade over task-registry: provides named, intent-revealing helpers and bakes in the success/failure status split so callers never pass raw status strings. |
| src/tasks/task-executor-policy.ts | Pure extraction of policy/formatting functions from task-registry.ts; function bodies are identical to what was removed. |
| src/cron/service/timer.ts | Switches to task-executor helpers and extracts executeMainSessionCronJob/executeDetachedCronJob. createCronTaskRunId is duplicated with ops.ts. |
| src/cron/service/ops.ts | Parallel refactoring of the manual-run path with correct ok/skipped→complete and error/timeout→fail routing. createCronTaskRunId duplicated from timer.ts. |
| src/agents/subagent-registry-lifecycle.ts | Terminal update split correctly into completeTaskRunByRunId/failTaskRunByRunId; startedAt: entry.startedAt silently dropped (currently a no-op). |
Comments Outside Diff (1)
-
src/agents/subagent-registry-lifecycle.ts, line 226-244 (link)startedAtsilently dropped on terminal updateThe previous call to
markTaskTerminalByRunIdincludedstartedAt: entry.startedAt, which allowed the terminal write to backfill thestartedAtfield if it differed from what was stored at creation time. NeithercompleteTaskRunByRunIdnorfailTaskRunByRunIdexposes astartedAtparameter, so this field is now silently dropped.In practice the task record is created with the same
startedAtvalue insubagent-registry-run-manager.ts, so there should be no observable delta today. But this is a silent narrowing of the API: callers that previously relied on terminal-time correction ofstartedAtcan no longer do so through the new helpers. Worth noting in a comment or ensuring neither helper needs to acceptstartedAtfor future use cases.Prompt To Fix With AI
This is a comment left during a code review. Path: src/agents/subagent-registry-lifecycle.ts Line: 226-244 Comment: **`startedAt` silently dropped on terminal update** The previous call to `markTaskTerminalByRunId` included `startedAt: entry.startedAt`, which allowed the terminal write to backfill the `startedAt` field if it differed from what was stored at creation time. Neither `completeTaskRunByRunId` nor `failTaskRunByRunId` exposes a `startedAt` parameter, so this field is now silently dropped. In practice the task record is created with the same `startedAt` value in `subagent-registry-run-manager.ts`, so there should be no observable delta today. But this is a silent narrowing of the API: callers that previously relied on terminal-time correction of `startedAt` can no longer do so through the new helpers. Worth noting in a comment or ensuring neither helper needs to accept `startedAt` for future use cases. How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/cron/service/timer.ts
Line: 127-129
Comment:
**Duplicated helper in `ops.ts`**
`createCronTaskRunId` is defined identically in both `src/cron/service/timer.ts` and `src/cron/service/ops.ts` (line 389). If the run-ID format ever needs to change (e.g. adding a counter for jobs that fire more than once per millisecond), both copies must be updated in lockstep, creating a silent divergence risk.
Consider extracting this to a shared module — e.g. a `cron-run-id.ts` utility or placing it in `jobs.ts` — and importing it in both files.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/subagent-registry-lifecycle.ts
Line: 226-244
Comment:
**`startedAt` silently dropped on terminal update**
The previous call to `markTaskTerminalByRunId` included `startedAt: entry.startedAt`, which allowed the terminal write to backfill the `startedAt` field if it differed from what was stored at creation time. Neither `completeTaskRunByRunId` nor `failTaskRunByRunId` exposes a `startedAt` parameter, so this field is now silently dropped.
In practice the task record is created with the same `startedAt` value in `subagent-registry-run-manager.ts`, so there should be no observable delta today. But this is a silent narrowing of the API: callers that previously relied on terminal-time correction of `startedAt` can no longer do so through the new helpers. Worth noting in a comment or ensuring neither helper needs to accept `startedAt` for future use cases.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Merge branch 'main' into pr5/cron-target..." | Re-trigger Greptile
| function createCronTaskRunId(jobId: string, startedAt: number): string { | ||
| return `cron:${jobId}:${startedAt}`; | ||
| } |
There was a problem hiding this comment.
createCronTaskRunId is defined identically in both src/cron/service/timer.ts and src/cron/service/ops.ts (line 389). If the run-ID format ever needs to change (e.g. adding a counter for jobs that fire more than once per millisecond), both copies must be updated in lockstep, creating a silent divergence risk.
Consider extracting this to a shared module — e.g. a cron-run-id.ts utility or placing it in jobs.ts — and importing it in both files.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cron/service/timer.ts
Line: 127-129
Comment:
**Duplicated helper in `ops.ts`**
`createCronTaskRunId` is defined identically in both `src/cron/service/timer.ts` and `src/cron/service/ops.ts` (line 389). If the run-ID format ever needs to change (e.g. adding a counter for jobs that fire more than once per millisecond), both copies must be updated in lockstep, creating a silent divergence risk.
Consider extracting this to a shared module — e.g. a `cron-run-id.ts` utility or placing it in `jobs.ts` — and importing it in both files.
How can I resolve this? If you propose a fix, please make it concise.* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor * refactor(cron): split main and detached dispatch
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor * refactor(cron): split main and detached dispatch
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor * refactor(cron): split main and detached dispatch
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor * refactor(cron): split main and detached dispatch
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor * refactor(cron): split main and detached dispatch
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor * refactor(cron): split main and detached dispatch
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor * refactor(cron): split main and detached dispatch
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy * refactor(tasks): route acp through executor * refactor(tasks): route subagents through executor * refactor(cron): split main and detached dispatch
Summary
Testing