Repository navigation
refactor(cron): move scheduling into the worker actor - #169766
Conversation
Retain the shared state worker for cron timers and push versioned configuration between commands. Keep due selection, bounded catch-up, durable deferral, and CRUD schedule decisions with worker-owned rows; remove the host scheduling paths. Preserve completion-owned cadence and existing receipt recovery without a schema or public-option change. Refs #168072.
|
🦞👀 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 changes before merge. What this changesThis PR moves cron timers, catch-up planning, configuration snapshots, and job-edit decisions into the existing SQLite worker. Example: The Gateway starts with seven overdue command jobs.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Needs changes before merge - 3 items remain Keep this PR open: the approved worker consolidation is useful, but the previously reported startup-recovery regression remains unresolved. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherCron receives Gateway commands and configuration, persists jobs and run receipts in SQLite, and sends committed requests to the host launcher. flowchart LR
A[Gateway commands and configuration] --> B[Cron worker actor]
B --> C[SQLite jobs and receipts]
B --> D[Wake notification]
D --> E[Admitted host tick]
E --> B
B --> F[Host launcher]
F --> G[Task executor]
Technical reviewBest possible solution: Keep the worker as the sole scheduler while preserving automatic recovery after its initial startup write fails. Do we have a high-confidence way to reproduce the issue? Source establishes the failure path with an overdue command job, a future job, and a rejected initial catch-up or receipt write; this read-only review ran no reproducer. Is this the best way to solve the issue? Consolidating scheduling in the existing worker follows the approved design, provided initialization preserves the established failed-start recovery contract. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 70885c1bbbda. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
LabelsLabel changes: No label 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 (4 earlier review cycles)
Reviewed October 12, 2026, 7:38 AM ET / 11:38 UTC (Revision 5). |
Compare the same defined ownership facts across SQL rows and cached session snapshots. Preserve creator, workspace, and lifecycle checks while avoiding false admission conflicts from undefined optional metadata.
Merge main at 70885c1 while preserving worker-owned scheduling and main's prepared-session reuse optimization. Move completion maintenance coverage into the existing batch fixture. Keep runtime selection consistent with reported harness provenance and request the lifecycle facts used by real cron preparation in dispatch tests. All existing expected values and refusal assertions remain intact. Evidence: 189 cron files exercised (1568 tests); four fixture failures were reproduced and corrected. All four affected files then passed, 41 tests in 45.02s (51.54s wrapper). The other 187 files passed unchanged. Cron test types, focused lint, Madge (zero cycles), and isolated P0/P1 review pass. Manual edits remain in four cron test files; no production or UI repair. Refs #168072.
…169766) Cron PR 2b-ii of the worker-owned redesign (docs/refactor/cron-worker-owned.md): the cron worker now owns timers, catch-up, pacing, schedule computation and CRUD reconciliation; the host pushes config snapshots and launches committed requests. Host scheduling paths are removed. Also: mutation validation no longer loads delivery routing, pending deadlines survive the cutover, catch-up overflow settles after initial receipts, startup clears stale disabled deadlines, and cached snapshot metadata no longer reads as changed workspace authority. No schema, config or CLI change. Refs openclaw#168072.
What Problem This Solves
Cron scheduling and job edits still split decisions between the Gateway host and SQLite worker after the worker-owned run-queue cutover. This moves scheduling into the worker and repairs the CI failures that exposed incomplete timing, import-boundary, and session-authority cutovers.
Refs #168072.
Current head:
210b8139c7e2229fd77d76e1072d4bf1102c0e82.User Impact
Preserves cron timing, catch-up, pacing, retries, and job-edit behavior across Gateway restarts. Scheduled runs retain the creator’s stored workspace authority, including managed-worktree ownership and file containment. No schema/DDL, dependency declaration, public configuration, or CLI change. Doctor still backs up and preserves historical ownership before repair; ordinary startup clears obsolete disabled-job deadlines without rewriting owners.
The accepted crash semantics remain: a crash after activation but before dispatch may miss one occurrence, and one launch can race an operator disable. Transient event payloads lost across restart are recorded as skipped rather than reconstructed.
Why This Change Was Made
One retained worker actor owns timers, due-slot selection, bounded catch-up, durable deferral, and CRUD/declarative schedule decisions. The host pushes versioned configuration snapshots between commands and launches committed requests. The existing shared-state worker lease retains the actor and joins shutdown. Removed the host timer, catch-up, scheduler-mutation, and startup-plan paths.
The CI repairs keep mutation preparation independent of delivery routing, preserve pending deadlines during ordinary refresh, repair stale future slots on active ticks, and defer overflow until the initial catch-up receipts settle. Settlement clears an obsolete catch-up marker after a manual completion without changing its cadence. Configuration capture resolves a default owner only when needed and no longer replaces the service's accepted cron settings with unrelated global snapshots.
The latest authority repair keeps the complete session comparison and normalizes only absent optional fields. The initial worker read omitted
owner,participants, andparticipantCount; the newer creation-receipt cache returned the same absent values as explicitundefinedfields. Strict object comparison rejected that representation change before task execution. All defined creator, owner, workspace, and lifecycle fields remain compared. The existing end-to-end permission assertions are unchanged; the status assertion now includes the recorded run error. A focused regression models both reader representations and proves that an actual persisted workspace change still rejects admission.Tests that depended on removed host timer internals now drive the real worker notification listener or assert the worker's committed wake deadline. This applies to
timer.test.ts,service.timer-maintenance.test.ts,service.cross-tick-admission.test.ts, and the deferred one-shot indoctor-config-flow.cron-owners.test.ts. Timing, persistence, execution count, and admission assertions remain. Recovery tests now fail immediately if the run settles before its expected payload starts, instead of hanging for 120 seconds. The import-boundary test is unchanged. The additional lifecycle fixture now seeds valid disabled rows, and its spy cleanup runs even when a pending tick rejects; no responsiveness or reply-loss assertion was removed.Against base
ac5432479226a46259c303ad3a8907fc8ad310fe: production +1,949 / −1,847 (net +102; 3,796 changed lines); tests/support +1,548 / −717; docs/config +9 / −1. The only baseline change is deletion of the retired timer assertion. The campaign's net-negative production requirement is not met. Further removal of obsolete reservation and host-finalization machinery needs a separate, behavior-proven cutover; this repair does not claim that gate is complete.Evidence
Latest CI run
38237124225tested mergeff28a956c7feeb7e9d9fb8f449b087a88037bc80(tree6acbc8ba30e8b0f4a90ca6d0801a9704f92e87c0). The branch alone passed, so reproduced that exact merge in a disposable source fixture inside the assigned worktree, using Node 24.19.0. It reproduced both original workspace failures: 2 failed / 5 passed. Diagnostics showed identical stored values but three extraundefinedproperties in the cached entry. After the cron-only repair, 12/12 focused tests passed in 52.14s (55.88s wrapper), including all seven original workspace-authority cases. The disposable fixture was removed; no main integration or unrelated tracked edit was needed.New regression negative control: before the repair, identical authority presented with absent-versus-undefined fields fails admission; a real persisted workspace change also rejects. After repair, the identical-authority case passes and the changed-workspace case still rejects. Creator provenance, foreign-session denials, archived sessions, managed ownership, and file containment assertions remain intact. No permission was broadened and no assertion was weakened.
Final local proof: 52 isolated-agent files / 540 tests passed, plus the importing Gateway usage owner-attribution file 9/9 passed. Combined 53 files / 549 tests, 391.15s wall; cron Vitest duration 326.79s, Gateway duration 56.47s. The new regression owner file spent 19.421s in its five cases; the largest individual test in the complete run was 9.380s. An earlier eight-file CI-subset replay passed 153/153. Targeted cron types passed (8.6s), exact changed-file lint and format passed, final Madge reports 0 cycles, and a fresh isolated Codex repair review found no actionable P0/P1 findings.
The wrapper inventory failure is inherited: the full log names
src/config/sessions/transcript-entry-anchor.ts, newly imported bysession-accessor.sqlite-transcript-anchor.tson the tested main base. Main commit777e85c9eeceintroduced that runtime edge; main already fixes the inventory in9e4f18346b8d. This lane changes neither module nor the inventory.Latest
check:changed --base HEADpassed all preceding guards, production types, and all 28 core-test graphs (259.33s), then stopped at the same inherited dead exports:resolveEffectivePromptTokensandrenderPublicSessionCardSvg. Both files are unchanged by this lane. All nine trailing checks were run separately and passed, including exact changed-file lint, schema, storage, media, sidecar, runtime-cycle, and webhook/pairing checks. No baseline or unrelated owner was edited.Original CI run
38228289309, headc0038e5e618dfd8ce918da002501d73392f84c79: fetched the three failed job logs once; 18 failed cases across small-3, small-7, and small-11. Reproduced the owner failures locally before fixing them.Focused repair proof: 62 passed across eight cron files and the Doctor cron-owner file. Cron duration 43.17s; Doctor 149.25s. Recovery cases now take 92ms–1.35s instead of four 120-second CI timeouts. The unchanged Doctor delivery/maintenance path took 32.8s in one case on this shared Mac (the same case took 4.5s in the saved CI log). An unchanged heartbeat-routing sibling waits for the production 30-second minimum-spacing policy with fake timers disabled (30.8s); recorded for its owner without editing outside cron. No timeout increases, retries, or weakened assertions.
Negative controls: restoring the delivery runtime import fails with “Startup commands must not load delivery resolution”; restoring expired-slot recomputation during ordinary refresh fails because the pending run settles as
not-duebefore its payload starts.Full saved cron replay: 30 files / 238 tests passed (219.46s wall); the service replay reported 105/106 files passing, 784 passed / 2 fixture failures (459.25s wall). Those failures came from recreating invalid disabled-job deadlines and leaking a worker spy during failed cleanup. Corrected that idle fixture and guaranteed cleanup without changing its assertions. The final three-file proof passed 19/19 cases (18.77s wall, 15.90s Vitest duration), including both failures. Also replaced the obsolete host wake in
service.list-past-due.test.ts: 61.849s → 1.136s with every assertion retained. No full service replay was repeated after these test-only corrections; unchanged passing source is retained evidence. All 122 importing sibling files / 1,882 tests passed (1,809.38s wall). All four E2E files / 19 tests passed (290.30s wall including runtime build; 65.79s Vitest duration).Targeted type graphs
core-test-services-cron,core-test-commands, andcore-test-commands-doctorpassed in 2.0s / 9.8s / 8.6s. Madge reports 0 cycles.check:changedpassed production, all core-test and root-test types, formatting, boundaries, and preceding guards, then stopped at two inherited dead exports:resolveEffectivePromptTokensandrenderPublicSessionCardSvg. Every trailing check was run separately: scripts lint, schema, database ownership, media, sidecar, runtime cycles, webhook/pairing boundaries, and root helper lint passed. Full-core lint found one cron test shadowing error (now corrected and checked separately) plus 13 inherited errors in unchanged files. Final targeted lint passed for all three corrected cron files. Final cron types passed again in 2.6s; line-cap ratchet passed with no growth;git diff --checkpassed. The aggregate gate remains red; no unrelated owner or lint baseline was changed.Fresh candidate recovery from consistent copies created by released
[email protected](e178c39): both retainedintegrity_check: okand schema version 20. The pending copy's eight active receipts became interrupted; unrecoverable queued work was skipped. At the current clock, five (clean copy) and two (pending copy) due synthetic jobs executed. Both retain 11 jobs after the existing loader retires one obsolete system job. No operator state was used.Prior isolated real timer/notification/launcher proof executed two one-shots and removed both (
remainingJobs: 0). This proves transport and rearming, not latency on the shared host.Publication: the repair is pushed at
210b8139c7e2229fd77d76e1072d4bf1102c0e82. The PR remains ready; final exact-head CI is left to run. No CI completion or merge is claimed.A fresh isolated Codex review of the repair diff completed with no actionable P0/P1 findings. The complete redesign still needs maintainer review; the earlier whole-lane review attempt was unavailable. No merge was attempted.
Inherited full-core lint findings (all files unchanged from the pinned base)
ui/src/e2e/model-providers.e2e.test.tseslint(max-lines)src/plugins/registry-runtime-session-ownership.tseslint(max-lines)ui/src/pages/chat/components/chat-detail-panel.tsxeslint(max-lines)ui/src/pages/chat/components/chat-message-images-solid.tsxeslint(max-lines)src/cli/update-cli/update-command-post-update.tseslint(max-lines)src/agents/isolated-completion.tseslint(max-lines)src/auto-reply/reply/dispatch-from-config.choose-route.tseslint(max-lines)src/gateway/server-methods/chat-abort-runtime.tseslint(max-lines)src/agents/worktrees/checkout.tseslint(max-lines)src/gateway/session-worktree-preparation.tseslint(max-lines)src/agents/tools/sessions-send-tool.tseslint(max-lines)src/plugin-state/plugin-state-store.tseslint(max-lines)ui/src/components/session-group-defaults-dialog.tsxtypescript(no-misused-promises)