Skip to content

refactor(cron): keep receipt checks off the Gateway thread - #161935

Merged
steipete merged 3 commits into
mainfrom
codex/cron-receipt-current-reader-20260930
Sep 30, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/cron-receipt-current-reader-20260930

Conversation

@steipete

@steipete steipete commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cron receipt-currentness checks still executed SQLite on the Gateway thread before payload dispatch, script-result publication, and webhook delivery.

User Impact

Those direct checks now await native reads without blocking the Gateway event loop. Removal remains effective across the new await, including main-session jobs that retain a cancellation request without a bound abort controller. Run ownership, accepted self-removal, storage formats, and retention stay unchanged.

Why This Change Was Made

The existing shared-state read worker reads the receipt, current job, and required deletion facts in one transaction. It sends only the owner fields needed by the caller after the same full row decoding. The run retains its original database context, bypasses stale discovery snapshots, and checks cancellation and its exact active marker again before each effect. Reopening the same database cannot revive a retired context; missing receipt storage refuses execution without initialization.

Cancellation requests and marker identity remain distinct: a removed run keeps its marker for duplicate exclusion and settlement, but cannot produce another effect. The synchronous SDK message-action and message-source guards retain their existing current-read owner and remain separate follow-through work; this PR does not claim universal Cron SQL elimination.

Evidence

  • Mixed owned/ownerless startup and reload: baseline 58/54 caller-thread SQL calls become zero, preserving execution, history, and event assertions.
  • Actual native-reply barriers reproduce both removed main-session effects on the old code. The unchanged two cases pass after the fix: the worker reports the job present, public removal commits its absence, then releasing the reply produces no event/webhook. Measured cases: 6.626 s and 6.541 s; the 102.47 s command includes worker rebuilding.
  • Foreign-process receipt retirement blocks payload, script-result, and webhook effects despite an inherited discovery snapshot. A separately held native SQL query leaves the event loop responsive, and public removal joins its cancellation/native exit.
  • Original 50-file Cron selection: 369 passed after replacing the premature started-event assumption with actual runner entry. Additional receipt/authority coverage: 50 passed, including source retirement, missing storage, accepted self-removal, and real Gateway writer-held authority.
  • Gateway's original four-file group passed 186 cases before the final deferred-helper cleanup; the final plain Gateway file passed all 16 afterward. Existing call-count, root-lifetime, already-running, finished-event, and deadline assertions remain intact.
  • Core and all 27 test-type graphs are covered with source-bound reuse and affected graph reruns. Selected guards, three export scans, lint, both cycle checks, and fresh P0–P2 review passed. The final maintained qaRuntime build passed (78.10 s, source unchanged).

The first hosted run, 36733462593, found an introduced type-import cycle, repaired by the leaf owner-field contract. 36736723276 then exposed the two fixture ordering assumptions; both were reproduced and corrected. Failed and cancelled lanes remain historical, not coverage.

A final local Gateway group attempt also hit the unchanged one-second first-RPC deadline before the changed entry wait. Diagnostic passes do not establish its cause; that timing failure remains explicit, and fresh final-head hosted receiving is required. No deadline was increased. No published-driver upgrade cell or full SDK declaration build is claimed: this cut changes no updater, Doctor, schema, migration, or service handoff contract.

@clawsweeper

clawsweeper Bot commented Sep 30, 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 gateway Gateway runtime size: L labels Sep 30, 2026
@steipete
steipete marked this pull request as ready for review September 30, 2026 15:00
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 30, 2026
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 30, 2026, 1:45 PM ET / 17:45 UTC (Revision 3).

ClawSweeper review

What this changes

Cron runs move receipt, job, and agent-deletion reads to the SQLite worker and recheck cancellation before payload, event, script-result, and webhook effects, with regression tests and storage documentation.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open. Current main still performs synchronous receipt checks, and the latest branch addresses the removal race identified in the prior review. This remains a distinct, reviewable improvement.

Priority: P2
Reviewed head: e2918071b3576aa68e2be31fcc4eff95dcf27102

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused native-worker proof covers the previously reported race, and the patch follows the existing storage owner without a concrete blocking finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR reports after-fix CronService runs using the real SQLite worker and public job removal: a worker reply is held after a present-job snapshot, removal commits, and the observed event and webhook sinks remain uncalled after release. The source test covers the earlier controller-less race; no stored-data contract changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR reports after-fix CronService runs using the real SQLite worker and public job removal: a worker reply is held after a present-job snapshot, removal commits, and the observed event and webhook sinks remain uncalled after release. The source test covers the earlier controller-less race; no stored-data contract changes are introduced.
Evidence reviewed 7 items Current main still uses a synchronous guard: The current-main Cron service calls the synchronous receipt assertion; the branch's worker-backed check is not already present.
Worker-backed currentness check: The introduced check awaits a current worker read using the run's captured database context, then checks admission, abort, requested cancellation, and the active marker before accepting the facts.
Prior P1 addressed: The previous review identified controller-less main-session removal after a worker snapshot. The latest source checks requested cancellation after the await, and the new test holds that reply while public removal commits.
Findings None None.
Security None None.

