refactor(tasks): unify the shared task run registry#57324
refactor(tasks): unify the shared task run registry#57324vincentkoc merged 5 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR unifies the shared task-run registry by simplifying the schema (removing
Confidence Score: 4/5Mostly safe to merge, but the ops.ts manual-run timeout path has a real status-mapping defect that should be fixed first. One P1 logic bug: manual cron runs that exceed their timeout are recorded as src/cron/service/ops.ts — specifically the catch block in
|
| Filename | Overview |
|---|---|
| src/cron/service/ops.ts | Adds task-record creation/update for manual cron runs, but the timeout-to-timed_out status mapping is broken because String(err) includes the "Error: " prefix that the string comparison does not expect. |
| src/cron/service/timer.ts | Adds task-record creation/update for scheduled and startup-catchup cron runs. Uses isAbortError to normalise the timeout message before storing, so the timed_out mapping is correct. |
| src/tasks/task-registry.ts | Core registry refactored: removes source/bindingTargetKind, adds sourceId/parentTaskId/agentId/cleanupAfter, renames accepted→queued and done→succeeded. normalizeTaskStatus provides a forward-compatible fallback for unrecognised values. |
| src/tasks/task-registry.types.ts | Type contract updated to the new unified ledger shape. Clean removal of old aliases; cron added to TaskRuntime; cleanupAfter field added to TaskRecord. |
| src/tasks/task-registry.maintenance.ts | Status rename (accepted→queued) applied; cleanupAfter field now respected in pruning logic before falling back to the generic retention window. |
| src/commands/tasks.ts | CLI display updated to reflect new field names and statuses; sourceId, result, parentTaskId, agentId, and cleanupAfter added to show output. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/cron/service/ops.ts
Line: 497-503
Comment:
**Timeout detection broken: `String(err)` includes `"Error: "` prefix**
`executeJobCoreWithTimeout` rejects with `new Error(timeoutErrorMessage())` on timeout. The `catch` block on lines 492–495 serialises this as `String(err)`, which produces `"Error: cron: job execution timed out"` — not the bare `"cron: job execution timed out"` string this comparison expects.
As a result, any manual cron run that times out will be recorded with `status: "failed"` instead of `status: "timed_out"`.
Compare how `timer.ts` handles the same situation: it uses `isAbortError(err) ? timeoutErrorMessage() : String(err)` to normalise the error message before storing it. The fix is to apply the same normalisation in the catch block:
```typescript
} catch (err) {
const errorText =
err instanceof Error && err.message === "cron: job execution timed out"
? err.message
: String(err);
coreResult = { status: "error", error: errorText };
}
```
Then the existing status mapping will correctly produce `"timed_out"` for timeout errors.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Merge branch 'main' into refactor/task-r..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d798d4f6ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 837882fe83
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fb12e4b52d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| task.status === "succeeded" || | ||
| task.status === "failed" || | ||
| task.status === "timed_out" || | ||
| task.status === "lost" || |
There was a problem hiding this comment.
Handle legacy
done status in task cancellation
cancelTaskById now only treats succeeded/failed/timed_out/lost/cancelled as terminal, but persisted task snapshots are still loaded as schema version 1 without status migration, so pre-refactor records with status: "done" remain possible after upgrade. In that state, canceling an already-finished task can incorrectly attempt runtime cancellation and then rewrite historical completion as cancelled, which corrupts task history for upgraded installs until old records age out.
Useful? React with 👍 / 👎.
|
🤖 We're reviewing this PR with Aisle We're running a security check on the changes in this PR now. This usually takes a few minutes. ⌛ Progress:
Latest run failed. Keeping previous successful results. Trace ID: Last updated on: 2026-03-30T09:47:42Z |
* refactor(tasks): simplify shared task run registry * refactor(tasks): remove legacy task registry aliases * fix(cron): normalize timeout task status and harden ledger writes * fix(cron): keep manual runs resilient to ledger failures
* refactor(tasks): simplify shared task run registry * refactor(tasks): remove legacy task registry aliases * fix(cron): normalize timeout task status and harden ledger writes * fix(cron): keep manual runs resilient to ledger failures
* refactor(tasks): simplify shared task run registry * refactor(tasks): remove legacy task registry aliases * fix(cron): normalize timeout task status and harden ledger writes * fix(cron): keep manual runs resilient to ledger failures
Summary
Testing