Repository navigation
fix(workers): cancel queued host callbacks at task deadlines - #167740
Conversation
Propagate task cancellation through history, usage, cold restoration, shared-state admission, and worktree effects. Name timed-out callbacks while keeping accepted native work under its settlement owner. Preserve independent coalesced openers and completed history authority. Record close receipts in the reply owner before caller settlement.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThe PR carries worker-task cancellation into queued database, history, usage, and worktree operations so expired requests stop waiting while accepted work finishes safely. Example: A database opening expires while another opening holds the worker reply.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR retains useful work beyond the merged deadline repair and the overlapping SQLite proposal. No concrete introduced defect was found; the latest fixture corrections preserve the existing safety assertions. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherOpenClaw workers request database and filesystem operations through callbacks in the main process. The worker scheduler supplies cancellation signals, while operation queues and resource owners control admission, settlement, and cleanup. flowchart TD
A[History or usage request] --> B[Worker task and deadline]
B --> C[Host callback with cancellation signal]
C --> D{Operation admitted?}
D -->|Waiting and canceled| E[Remove queued operation]
D -->|Already accepted| F[Resource owner settles work]
E --> G[Request completes and successor progresses]
F --> G
Technical reviewBest possible solution: Keep cancellation with the existing queue owners and preserve native settlement and cleanup after admission. Do we have a high-confidence way to reproduce the issue? Yes: current main’s opening and cold-restoration queues omit cancellation, and the held-reply and held-writer regressions exercise those paths. The PR records failing baseline controls and passing candidate results; this read-only review did not rerun them. Is this the best way to solve the issue? Yes: forwarding the existing task signal into established admission owners repairs dropped cancellation while preserving FIFO ordering, live authority, and accepted-operation settlement. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3223e13a514c. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +317, Tests +680, Docs +9, Other -1. Total +1005 across 70 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 9, 2026, 5:53 AM ET / 09:53 UTC (Revision 2). |
|
Final-head CI has one inherited test failure: The same assertion failed on unchanged main All task-caused CI failures are repaired and independently reviewed. The two corrected Gateway files pass all 23 tests; the final staged gate and 11 cold-storage siblings pass. Final-head CI reports 87 successful jobs and 23 skipped jobs, with only this test job and its aggregate red. Landing under the inherited-failure exception without rerunning CI. |
The cancellation-wait helper captured opening options in the same V8 context as cached SQLite client callbacks. Reusing a handle could keep completed callers and their admission authority alive for its lifetime. Move the wait outside that scope and reuse one actor binding. Preserve abort-reason identity, admission checks, and native settlement while the existing forced-GC regression still requires zero retained caller objects and reuse of the same store and actor. Follow-up to #167740.
Backport the worker-runtime and SQLite/shared-state cancellation portion of #167740 onto the release owners. Keep queued cancellation separate from accepted native settlement, preserve FIFO and independent coalesced callers, and retain cleanup custody. Carry cancellation through plugin-state and agent writes. Adapt the necessary deadline ownership contract from #167446 without importing its history refactor. Code Mode keeps its existing approval-aware host budget. Use structured operation labels for diagnostics; raw callback strings retain the worker-entrypoint fallback and never become log payloads. This is a selected backport, not full #167740 coverage: its newer ACP/worktree, history/usage and cold-restoration portions are deliberately not imported. Proof: 200 distinct tests across 10 files; original host-wait suspension fails all five deadline cases; donor raw-string labeling fails the payload case. Physical frozen install, worker-runtime build, core types, all 27 core test graphs, three zero-entry Knip scans, changed-source guards and scoped lint pass. Post-review diagnostic repair has fresh affected build/type/lint/test proof. Deadline ownership portion adapted from 486cdae. (cherry picked from commit 7dd2721) (cherry picked from commit b7984f6845f075a5f92825926632575bbcc0202c)
…w#167740) Propagate worker-task cancellation through queued host database, history, usage, cold-restoration, and worktree operations. Emit callback-specific timeout diagnostics while preserving accepted native effects and cleanup under their existing owners. Keep independent coalesced callers usable and retire abandoned successful opens. Repair the history revocation and ended-transcript fixtures to observe the active callback boundary without coupling to optional argument arity. Validation: 980 distinct tests across 81 files plus 20 closure checks, changed-source gates, export guard, and build passed on isolated remote validation. Full production and final fixture corrections passed independent review. Final-head CI had one independently reproduced inherited managed-Doctor readiness assertion; landed under the inherited-failure exception.
The cancellation-wait helper captured opening options in the same V8 context as cached SQLite client callbacks. Reusing a handle could keep completed callers and their admission authority alive for its lifetime. Move the wait outside that scope and reuse one actor binding. Preserve abort-reason identity, admission checks, and native settlement while the existing forced-GC regression still requires zero retained caller objects and reuse of the same store and actor. Follow-up to openclaw#167740.
What Problem This Solves
Fixes expired worker tasks leaving host callbacks queued for SQLite, history, usage, cold-restoration, and worktree operations. The pool deadline repair in #167446 bounds the worker task; several downstream handlers still dropped its abort signal before reaching their queue owners.
User Impact
Expired callbacks cancel waiting work and emit
WORKER_HOST_CALLBACK_TIMEOUTwith a bounded callback name. Accepted native writes and required cleanup keep their settlement ownership. Independent callers sharing an actor opening remain usable when its first caller cancels.No configuration, schema, dependency, or operator migration changes.
Why This Change Was Made
Carry the existing task signal through the remaining callback interfaces. Reuse the cancellable FIFO for cold restoration and broker opening, removing the uncancellable queue paths. Cancellation stops observations of shared retirement/preparation; their resource owners continue settling. Transient callback signals no longer become retained history authority, and abandoned successful opens still retire when idle.
The audit covers ten callback families. Existing transcript-index and report-generation network/store callbacks already forward signals. Synchronous hydration/catalog callbacks do not queue work; Code Mode retains its explicit approval-aware deadline owner. Prepared-runtime waits added on main follow the same cancellation/settlement boundary. Close receipts now publish in the validated reply owner before caller completion, removing the broker's forwarding adapter.
Production TypeScript delta is +317 lines. The requested non-test/non-doc path filter reports +320 (+4 README lines, −1 obsolete mock-baseline entry). Growth carries the existing cancellation contract through previously signal-free interfaces; there is no second scheduler or timeout manager.
Evidence
Validated staged source on base
3b3cd5939993f16017b6747cbcf80a83b49006ef, with source hashes checked before execution. Heavy checks ran on AWS Crabboxcbx_635d3f27917dand the authorized isolated Linux rig; none ran on the development Mac.node scripts/check-changed.mjs --stagedSetFilebirthtime case skipped on Linuxpnpm buildBefore-fix controls reproduce queued operations remaining pending after cancellation until the 30-second test guard, canceled work being admitted, and one opener's cancellation poisoning independent callers. Three prepared-runtime cases also fail on the current main implementation. The corrected cases reject before the held writer or retiring worker is released. Separate controls verify that ordinary and persistent storage failures still propagate. This measures cancellation behavior, not production CPU or throughput.
Focused wrapper wall times (
node scripts/run-vitest.mjs <files> --maxWorkers=1): the corrected lease file passed 14 cases in 43.02 s including worker-fixture compilation; the history/ACP/compute group passed 5 cases in 150.67 s including 92.9 s compilation. Real history/ACP test bodies cost 3.2–4.8 s, and compute cancellation 1.7 s; prepared-runtime cancellation bodies cost 2–3 ms. These use existing fixtures and deferred barriers, with no new timer sleeps or test files. Final-head CI is recorded below.AWS and the isolated rig were used after Blacksmith admission did not complete. Superseded and interrupted attempts are not counted as passing evidence.
Known follow-up: process-held history omits prepared subagent visibility facts from its worker protocol. A synthetic forwarded-child assertion fails identically on unchanged base
687e6e9d1a8a1c698f0a713c58f7e7dd6d6312a9. This change preserves existing display behavior and the original page/delta/SSE assertions. Live production was not modified or benchmarked. Custom host code must honor its signal; the pool cannot forcibly stop arbitrary host JavaScript.CI follow-through
The first PR run exposed two stale Gateway test fixtures. Cold restoration now uses the cancellable writer queue, so its revocation fixture now pauses the actual queued metadata read instead of spying on the retired queue. The ended-transcript fixture preserves its exact request, recipient, and output-size checks while allowing the optional signal argument.
AWS Crabbox
cbx_957137c80b84, runrun_aeb5b438f18389c7f65a774d471b5168, verified the follow-up source hashes and passed:node scripts/run-vitest.mjs ... --maxWorkers=1.node scripts/check-changed.mjs --staged: passed in 280 seconds, zero lint warnings/errors, both affected Gateway test-type graphs passed.Combined with unchanged-source proof above, 980 distinct tests across 81 files passed, plus the 20 closure checks. The follow-up changes tests only.
On unchanged CI main parent
21ecc39d75d46362b2717487c7dc49a90c7ddd21, both Doctor files reproduced the same resolved-instead-of-rejected failures, and the CLI-update type graph reproducedupdate-cli.windows-lifecycle.test.ts:508TS2554. The Doctor fixtures still expect rejection after main changed failed-readiness/running-service handling to warn and return. The Windows fixture calls a typed signal listener without its signal argument. These baseline failures are excluded from passing test counts. The final-head Windows type, legacy-updater, and assertion-ratchet jobs pass after independent main fixes.Final-head CI run 37913423324 tested
4c1e1059b9c85c910212e40973d0ded3784bf28cthrough mergedea79148c26992a08869a6e1ee5e5325cbae592fonto main3223e13a514c6134e10ee7f585627434d245fd20: 87 jobs succeeded, 23 were skipped, and the sole failing test job is the inherited managed-Doctorrestart-unhealthyassertion. The aggregate fails only for that job. All five relevant production/fixture files are byte-identical between the directly tested main baseline, CI main parent, and PR merge. Landing uses the inherited-failure exception; no CI rerun or unrelated repair is included.