Skip to content

refactor(tasks): unify the shared task run registry#57324

Merged
vincentkoc merged 5 commits intoopenclaw:mainfrom
vincentkoc:refactor/task-run-registry
Mar 29, 2026
Merged

refactor(tasks): unify the shared task run registry#57324
vincentkoc merged 5 commits intoopenclaw:mainfrom
vincentkoc:refactor/task-run-registry

Conversation

@vincentkoc
Copy link
Copy Markdown
Member

Summary

  • simplify the shared task registry into a minimal task-run ledger
  • register cron execution attempts in the shared task registry alongside ACP, subagents, and background CLI runs
  • remove unreleased legacy task-registry aliases and update status/CLI/test coverage to the new contract

Testing

  • pnpm test -- src/tasks/task-registry.test.ts src/tasks/task-registry.store.test.ts src/commands/tasks.test.ts src/acp/control-plane/manager.test.ts src/gateway/server-methods/agent.test.ts src/cron/service/ops.test.ts src/cron/service/timer.test.ts
  • pnpm check
  • pnpm build

@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling labels Mar 29, 2026
@vincentkoc vincentkoc self-assigned this Mar 29, 2026
@openclaw-barnacle openclaw-barnacle bot added size: M maintainer Maintainer-authored PR labels Mar 29, 2026
@vincentkoc vincentkoc marked this pull request as ready for review March 29, 2026 22:57
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 29, 2026

Greptile Summary

This PR unifies the shared task-run registry by simplifying the schema (removing source/bindingTargetKind, adding sourceId/parentTaskId/agentId/cleanupAfter), renaming status values (accepted→queued, done→succeeded), and integrating cron job executions (scheduled, startup-catchup, and manual) into the registry alongside ACP, subagent, and background CLI runs. The changes are broadly consistent across all callers and the type contract is tightly updated.

  • The core task-registry.ts and task-registry.types.ts changes are clean and well-structured; normalizeTaskStatus provides a safe fallback for stored records that carry old status strings.
  • The three cron task-record paths in timer.ts (onTimer, runStartupCatchupCandidate) and the applyOutcomeToStoredJob update are correctly implemented — timer.ts uses isAbortError to normalise the error text before comparing for the timeout case.
  • ops.ts (manual-run path) has a bug: the catch block stores String(err) which for new Error("cron: job execution timed out") produces "Error: cron: job execution timed out", but the subsequent status mapping compares against the bare string "cron: job execution timed out" — so any manual cron run that times out will be recorded as status: "failed" instead of "timed_out".
  • Tests were updated consistently, but no test exercises the timed_out status path through finishPreparedManualRun, leaving the bug uncovered.

Confidence Score: 4/5

Mostly 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 failed instead of timed_out because String(err) on an Error object includes the "Error: " prefix that the string comparison does not account for. All other changes are consistent and well-tested.

src/cron/service/ops.ts — specifically the catch block in finishPreparedManualRun and the subsequent updateTaskRecordById status mapping.

Important Files Changed

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@vincentkoc vincentkoc merged commit 53bcd57 into openclaw:main Mar 29, 2026
8 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +955 to 958
task.status === "succeeded" ||
task.status === "failed" ||
task.status === "timed_out" ||
task.status === "lost" ||
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@aisle-research-bot
Copy link
Copy Markdown

aisle-research-bot bot commented Mar 30, 2026

🤖 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. ⌛
We'll post the results here as soon as they're ready.

Progress:

  • Analysis
  • Finalization

Latest run failed. Keeping previous successful results. Trace ID: 019d3bea11b76b1891c5f85f1f1f89bf.

Last updated on: 2026-03-30T09:47:42Z

pritchie pushed a commit to pritchie/openclaw that referenced this pull request Mar 30, 2026
* 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
alexjiang1 pushed a commit to alexjiang1/openclaw that referenced this pull request Mar 31, 2026
* 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
pgondhi987 pushed a commit to pgondhi987/openclaw that referenced this pull request Mar 31, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations gateway Gateway runtime maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant