Skip to content

improve(cron): move recovery proposal reads off the caller thread - #153158

Merged
steipete merged 3 commits into
mainfrom
codex/cron-proposal-batch-20260919
Sep 20, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/cron-proposal-batch-20260919

Conversation

@steipete

@steipete steipete commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cron recovery proposal acquisition still queried SQLite on the caller thread during startup, timer recovery, and run-settlement waits.

User Impact

Those proposal observations now run in the shared-state worker. Cancellation, stop, or restart detected after proposal acquisition prevents obsolete recovery and entry into subsequent scheduling or maintenance. Already committed interruptions keep their history and events across a stop-and-restart during the following reload.

Final recovery writes, execution-authority checks, and guarded saves retain their existing native owners. This does not make the entire Cron flow SQL-free on the caller thread.

Why This Change Was Made

One fixed command preserves the original transaction that observes the active receipt and matching running-marker association, including existing receipt-table initialization. Proposal facts never grant authority: process liveness and local receipt ownership stay on the host, and the final recovery transaction rereads the exact receipt and markers before changing rows. There is no asynchronous work inside that transaction and no schema, retention, configuration, or public API change.

The callers await proposals in their existing order and recheck cancellation and service generation before recovery. Timer recovery collects every proposal before synchronously repairing the batch and starting its notifications. Startup and timer recovery retain committed interruption facts through the canonical reload, then publish them under the same partition lock before a replacement can start catch-up. Lifecycle checks then fence fresh work. Retirement detected after proposal acquisition releases admission and capacity without entering timer maintenance or re-arming the replacement scheduler. A stop or restart during reservation persistence joins the existing receipt-specific cleanup before the timer exits, releasing only its own batch slots. Retirement during an already-running per-agent sweep retains its existing behavior.

Evidence

  • The original cold proposal regression on Node performed caller-thread SQLite work. The candidate passes with zero database constructions and zero prepare/exec/close/get/all/run/iterate calls; constructor observation is positively calibrated.
  • Recovery, receipt settlement, identity, trigger, and service coverage: 291 selected cases pass across eleven suites on the actual main composition: 235 Cron cases and 56 shared-worker admission, settlement, and lifecycle cases. Removing the new post-await guards made all four lifecycle regressions fail on unintended durable repairs. A separate regression caught entry into the retired timer's maintenance tail.
  • Three actual two-job regressions pass: restart while a later proposal is held, and restart after committed repairs while timer or startup reload is held. The first exposed a dropped committed prefix; the startup case independently failed with the added generation guard and passed when only that guard was removed. The final repair preserves both histories and events without losing lifecycle fencing, executing payloads, or leaking admission.
  • Normal-build Node 24.21.0 and Bun 1.4.2 calibration and cold startup cells pass. The unchanged probe starts from an exited synthetic run admitted through CronService.run, requires one replacement and error-then-success events, and checks no active receipt. Construction and all seven method counters are calibrated in separate processes before cold startup.
  • Whole startup retains seven host database constructions in both runtimes. Against the matched main baseline, host prepare/exec/get counts move from 574/78/501 to 571/74/495. Native recovery and admission work remains in the totals. The exact lifecycle-coordinator bucket is reported separately without exclusions.
  • The first hosted run caught an added generation check returning before durable reservation cleanup. The unchanged baseline passed all 34 admission tests; the published candidate failed the existing scheduled-stop case and a new scheduled-restart control. The repair routes both through canonical cleanup while retaining a newer admission slot. An expanded existing test then caught empty retired ticks waiting behind a held replacement lock. Empty batches now return without reacquiring that lock; reserved batches retain cleanup. All 68 focused admission, retirement, interruption, and placement cases pass without timeout or assertion changes.
  • Fresh P2 review, the normal build, full changed-scope gate, and Node/Bun runtime cells pass on the actual main composition. Earlier local gate attempts caught two test-only issues, now fixed without weakening assertions.

@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L maintainer Maintainer-authored PR labels Sep 19, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 19, 2026
@clawsweeper

clawsweeper Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 19, 2026, 5:51 PM ET / 21:51 UTC (Revision 2).

ClawSweeper review

What this changes

Moves Cron recovery observations into the shared database worker while preserving stop/restart fencing, interruption history, and reservation cleanup.

Merge readiness

✅ Ready for maintainer review

The improvement remains useful, and the previous reservation-cleanup blocker is addressed. No remaining introduced correctness defect was found.

