Repository navigation
refactor(cron): finish worker-owned results and recovery - #169946
Conversation
|
🦞👀 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: blocked before merge. What this changesThis PR consolidates cron results and restart recovery in the worker while preserving opt-in execution identity audit links. Example: A one-shot scheduled for 12:00 becomes active, then the Gateway crashes before recording its result.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep open: this maintainer-directed PR completes a useful worker ownership cutover, and no definite introduced correctness defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherCron receives scheduled, manual, and event requests; the Gateway executes committed requests, and the worker records job state, history, and terminal receipts before publishing results. flowchart LR
A[Run requests] --> B[Cron worker]
B --> C[Gateway launcher]
C --> D[Run executor]
D --> B
B --> E[SQLite state and history]
B --> F[Views and notifications]
Technical reviewBest possible solution: Complete the single worker owner for results and recovery while preserving permission checks and the accepted no-replay policy. Do we have a high-confidence way to reproduce the issue? This is an ownership refactor; current-main source retains the paths being replaced, and inspected tests cover terminal idempotency, restart recovery, and public run lookup without being executed during this review. Is this the best way to solve the issue? The implementation follows the approved staged design by removing competing accounting paths and retaining live permissions with their existing owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4ba65fccf9bc. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfacePR surface statistics unavailable: the file list is incomplete. 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 12, 2026, 10:57 AM ET / 14:57 UTC (Revision 2). |
Record execution, primary delivery, job state, and history in the worker. Restore recorded terminal outcomes on restart and interrupt uncertain runs without replaying payloads or delivery. Remove receipt settlement, foreign monitoring, execution binding, and obsolete recovery protocols. Preserve permission provenance and live effect checks. Post-run notifications remain asynchronous and cannot undo committed terminal accounting. Refs #168072
0e7320e to
ca1b2fe
Compare
…er (openclaw#169946) Final PR of the cron worker-owned redesign (docs/refactor/cron-worker-owned.md): one worker-owned terminal handler records execution and primary-delivery outcome, updates job and history, and emits post-run notifications without commit guards; restart recovery restores recorded results once and marks uncertain runs interrupted without replaying payloads or delivery. Nonce settlement, receipt binding/observation plumbing, foreign-receipt monitoring and host recovery orchestration are deleted. Opt-in audit execution bindings for scheduled runs are preserved through the existing store. Production -2,076 LOC (program total -5,542). Refs openclaw#168072.
What Problem This Solves
Cron completion and restart recovery still had competing host-side receipt settlement and recovery paths after scheduling moved to the worker.
Refs #168072.
User Impact
Execution and primary-delivery outcomes are recorded with job state and history. On restart, recorded terminal results are restored once; uncertain active runs are interrupted without replaying their payload or delivery. Timed queued requests can resume; requests whose transient payload was lost are recorded as skipped. Manual run IDs remain available for exact history lookup.
This deliberately accepts a potentially missed occurrence after a crash to avoid uncertain payload or delivery replay. There are no schema, configuration, CLI-option, dependency, or permission changes. Existing task, transport, heartbeat, and permission owners retain their live-effect checks and provenance.
Why This Change Was Made
The worker owns terminal accounting and startup recovery in synchronous transactions. The host publishes committed facts and dispatches post-run notifications asynchronously. Receipt custody, nonce settlement, receipt-authority binding, foreign-receipt monitoring, obsolete registrations, and private protocol tests are removed together. Completion preserves newer job edits and settles the next deadline before publishing the finished event. Shutdown joins owned work and reports cleanup failures as warnings. A lost finalization reply invalidates public views without replaying execution.
Execution-identity audit coverage is preserved: after admission, the launcher records one opt-in context/execution link to the existing receipt through the worker and existing lazy binding store. The first admitted execution keeps that diagnostic link; duplicate trigger/payload admissions cannot replace it. Failed writes warn without aborting execution. Disabled/default collection allocates neither a binding table nor rows. Readers and deletion retain their existing contract; no receipt authority or settlement machinery is restored. Gateway handoff and shutdown proof remains at the real boundary, including the terminal worker command. The rebase preserves main's independent test pruning and removal of the generic reader capture helper. UI and the general SQLite admission mechanism are untouched.
Evidence
0e7320ea873d: 139/139 files and 1,274/1,274 tests passed, no unrun files and no reruns.node scripts/run-vitest.mjs <selected audit/cron/owner-sibling files> --maxWorkers=1reported[test] passed 6 Vitest shards in 1250.50s; wall time was 1251.19 s. Shared runtime build took 268.7 s (tsdown 244.5 s); the longest reported individual test was 12.223 s. Shards: unit 11 files/89 tests/17.77 s; Gateway 4/107/63.63 s; infrastructure 14/176/95.15 s; cron 106/866/449.97 s; Doctor 1/18/118.49 s; E2E 3/18/59.76 s. Doctor test bodies totaled 100.701 s. All 17 audit files, the new scheduled-run identity regression, and direct/one-barrel owner siblings were included. The plugin-reload cases passed in this order; that is current-run proof, not a fix for the independently reproduced admission leak below.f458771780dd1384163965c1d81e330010e8e65b: preserved main's no-write history-maintenance fast path and this PR's removal of receipt-owner filtering. Removed the retiredlocallyOwnedReceiptIdsfield from main's new maintenance fixture. All 6 affected history/maintenance/RPC/audit-link files passed all 40 tests in 154.09 s (Gateway 21 tests/116.05 s; cron 19/27.88 s). Core types, cron test types, targeted lint, and Madge passed again. No UI or unrelated owner edits were introduced.0 runtime value cycle(s)). Independent Codex review found no actionable P0/P1 issues. No schema definition, UI, dependency, config option, or CLI option changed.[email protected]→ candidate worker recovery passed in 26.43 s. Recorded history was restored once, uncertain runs were interrupted, and a lost queued payload was skipped. Cron/task table definitions stayed unchanged through the existing shared-state 20→21 migration. Backup rollback plus the released SDK reader passed in 2.90 s; original rows and schema hash matched exactly. This covers copied-database recovery/rollback, not a full installed-updater campaign.4d440abc91932aacd17a193a1467ba005405fcd3and installing its frozen dependencies, the six conflict-affected suites passed all 83 tests in 55.53 s wall (16.31 s compiler preparation). No test exceeded 30 s. Post-rebasepnpm tsgo:coreand targeted lint for all six affected files passed (exit 0). The upstream fs-safe pin required refreshing this worktree's private installation; this PR changes no dependency file.check:changedpassed its preceding guards, production types, all 28 dependent core-test graphs, root test types, formatting, coercion, and deprecated-API checks. It stopped at eight inherited Knip exports: two in unchangedsrc/config/sessions/session-accessor.transcript.tsand six in unchanged UI files. Running the downstream plan separately passed 10/11 steps; full-core lint reported 14 errors in unchanged files (13 line limits and one UI promise handler), none in changed files. No unrelated owner, baseline, ignore, or suppression was edited. Madge: zero import cycles.git diff --checkpassed. Independent Codex review completed; index-only conflict-resolution findings were corrected by staging the restored, tested files. No actionable findings remain.The identical 126-path selection on pristine base
1589da87911da73ab5cba9f21658f67166fb8b2breproduced the same fivetrigger-script.plugin-reloadfailures. Both runs reached the same 116 files before stopping; base passed 1,068 tests across 115 files, with only that plugin-reload file failing. Its cron group passed 911/916 tests in 457.82 s; the complete base command took 675.94 s. An optional JSON-reporter attempt stopped before cron on unsupported Gateway project configuration and is excluded from product evidence; the normal-reporter rerun kept the exact selection.Inherited leak → L1562: the candidate diagnostic reports
ERR_WORKER_OUT_OF_MEMORYbefore any tool effect. Base assertions omit the underlying error but reproduce the same five rapid, pre-effect failures. The admission publisher, Code Mode worker, and non-isolated runner are byte-identical between base and candidate. Real closed SQLite databases retain records published throughsetEnvironmentData: 300 closed databases produce 41,470,200 JSON bytes and exhaust the actual worker's 60 MiB old + 4 MiB young heap before readiness. Retiring those owned records restores startup at 21.4 MB heap. The isolated reproducer uses task-created databases; no heap increase or admission bypass was applied. The campaign lead assigned the generic admission fix to L1562.Physical line accounting separates test fixtures/harnesses from production. This PR: production +904 / -2,980 = -2,076 net (3,884 changed production lines); tests/support +1,425 / -5,886 = -4,461 net. The audit-coverage correction adds 140 net production lines and 63 net test/support lines.
Retired result/recovery-path checks both return no matches:
Cron terminal-result and restart-recovery owners have no commitGuard, revocation-generation, or nonce-settlement path. A whole-cron grep still finds the intentionally retained live caller/device, task, session, heartbeat, self-removal, and tool-permission guards; these are effect/permission checks, not terminal accounting. The restored audit link is diagnostic metadata only.