How this fits together

Cron accepts scheduled and manual jobs, checks durable run receipts and current job definitions, then dispatches events, payloads, or webhooks. The shared-state reader worker supplies SQLite facts to the Gateway.

flowchart LR
A[Scheduled or manual job] --> B[Run receipt]
B --> C[SQLite read worker]
C --> D[Gateway currentness check]
E[Job removal] --> D
D --> F[Event, payload, or webhook]
F --> G[Run result]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +224, Tests +437, Docs +10. Total +671 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 15 277 53 +224
Tests 8 470 33 +437
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 757 86 +671

Review metrics

Metric Value Why it matters
Production versus test growth production +277/−53; tests +470/−33 The worker read and post-await fences explain the production growth; the larger test addition targets the receipt and removal races.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/cron/store/run-receipt-store.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep the existing receipt owner and native read worker, with live cancellation and marker checks immediately before each affected effect.

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

Yes, from source: current main calls the synchronous receipt guard on the Gateway path before effects. I did not execute the checkout in this read-only review.

Is this the best way to solve the issue?

Yes. Using the existing shared-state reader and rechecking live run authority after its await is a narrow repair that preserves the stored receipt contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 25eb94b22ac6.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR reports after-fix CronService runs using the real SQLite worker and public job removal: a worker reply is held after a present-job snapshot, removal commits, and the observed event and webhook sinks remain uncalled after release. The source test covers the earlier controller-less race; no stored-data contract changes are introduced.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR reports after-fix CronService runs using the real SQLite worker and public job removal: a worker reply is held after a present-job snapshot, removal commits, and the observed event and webhook sinks remain uncalled after release. The source test covers the earlier controller-less race; no stored-data contract changes are introduced.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded Cron responsiveness repair with limited user-facing blast radius.
  • merge-risk: 🚨 message-delivery: The new awaited checks sit immediately before event and webhook dispatch, where a mistake could send or suppress delivery.
  • merge-risk: 🚨 security-boundary: The receipt and active marker carry run authority across a worker await; the delayed-reply cases specifically exercise removal revocation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR reports after-fix CronService runs using the real SQLite worker and public job removal: a worker reply is held after a present-job snapshot, removal commits, and the observed event and webhook sinks remain uncalled after release. The source test covers the earlier controller-less race; no stored-data contract changes are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR reports after-fix CronService runs using the real SQLite worker and public job removal: a worker reply is held after a present-job snapshot, removal commits, and the observed event and webhook sinks remain uncalled after release. The source test covers the earlier controller-less race; no stored-data contract changes are introduced.

Evidence

What I checked:

  • Current main still uses a synchronous guard: The current-main Cron service calls the synchronous receipt assertion; the branch's worker-backed check is not already present. (src/cron/service/run-receipts.ts:200, 25eb94b22ac6)
  • Worker-backed currentness check: The introduced check awaits a current worker read using the run's captured database context, then checks admission, abort, requested cancellation, and the active marker before accepting the facts. (src/cron/service/run-receipts.ts:204, e2918071b357)
  • Prior P1 addressed: The previous review identified controller-less main-session removal after a worker snapshot. The latest source checks requested cancellation after the await, and the new test holds that reply while public removal commits. (src/cron/service.receipt-currentness.test.ts:17, e2918071b357)
  • Final-effect observations: The two delayed-reply cases assert committed removal and no subsequent system-event, heartbeat, or webhook call. The PR body reports both cases passing after the fix, at 6.626 and 6.541 seconds, and reproducing the old behavior before it. (src/cron/service.receipt-currentness.test.ts:120, e2918071b357)
  • Stored-data boundary: The introduced read command selects existing receipt, job, and deletion facts in one transaction; no schema, stored format, or migration change appears in the introduced patch. (src/cron/store/run-receipt-read.ts:77, e2918071b357)
  • Current-main feature history: Merged Cron receipt and Gateway responsiveness work predates this branch, including the guarded-write cutover and run-finalization work. (src/cron/service/run-receipts.ts, 2ef0b1048dcd)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Josh Avant: 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 (2 earlier review cycles)
  • reviewed 2026-09-30T15:07:08.013Z sha 5f60d10 :: needs real behavior proof before merge. :: [P1] Reject removed main-session jobs after the awaited receipt read
  • reviewed 2026-09-30T15:34:37.361Z sha 4a3b551 :: needs real behavior proof before merge. :: [P1] Reject removal before main-session event dispatch

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 30, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 30, 2026
@steipete
steipete merged commit 4a6d9aa into main Sep 30, 2026
207 of 245 checks passed
@steipete
steipete deleted the codex/cron-receipt-current-reader-20260930 branch September 30, 2026 18:26
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 1, 2026
…161935)

* refactor(cron): offload direct receipt checks

* fix(cron): keep receipt read facts in a leaf contract

* fix(cron): honor removal after awaited receipt reads
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 gateway Gateway runtime merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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