Priority: P2
Reviewed head: 21228c59c00e4b4aaf4dce668497062d8f859021

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused worker cutover with meaningful lifecycle coverage and the prior cleanup defect resolved.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor proof gate does not apply to this maintainer-authored PR. Its captured body reports Node/Bun CronService recovery and SQLite placement results matching the changed path; no new authority boundary requires additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor proof gate does not apply to this maintainer-authored PR. Its captured body reports Node/Bun CronService recovery and SQLite placement results matching the changed path; no new authority boundary requires additional final-effect proof.
Evidence reviewed 9 items Current main still needs the improvement: Current main executes proposal acquisition directly through a synchronous state write transaction, including receipt and running-marker reads.
Latest release comparison: The supplied latest release, v2026.9.5, also contains synchronous proposal acquisition; its source does not already provide this worker cutover.
Observation and mutation owners remain separate: The worker preserves the existing observation transaction and receipt initialization. Host recovery still checks process liveness and compares the authoritative receipt and running association before writes. No new permission, schema, configuration, dependency, or public plugin API is introduced.
Findings None None.
Security None None.

How this fits together

Cron recovers interrupted scheduled jobs using persisted job markers and execution receipts. Startup, timer ticks, and settlement waiters obtain observations from the database worker, then the host validates current ownership before repairing state and resuming scheduling.

flowchart TD
  A[Startup or timer or settlement wait] --> B[Shared database worker]
  C[Stored job markers and receipts] --> B
  B --> D[Host lifecycle and liveness checks]
  D --> E[Transaction rechecks exact current state]
  E --> F[Repair and publish interruption]
  F --> G[Resume scheduling or release reservations]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +117, Tests +480, Docs +17. Total +614 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 7 177 60 +117
Tests 9 522 42 +480
Docs 1 17 0 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 716 102 +614

Review metrics

Metric Value Why it matters
Production versus test growth Production +117 net lines; tests and test support +480 net lines Production growth implements the worker boundary and lifecycle fencing; most growth protects placement, interruption publication, and reservation cleanup.

Technical review

Best possible solution:

Keep observation work in the shared worker while retaining exact-state recovery checks and receipt-specific cleanup with their existing host owners.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a discrete user-facing bug reproduction: source directly establishes synchronous proposal reads on current main. Runtime measurements were reported by the author, not rerun here.

Is this the best way to solve the issue?

Yes. Reusing the shared-state worker preserves the existing transaction and recovery owner without introducing a competing store or changing persisted formats.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fd22b275d548.

Labels

Label justifications:

  • P2: This is a bounded Cron responsiveness improvement with focused recovery and lifecycle coverage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor proof gate does not apply to this maintainer-authored PR. Its captured body reports Node/Bun CronService recovery and SQLite placement results matching the changed path; no new authority boundary requires additional final-effect proof.

Evidence

What I checked:

  • Current main still needs the improvement: Current main executes proposal acquisition directly through a synchronous state write transaction, including receipt and running-marker reads. (src/cron/service/run-recovery.ts:264, fd22b275d548)
  • Latest release comparison: The supplied latest release, v2026.9.5, also contains synchronous proposal acquisition; its source does not already provide this worker cutover. (src/cron/service/run-recovery.ts:264, ec9c1a13db89)
  • Observation and mutation owners remain separate: The worker preserves the existing observation transaction and receipt initialization. Host recovery still checks process liveness and compares the authoritative receipt and running association before writes. No new permission, schema, configuration, dependency, or public plugin API is introduced. (src/cron/service/run-recovery.ts:262, 21228c59c00e)
  • Previous blocker resolved: The current retired-batch branch invokes canonical cleanup for nonempty reservations; its finally releases each batch-owned admission slot. Empty retired batches avoid reacquiring the replacement scheduler's lock. This addresses the prior review's concrete cleanup concern. (src/cron/service/timer-scheduler.ts:327, 21228c59c00e)
  • Cleanup regression coverage: The expanded reservation test covers scheduled stop and restart, an injected cleanup failure, cleared durable markers, no payload execution, and preservation of a separately acquired successor admission slot. (src/cron/service/ops.run-admission-cleanup.test.ts:802, 21228c59c00e)
  • Recovery publication coverage: Two-job tests exercise restart during a later proposal and during post-repair reload for startup and timer recovery. Assertions inspect durable receipts, exactly one history entry per job, interruption events, and released admission. (src/cron/service/run-recovery.batch.test.ts:69, 21228c59c00e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-19T20:36:00.628Z sha f35be5e :: blocked before merge. :: [P1] [P1] Release committed reservations before returning on retirement

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 19, 2026
@steipete
steipete merged commit 084dfec into main Sep 20, 2026
223 checks passed
@steipete
steipete deleted the codex/cron-proposal-batch-20260919 branch September 20, 2026 00:21
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 20, 2026
…enclaw#153158)

* perf(cron): move recovery proposal observations off-thread

* fix(cron): settle retired timer reservations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant