Repository navigation
fix(gateway): cancelled tasks no longer continue running - #118358
Conversation
|
Codex review: blocked before merge. Reviewed September 4, 2026, 11:49 PM ET / September 5, 2026, 03:49 UTC. ClawSweeper reviewWhat this changesMakes ordinary Gateway task cancellation stop the exact agent run, wait for completion, and preserve its final diagnostic. Merge readiness⛔ Blocked before merge - 3 items remain This remains a useful fix: current main and the latest release retain the false-success cancellation path. Prior runtime findings are addressed; one operator-documentation mismatch remains. Priority: P1 Review scores
Verification
How this fits togetherThe task ledger records work executed by the Gateway. CLI and API cancellation requests now reach the live execution owner, which aborts the run and its approvals before confirming the task outcome. flowchart TD
A[CLI or API cancellation] --> B[Task access check]
B --> C[Task ledger]
C --> D{Exact live owner exists?}
D -->|No| E[Refuse with diagnostic]
D -->|Yes| F[Abort run and approvals]
F --> G[Wait for producer completion]
G --> H[Report confirmed outcome]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +158, Tests +351. Total +509 across 28 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep producer-owned cancellation with matching operator guidance; durable task rows alone cannot supply the live-owner binding or completion join that justify the production growth. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main and v2026.9.1 skip live cancellation for ordinary CLI tasks and can mark them cancelled anyway. The supplied before/after runs corroborate this; this read-only review did not execute them. Is this the best way to solve the issue? Yes for the runtime repair: the producer owns both exact-run authority and actual completion. Registry-only updates cannot establish cancellation, and session-wide abort would target unrelated work; the operator documentation still needs alignment. Full review comments:
Overall correctness: patch is correct AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cc7261dfacce. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
This pull request has been automatically marked as stale due to inactivity. |
…cel-session-lanes # Conflicts: # src/gateway/health/types.ts # src/gateway/server-methods/tasks.test.ts # src/gateway/server-methods/tasks.ts # src/process/command-queue.ts
…cel-session-lanes
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…aw#118358) Preserve contributor ancestry while integrating current main. Route ordinary task cancellation through the producer-bound abort owner and confirm actual settlement before reporting success. Keep background command cancellation with its existing owner. Co-authored-by: Ayaan Zaidi <[email protected]>
…enclaw#118358) Integrate current main's received-work lifetime owner. Return the same producer completion promise used by task cancellation so Gateway shutdown joins execution and its cleanup. Co-authored-by: Ayaan Zaidi <[email protected]>
…8358) Carry the producer's redacted terminal diagnostic with the existing private result metadata. Preserve the SDK outcome carrier and JSON response shape while finalizing tracked failures and timeouts. Cover store reload, cancellation settlement timeout, and diagnostic propagation. Direct ownerless cancellation to task audit without changing reconciliation policy. Co-authored-by: Ayaan Zaidi <[email protected]>
…law#118358) Use the existing deferred helper for the configured TypeScript library and complete the content-phase Gateway context fixture. Keep product behavior and assertions unchanged. Co-authored-by: Ayaan Zaidi <[email protected]>
Integrate current main and migrate its new cancellation test to the canonical abort-operations module. Preserve main attachment cleanup behavior and source credit. Co-authored-by: Ayaan Zaidi <[email protected]>
Replace the stale registry-only description with exact live-run cancellation, settlement confirmation, and existing ownerless-task recovery guidance. Co-authored-by: Ayaan Zaidi <[email protected]>
|
Thanks @peter3n! Landed in 0d84b12e65e1, with Peter retained as primary author and Ayaan credited as co-author. Proof: real packaged Gateway and CLI cancellation, real agent/tool work, approval cleanup, stale-approval refusal, and completed unrelated and subsequent work.
Runtime proof and all 777 focused tests passed at ac9113ae. The final a11633d9 changes only the guide; it has a fresh clean P0 review and green exact-head CI. The late documentation finding is fixed. The unrelated ClawHub mirror-anchor mismatch remains recorded in the PR evidence; it is not represented as a passing full anchor audit. |
* origin/main: fix(gateway): keep webhook ingress retryable during hot reload (openclaw#138627) fix: restore Gateway restarts after Git updates (openclaw#138781) fix(gateway): stop repeated teardown after WebSocket failures (openclaw#138818) fix(gateway): abort exact live runs when cancelling tasks (openclaw#118358) refactor(memory): share typed embedding-cache writes (openclaw#138827) fix(a2a): preserve tasks while reserving commands for users (openclaw#138731) feat: tune inbound batching without reconnecting channels (openclaw#138780)
Require offline CLI cancellation to fail visibly without mutating persisted state. Exercise authenticated RPC and CLI cancellation against a real held provider request, preserve cancellation provenance, and verify later heartbeat work succeeds. Follow up the execution ownership repair in #118358.
…18358) Bind ordinary Gateway-owned tasks to their exact live producer, use the canonical abort owner, and confirm actual settlement before reporting cancellation. Preserve background-command ownership, cancellation reasons, requester access, and unrelated work. Remove the incoming monitoring expansion and duplicate CLI result handling. Retain the contributor's original ancestry and current-main execution-lifetime ownership. Carry the producer's redacted failure and timeout diagnostics through task settlement without changing the existing SDK outcome carrier or JSON response. Verified with real packaged Gateway and CLI red/green, real model/tool execution, approval cleanup and stale-approval refusal, concurrent and subsequent work, background-command cancellation, and retained crash/upgrade recovery. Runtime validation passed all 777 focused tests across 22 files, including the new main caller and the command case previously blocked by disk capacity. The final guide-only correction leaves those runtime inputs unchanged and documents the verified cancellation and recovery behavior. Co-authored-by: Ayaan Zaidi <[email protected]>
…#139135) Require offline CLI cancellation to fail visibly without mutating persisted state. Exercise authenticated RPC and CLI cancellation against a real held provider request, preserve cancellation provenance, and verify later heartbeat work succeeds. Follow up the execution ownership repair in openclaw#118358.
What Problem This Solves
Cancelling an ordinary Gateway-owned agent task could report success while its real run and foreground command continued. The CLI excluded all
clitasks from Gateway cancellation. The shared registry then changed the task record without aborting the run.Why This Change Was Made
The Gateway producer now binds the task to its exact live run owner. The shared task canceller uses that capability, reuses the canonical chat-abort operation, and waits for the producer's actual completion before confirming cancellation.
The binding checks task scope, session, controller, operational instance, lifecycle generation, and current authority. A copied run ID cannot select replacement work. Early lifecycle events cannot finish the task record before the producer settles. Gateway shutdown joins the same completion promise.
The CLI now reaches that shared Gateway path and uses one result formatter. Background commands keep their existing process-control owner. The incoming health and lane-age additions were removed.
The producer also carries its final redacted diagnostic with the existing private result metadata. Failed and timed-out tracked tasks retain that diagnostic after settlement. The existing SDK outcome carrier and JSON response shape stay unchanged.
User Impact
For records left behind by a crash or upgrade, keep the Gateway running so its existing maintenance pass can reconcile missing live CLI contexts as lost. Use
openclaw tasks auditandopenclaw tasks maintenanceto inspect the result. Offline maintenance does not guess Gateway liveness. See task maintenance.Evidence
Baseline:
d3adc01d75e2b189732bd4d86c6b3be3cfa7e03e.Current source head:
a11633d9101a6b2e170f263d2cee0e761e591043.Runtime product-proof head:
ac9113aec97e32230207cc68bbff3f87d1970218.Integration base:
4311b45631b3f9aeee6a69e1a5b1e0a22cb17234.Retained crash/upgrade and deadline-diagnostic proof:
bbe8c7889ee58ccb22debfc3b65d9f97b6758cf8.Both sides used the real packaged Gateway, normal authentication, a real supported locally served model, and an owned workspace. Task, session, and run identities came from the shipped tasks API. The foreground calls actually used
execwithyieldMs: 120000,timeoutSeconds: 180, andbackground: false.openclaw tasks cancelAborted, ticks stopped, and the command never wrote its completion marker.tasks.cancelcancelled: true; the command wrote six more observed ticks, finished, and the agent repliedDONE./approvecommand was rejected as unknown or expired. The other approval remained valid, and its approved command completed.Earlier
bbe8c788approval flow: CLI cancellation removes the selected approval; its stale approval command is refused; the other approval remains usable and its command completes. Playback is 3×. The synthetic workspace path is redacted.task-cancellation-final-v2.mp4
Fresh
ac9113aeapproval proof: two pending approvals, selected cancellation, stale approval refusal, and the other approved request completing. Playback is 3×; the synthetic workspace row is redacted.task-cancellation-ac9113ae.mp4
The original failing CLI reproduction was preserved, not replayed during fixture corrections. Each valid package and each failed preparation attempt was retained. The current-main integration preserved the received-work lifetime owner from #136146 and received fresh package, test, and live verification.
The first CI correction used the canonical deferred helper and completed a sibling Gateway context fixture. The next CI run exposed a newly merged main test that imported the moved abort-operations helper from its old module. This head integrates that main change and updates the caller's import without a compatibility alias or media-policy change.
This integrated head received a fresh canonical package build and install. All 37,906 tracked source entries matched the exact commit before build and provider execution. Fresh live proof passed CLI and Gateway foreground cancellation, concurrent work, terminal/missing controls, same-session replacement, background exec, and two real approvals. The selected approval was cancelled; its stale command was refused; the other actual Allow once action completed its command and agent turn. Effective model context remained 32,768 tokens, with no serving-runtime truncation.
Regression and sibling checks: All 777 tests in 22 files passed on
ac9113ae. This includes the eight-case new-main attachment fixture and the managed-worktree snapshot case previously blocked by disk capacity. Earlier failed runs remain in the evidence history. One new test launch stopped before collection because the copied experimental test cache was stale after the lockfile changed; a fresh isolated cache fixed the harness setup without changing source or assertions. The canonical package build and integrity check passed separately.The final documentation-only follow-up corrects the cancellation contract in Background tasks. A full 37,906-entry source comparison confirms that only
docs/automation/tasks.mdchanged after the runtime proof. The prior package contains the prior guide text; it is not relabelled as the documentation head. Runtime source, dependencies, test code and proof inputs are unchanged.pnpm docs:list, the full MDX check (752 files), and pinned formatting passed. The anchor audit resolved the changed task link; its one remaining failure is the external ClawHub-derived/clawhub/cli#package-transfer-namelink, outside this diff. This separate mirror-anchor mismatch is retained as a follow-up, not reported as a passing full anchor audit.The cancellation regression first failed on baseline because the real dispatch controller was not aborted. Three diagnostic cases separately failed for missing task errors, then passed after the producer-owned repair. Coverage includes delayed settlement, completion winning the race, changed task/session/controller/entry/lifecycle/authority, retained callbacks, replacement-owner cleanup, store reload, settlement timeout, and callback-secret redaction without changing JSON. Malformed-association cases are owner-boundary fault-injection tests, not seeded-row live demonstrations.
Verification commands and scope
Run in an isolated Linux environment with Node 24 and a private test cache; private artifact destinations are omitted below. This command is the current integrated-head suite.
pnpm check:import-cycles: zero runtime value cycles.git diff --check: passed.d534c751d442d5a1d293460b7922bab0e936b3f33ae08c275fc3453c51cd868a.ClawSweeper disposition: All three current rank-up moves are addressed: producer-owned diagnostics with tracking-enabled red/green tests; real cancellation and ownerless upgrade recovery; and integration with main's execution-lifetime owner. Store-reload and settlement-timeout controls cover the lifetime risks. The prior background-exec, exact-instance binding, and cancellation-reason findings are also addressed. The old malformed historical receipt is not relied upon.
The stored-data warning points to
task-registry.process-state.ts, butrunOwnersis an in-processMap, not serialized state. It is not restored after restart. The real upgrade control demonstrates that a persisted old task does not regain cancellation authority. No durable field, schema, migration, or maintenance policy was added.The 02:55 UTC review's external-helper inspection gap is resolved: the actual installed
@openclaw/fs-safe0.7.2 source and types were read directly.withTimeoutraces the original producer promise against a rejecting timer and clears that timer infinally; it does not synthesize completion or cancel the original promise. The settlement-deadline regression confirms that an unsettled producer cannot return cancellation success. The review reports no actionable code finding and itself confirms that no stored model was introduced; its repeated migration checklist is not an additional schema change.The latest 03:49 UTC review's late P3 and rank-up move are addressed: the guide now documents the running Gateway requirement, exact-run and approval shutdown, confirmed settlement, honest refusals and existing audit/maintenance recovery. Its independent access limitation for the helper and videos does not invalidate the retained inspected source, recordings and real results.
Size and ownership: production +249/−93 (net +156); tests/support +449/−96 (net +353); docs +4/−2, relative to the integration base. Two reset-only lines in a production file are classified as test support; moved abort construction is neutral in the net count. The new capability binds a durable task to its live producer and confirmed completion, neither of which a task row or run ID alone provides. Private producer diagnostics preserve the existing terminal result while delayed settlement prevents false cancellation success. Duplicate CLI result handling was removed, and abort-operation construction was moved without a compatibility alias.
Original report and contributor work: @peter3n. The original commits remain in the branch ancestry. AI-assisted repair and verification.