Repository navigation
perf(cron): reuse receipt transactions for agent availability - #156801
Conversation
Carry the receipt transaction into deletion guards and reuse coordinated native transactions for current-authority reads. Preserve ordinary committed-row isolation and schema validation. Synthetic receipt guards dropped from 453.2 ms with three child spawns to 3.04 ms with none; 268 focused Testbox tests and the complete changed-file gate passed.
|
🦞👀 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. Reviewed September 23, 2026, 6:10 PM ET / 22:10 UTC. ClawSweeper reviewWhat this changesCron receipt checks pass their SQLite transaction to the agent-deletion guard and let synchronous current-authority readers reuse a coordinated writer while ordinary reads retain committed-state isolation. Merge readiness✅ Ready for maintainer review Current main still has the synchronous receipt-guard hotspot, so this PR remains useful. The reviewed patch has no supported blocking correctness finding. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway’s cron scheduler checks an agent’s availability and a persisted run receipt before updating job state. Those checks use the shared SQLite state database and either allow the receipt transition or refuse it. flowchart LR
A[Cron run] --> B[Receipt transaction]
B --> C[Agent availability check]
D[Deletion journal] --> C
E[Admission and roster] --> C
C --> F{Available?}
F -->|Yes| G[Receipt update]
F -->|No| H[Refused transition]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +41, Tests +91, Docs +8. Total +140 across 13 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep agent-deletion authority checks inside the owning receipt transaction and preserve committed-state isolation for discovery reads as remaining cron work moves through the existing SQLite worker owner. Do we have a high-confidence way to reproduce the issue? Yes, the current-main receipt hook and separate reader path give a clear reproduction target, and the PR body reports a failing baseline through that hook. I did not execute current main in this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing transaction addresses the nested read at its owner without adding a parallel authority cache; the patch also preserves ordinary read isolation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 764c9331a31b. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Integrate the main revision exercised by this PR's CI merge and keep native storage retries in the same clock domain as their monotonic deadlines. Global fake timers could strand accepted worker work when a caller restored real timers, leaving Codex settlement cleanup hooks blocked for 180 seconds. The exact failing 12-file CI group reproduced on Testbox. Restoring native promise timers passed all 107 cases; the first formerly blocked case settled in 2.877 seconds. Coordinator budget, cancellation, authority, and worker custody checks remain intact.
JSON-escape mention sigils in optional attachment metadata so Codex does not interpret filenames as skill or plugin requests. Preserve exact decoded file identities and explicit mentions in the user's prompt. Cover initial and steering preparation through the registered owner. Merge current main including adf4aff from #156801. The prior CI run reproduced settlement cleanup hangs when fake timers discarded the native coordinator backoff; it was canceled after the failures were captured. The owning repair keeps native storage waits independent of caller timers.
…penclaw#156801) Carry the receipt transaction into deletion guards and reuse coordinated native transactions for current-authority reads. Preserve ordinary committed-row isolation and schema validation. Synthetic receipt guards dropped from 453.2 ms with three child spawns to 3.04 ms with none; 268 focused Testbox tests and the complete changed-file gate passed.
What Problem This Solves
Cron receipt availability checks can synchronously spawn a SQLite snapshot child while holding the shared-state write coordinator, blocking the Gateway event loop and other state writers.
User Impact
Receipt validation keeps the existing deletion, admission-refusal, and roster checks without paying for another database snapshot. No configuration, schema, retention, migration, or update behavior changes.
Why This Change Was Made
Receipt persistence and receipt-current checks now pass their existing transaction to the deletion owner. The shared current-authority reader also reuses the cached writer only inside its same-thread coordinated transaction, so lifecycle and worktree callbacks read the pending authoritative rows. Ordinary read-only/discovery reads keep committed-state isolation, and schema and maintenance checks remain in place. Admission refusals already belong to an in-memory owner and need no new database reader or cache.
Evidence
A synthetic measurement executes the real receipt
beforeWritehook in three shared-state write transactions. The original code fails the regression with three synchronous snapshot children and nine extra connection opens.These are focused samples, not a production latency projection. The supplied path removes about 99.3% of the measured transaction time.
Validation uses provider
blacksmith-testbox, profileopenclaw-check, leasetbx_01m381te2sf6j1dcsvf196e7cm(Testbox run).node scripts/run-vitest.mjs src/cron/store/run-receipt-store.test.ts -t 'checks receipt availability' --maxWorkers=1— expected regression failure (3 spawns, 9 connections).node scripts/check-changed.mjs --base faa6aa6243e— passed: core typecheck, all 25 test typecheck graphs, lint (zero warnings/errors), formatting, line limits, export checks, schema guards, and zero runtime import cycles. Remote command duration: 39m29s.pnpm testinvocations below, followed bynode scripts/run-vitest.mjs src/state/openclaw-state-db-readonly.test.ts src/state/openclaw-state-db.runtime-fence.test.ts src/cron/service/run-receipt-settlement.test.ts src/gateway/server-cron.test.ts --maxWorkers=1.Measured changed-test file costs on the same Testbox, using
/usr/bin/time -p pnpm test <file> --maxWorkers=1: receipt store 40.45s wall (37 tests, including 24.2s cold worker preparation), lifecycle registry 14.26s (12 tests), read operations 10.23s (13 tests). The receipt suite needs real SQLite transactions and process instrumentation to catch this regression; cold worker compilation dominates its wall time. CI case-duration sums from the first run: receipt store 4.181s (37 cases), lifecycle registry 6.775s (12 cases), and read operations 0.949s (13 cases); these exclude setup/import overhead.Independent review: no actionable P0–P2 findings after retaining explicit schema validation and extracting cached-handle reuse to stay within the line cap.
The first remote invocation lacked dependencies; a frozen-lockfile install on the same lease fixed the fixture. The first changed check also compared against the remote seed's older
origin/main; subsequent checks use the lane's pinned starting commitfaa6aa6243e.Stable started
cron.list/cron.status/page/get calls are verified to acquire no state write coordinator and dispatch no state worker mutation. Cold/stale store loading can still repair rows throughloadCronJobsStoreWithConfigJobs, and an unstarted scheduler can write throughrecomputeUnownedCronSchedules; changing those repair contracts is not a one-line read routing fix and remains outside this lane.The caller audit found no missed same-thread lifecycle migration: agent creation/team changes hold a config lock, cron add/update availability checks are outside native transactions, deletion completion already uses the supplied database, and generic worktree authority callbacks receive the central reader fix. Worker-thread admission callbacks keep their independent current-reader path because their writer handle belongs to another thread. No live Gateway deployment, production tail-latency measurement, or RSS comparison was performed. The Testbox lease was stopped after validation.
CI repair in the final change
The first PR CI run passed 143 jobs but failed
checks-node-changed-extensions-bundle-18: Codex settlement cleanup hooks timed out after 180 seconds, and the workflow automatically retried its no-output stall. The CI merge incorporated newer main session-coordinator code from #156067 that had replaced native promise timers with global-timer backoff while retaining a native monotonic deadline. Switching a fixture from fake to real timers could strand accepted storage work on an abandoned fake retry timer.The exact CI merge
989dd44c6e69a20eb33afb9f95b02d4bf5f9d63dand original 12-file/two-worker group reproduced the same cleanup timeout on Blacksmith Testboxtbx_01m388bbfqhe127xcdf7322xe1. Restoring nativenode:timers/promisesbackoff made all 107 tests pass ontbx_01m388rnvrjzvp29056mh61w5pin 100.89s; the first formerly failing case completed in 2.877s. Deadlines, cancellation, authority rechecks, and acquisition-only retries remain intact. The existing unit cases use a virtual sleep adapter so their timing and assertions remain deterministic; that file passed all nine tests in 2.30s wall (0.101s summed CI case time on the repaired head). Worker custody, receipt, and lifecycle siblings also passed (53 tests), followed by core typechecking. Final two-file lint passed with zero warnings/errors; the nine coordinator cases passed again. Fresh independent review found no actionable P0–P2 issues. A source-sync timeout occurred before one lint attempt; its transport retry succeeded. All Testbox leases are stopped. The final tree matches the tested CI-merge tree plus the reviewed timer repair.Final CI: run 35934135123 passed on
e9078ad020df319091ae39071f9bc7ab865dc3c0: 145 successful jobs, 15 skipped, zero failed. The previously failing extension bundle passed.