Skip to content

refactor(cron): reduce catch-up and receipt-binding reads - #172665

Merged
steipete merged 1 commit into
mainfrom
dbasync/croncatchup
Oct 15, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/croncatchup

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cron startup and clock-jump catch-up reread the jobs already loaded by the scheduler command, and execution diagnostic binding checks receipt existence before its conflict-safe insert.

User Impact

Reduces cron database work without changing schedules, exactly-once claims, persisted future retries, or delivery authorization. No schema change, migration, or operator action.

Why This Change Was Made

The synchronous worker command owns catch-up from load through mutation. Pass its jobs map into catch-up and persist changed runtime rows directly, removing the ID-only load, second row load, and duplicate runtime-authority read. Queue admission retains execution authority. Diagnostic binding writes directly through the existing first-link-wins owner.

Removed checks and accepted edges:

  • Catch-up row/authority rereads: reuse command-owned facts without an intervening await; unsupported out-of-owner SQLite writes during that command are not detected. Each new command still loads current jobs, so preceding in-process edits remain visible.
  • Receipt existence before diagnostic binding: a callback delayed past pruning may leave an orphan diagnostic link. The link confers no execution or delivery authority.

Claim uniqueness, receipt settlement, finalization's merge with current operator edits, and final external-effect authority checks remain intact. The superseded catch-up mutation path is deleted.

Evidence

Formatting, changed-file oxlint and git diff --check passed. Candidate CI, at synthetic merge 0bba905882799954fdedd38ddd7799754ec9ad65 for candidate c78d82422886bc29cb85d2ec0a519e7cbd4a29f6, passed all 30 selected jobs, including production/test types, type-aware lint, source contracts/export collisions, Madge (0 cycles), and T1/dialect ratchets. Scheduler tests passed 20/20 and queue tests 10/10, including preceding in-process edits, overflow/restart behavior and binding retries. Finalization's concurrent-edit/idempotent-settlement regression passed. Codex autoreview found no actionable P0–P2 findings.

Candidate Knip reported seven production and six full-tree export findings, all matched by file and rule on scheduled main. None concerns a changed cron file. Script exports and unused-file scans passed. The inherited-static-failure exception was recorded for follow-up. Two local Knip attempts timed out; a queued Testbox was stopped before proof ran. Local check:changed hit a Corepack launcher failure; the completed CI jobs provide the static proof.

Remaining proof gap: the separately named gateway-cron-startup-recovery.e2e.test.ts was not selected by that CI run. One local attempt hit the worker-compilation watchdog; after worker-cache preparation, the unchanged test timed out during Gateway startup imports, before its recovery assertions. This is neither passing persisted-future-retry proof nor a demonstrated cron regression. No timeout or assertion was changed. A later immediate remote-capacity probe created no lease and ran no test because the available source capsules were incomplete. The fresh scheduled-run fixture below does not close this gap.

Cron T1 call sites remain 0 → 0; both changed production owners already run in workers. Whole-repository T1 remains live 223 → 223, deprecated-only 12 → 12. No SDK, schema, update/Doctor, plugin-loading or service-lifecycle change. Net LOC: production −14, tests +34, documentation +4.

SQL and request measurements

Values are median [min–max] across three alternating base/candidate pairs. SQL includes all threads; requests are logical worker dispatches.

Scope / metric Base Candidate
Warmed SQL/turn 146.8 [141.8–152.2] 143.4 [140.3–145.2]
Warmed requests/turn 46 [43.8–47.3] 44.3 [43.6–46.2]
Raw warmed MAIN/turn 1.3 [1.3–1.3] 0.4 [0–1.3]
Cron-window SQL 447 [392–453] 394 [390–412]
Cron-window requests 132 [102–133] 103 [101–109]
Whole-workload SQL 4735 [4620–4861] 4743 [4689–4787]
Whole-workload requests 1129 [1073–1167] 1111 [1090–1131]
Scheduler operation SQL / requests 16 / 6 in every run 14 / 6 in every run

Measurement interpretation

The direct measured saving is two startup catch-up SELECTs: the whole-workload scheduler group is 16 → 14 SQL and 6 → 6 requests in every pair. The fixture starts with an empty cron store; source inspection establishes one additional removed runtime-authority SELECT for populated catch-up. The command still loads current rows once before catch-up, and the new regression proves preceding in-process edits survive the mutation. Diagnostic binding is not exercised by this harness; its one-SELECT saving is source/test evidence, not a measured zero or measured improvement.

The larger raw changes are not attributed to this patch. Warmed SQL is 146.8 → 143.4 and requests 46.0 → 44.3 per turn; causal warmed counts are nearly unchanged (117.9 → 117.8 SQL, 34.6 → 34.5 requests). The cron window drops 447 → 394 SQL and 132 → 103 requests, but includes job setup, polling, session work and background maintenance. Scheduled activation/claim remains 9 SQL / 3 requests, and terminal settlement remains 8 SQL / 1 request in every run.

Whole-workload SQL increases 4735 → 4743 (+8, +0.17%) while requests fall 1129 → 1111. The first-turn median increases 1387 → 1415 SQL (+28) and 170 → 181 requests (+11). Known positive first-turn groups are:

Source group Base SQL / requests Candidate SQL / requests Evidence / limit
Provider account auth and usage 19 / 7 28 / 8 Each candidate has one extra 9-SQL prepared-model catalog request through prepared-model-catalog-worker.ts and auth-profile JSON reads; absent in the base traces.
Session usage cache 13 / 2 26 / 5 Background work through session-cost-usage-worker-scope.ts and session-cost-usage-cache.sqlite.ts; whole-workload counts also rise, so this is not just window movement.
Plugin/skill metadata 19 / 3 34 / 6 Includes deferred lease checks and metadata refresh.
Unclassified first-turn remainder 463 / 49 482 / 53 Source attribution is incomplete outside the cron window; causal explanation remains unresolved.

These are independently calculated group medians and do not sum to the net +28/+11. The cause of the extra catalog/cache work is unproven. No caching, invalidation, replica or worker-routing change is present in this patch; touched scheduler operations consistently do less work. Under the campaign's attribution-over-raw rule, the unexplained increases are disclosed rather than labeled a cron regression or an across-the-board saving.

All six runs have the same 13 successful background state_leases expiry SELECTs from plugin lifecycle ownership checks across first-turn plus warmed windows. Their timing changes: warmed raw MAIN is 1.3 → 0.4 per turn, but the patch removes none of those reads. Causal warmed MAIN and cron-window MAIN remain zero. No latency claim: host load varied roughly 62–111 on 32 CPUs.

Three exact alternating base/candidate pairs completed successfully with ten warmed turns each, successful scheduled-run receipts, no failed SQL executions/prepares, and no fixture children left running. The task-local harness copy uses an allocated Gateway port, a synthetic stored OpenAI profile and current subagent result parsing; setup runs before tracing, all six harness hashes match, and the shared harness was not edited. This stored-account workload differs from the historical campaign workload; compare the paired runs here, not the earlier 82-SQL census.

The additive cron-window ledger accounts for every observed statement and request. Terminal settlement's eight statements are BEGIN, current jobs, conditional receipt completion, retention candidates, existing history, history insert, runtime update and COMMIT. The receipt CAS preserves idempotency; current-job/receipt-marker checks preserve operator edits, deletion and another active run. Existing-history handling preserves cancellations and incompatible committed outcomes; it is diagnostic, not authorization. Those retained reads are not claimed to be universally minimal. Fresh fixtures do not exercise pruning DELETEs, populated startup recovery or startup-batch settlement. Delivery is none, so the run does not prove an external send.

Six-run results, phase totals and additive cron ledger

Raw warmed medians do not regress (SQL 146.8 → 143.4, Δ -3.4; requests 46 → 44.3, Δ -1.7; MAIN 1.3 → 0.4, Δ -0.9 per turn); touched-owner regression status is unproven for diagnostic receipt binding (not attributed in 6/6 runs).

Base: d25a316fc7c3. Candidate: c78d82422886. Three alternating base/candidate pairs; ten warmed turns per run. Values are median [min–max]; deltas are candidate minus base.

SQL includes all threads. MAIN is Gateway main-thread SQL. Requests are distinct logical worker dispatches. An observed increase remains an increase; this report does not classify unexplained changes as noise or make wall-time claims.

Warmed turns

Metric Base Candidate Δ median
SQL/turn 146.8 [141.8–152.2] 143.4 [140.3–145.2] -3.4
requests/turn 46 [43.8–47.3] 44.3 [43.6–46.2] -1.7
MAIN/turn 1.3 [1.3–1.3] 0.4 [0–1.3] -0.9

These raw counts include all SQL executions and worker dispatches in the ten warmed phase windows, including background work, divided by ten. MAIN counts Gateway main-thread executions in those same windows.

Causal attribution is shown separately:

Causal metric Base Candidate Δ median
SQL/turn 117.9 [117.9–120.2] 117.8 [117.5–117.9] -0.1
requests/turn 34.6 [34.5–34.8] 34.5 [34.2–34.6] -0.1
MAIN/turn 0 [0–0] 0 [0–0] 0

Whole workload and cron window

Scope / metric Base Candidate Δ median
Whole SQL 4735 [4620–4861] 4743 [4689–4787] +8
Whole requests 1129 [1073–1167] 1111 [1090–1131] -18
Whole MAIN 218 [218–218] 218 [217–218] 0
Cron-window SQL 447 [392–453] 394 [390–412] -53
Cron-window requests 132 [102–133] 103 [101–109] -29
Cron-window MAIN 0 [0–0] 0 [0–0] 0

Phase totals

Phase Base SQL Candidate SQL Δ SQL Base requests Candidate requests Δ requests
01.boot 491 [482–501] 484 [483–486] -7 94 [92–104] 93 [92–93] -1
01.connect 49 [40–54] 59 [58–348] +10 21 [10–21] 22 [18–24] +1
02.first-turn 1387 [1377–1403] 1415 [1153–1469] +28 170 [168–177] 181 [172–183] +11
04.second-session 757 [747–779] 777 [768–797] +20 217 [211–227] 225 [220–232] +8
05.control-plane 9 [9–27] 9 [9–18] 0 1 [1–5] 1 [1–6] 0
06.cron 447 [392–453] 394 [390–412] -53 132 [102–133] 103 [101–109] -29
07.compaction 52 [52–97] 96 [54–97] +44 15 [15–29] 29 [17–29] +14
08.shutdown 84 [34–85] 35 [34–85] -49 22 [9–22] 9 [9–22] -13

Phase totals include concurrent background work. The warmed aggregate is reported above.

Six raw runs

Run Commit Raw warmed SQL / requests / MAIN per turn Causal warmed SQL / requests / MAIN per turn Whole SQL / requests / MAIN Cron SQL / requests / MAIN
1-base d25a316fc7c3 152.2 / 47.3 / 1.3 120.2 / 34.8 / 0 4861 / 1167 / 218 453 / 133 / 0
2-candidate c78d82422886 145.2 / 46.2 / 0 117.5 / 34.2 / 0 4787 / 1131 / 218 390 / 101 / 0
3-base d25a316fc7c3 146.8 / 46 / 1.3 117.9 / 34.5 / 0 4735 / 1129 / 218 447 / 132 / 0
4-candidate c78d82422886 143.4 / 44.3 / 1.3 117.9 / 34.6 / 0 4743 / 1111 / 218 412 / 109 / 0
5-base d25a316fc7c3 141.8 / 43.8 / 1.3 117.9 / 34.6 / 0 4620 / 1073 / 218 392 / 102 / 0
6-candidate c78d82422886 140.3 / 43.6 / 0.4 117.8 / 34.5 / 0 4689 / 1090 / 217 394 / 103 / 0

Touched owners across the whole workload

Operation Base SQL Candidate SQL Δ SQL Base requests Candidate requests Δ requests
Scheduler activation and claim 16 [16–16] 14 [14–14] -2 6 [6–6] 6 [6–6] 0
Diagnostic receipt binding unproven unproven — unproven unproven —

These whole-workload categories include cold work outside the cron window. The scheduler category also includes activation, tick and refresh work; it is not a startup-only measure.

Additive cron-window ledger

Operation Base SQL Candidate SQL Δ SQL Base requests Candidate requests Δ requests
Job setup and mutation 11 [11–11] 11 [11–11] 0 2 [2–2] 2 [2–2] 0
History polling (cron.runs) 4 [3–5] 3 [3–4] -1 4 [3–5] 3 [3–4] -1
Agent database lease admission 28 [28–28] 28 [28–28] 0 0 [0–0] 0 [0–0] 0
Audit and trajectory 8 [6–8] 6 [6–6] -2 5 [3–5] 3 [3–3] -2
Continuation cleanup 6 [6–6] 6 [6–6] 0 3 [3–3] 3 [3–3] 0
Delivery-queue health 1 [0–2] 0 [0–1] -1 1 [0–2] 0 [0–1] -1
Gateway device identity, pairing and auth 17 [0–21] 0 [0–0] -17 12 [0–13] 0 [0–0] -12
Execution, transcript and continuation 2 [1–2] 2 [2–2] 0 2 [1–2] 2 [2–2] 0
Inference binding setup 7 [7–7] 7 [7–7] 0 4 [4–4] 4 [4–4] 0
Launch reload 1 [1–1] 1 [1–1] 0 1 [1–1] 1 [1–1] 0
Maintenance 4 [4–4] 4 [4–18] 0 3 [3–3] 3 [3–7] 0
Plugin and skill metadata refresh 0 [0–3] 0 [0–3] 0 0 [0–1] 0 [0–1] 0
Prompt context bookkeeping 0 [0–0] 0 [0–0] 0 2 [1–2] 1 [1–1] -1
Provider account auth and usage 19 [18–20] 18 [18–19] -1 12 [11–13] 11 [11–12] -1
Scheduler activation and claim 9 [9–9] 9 [9–9] 0 3 [3–3] 3 [3–3] 0
Session storage, projection, transcript and maintenance 247 [231–251] 231 [229–231] -16 56 [50–58] 50 [50–50] -6
Session and transcript preparation 0 [0–0] 0 [0–0] 0 1 [1–1] 1 [1–1] 0
Session upstream monitoring 0 [0–1] 0 [0–1] 0 0 [0–1] 0 [0–1] 0
Session cost and usage cache 36 [36–36] 36 [36–36] 0 6 [6–6] 6 [6–6] 0
Subagent registry maintenance 2 [2–2] 2 [2–2] 0 2 [2–2] 2 [2–2] 0
Terminal receipt, history and retention 8 [8–8] 8 [8–8] 0 1 [1–1] 1 [1–1] 0
SQLite WAL checkpoints 4 [1–6] 2 [2–2] -2 0 [0–0] 0 [0–0] 0
Worker placement and turn admission 28 [19–28] 18 [18–19] -10 9 [6–9] 5 [5–6] -4
Source-attributed subtotal 447 [392–453] 394 [390–412] -53 132 [102–133] 103 [101–109] -29
Unattributed remainder 0 [0–0] 0 [0–0] 0 0 [0–0] 0 [0–0] 0
Window total 447 [392–453] 394 [390–412] -53 132 [102–133] 103 [101–109] -29

Within each run, source-attributed operations plus the unattributed remainder equal the window total; independently calculated medians need not add. The subtotal and total are summary rows, not additional work. Each request has one primary source operation, including requests that execute no SQL. Statements inherit that operation or use their own source when the request is unresolved. Setup and polling are included above as separate operations.

History polling RPCs: base 4 [3–5], candidate 3 [3–4] (Δ -1). RPC counts are separate from worker requests.

Startup read evidence

Operation Base SQL Candidate SQL Δ SQL Base requests Candidate requests Δ requests
boundedCatchup SQL frame: loadCronRows 2 [2–2] 0 [0–0] -2 1 [1–1] 0 [0–0] -1
startCronScheduler origin: loadCronRows 1 [1–1] 1 [1–1] 0 1 [1–1] 1 [1–1] 0
Scheduler, start unproven: loadCronRows 4 [4–4] 4 [4–4] 0 4 [4–4] 4 [4–4] 0
No scheduler marker: loadCronRows 14 [13–14] 14 [13–14] 0 12 [11–12] 12 [11–12] 0

Only successful SELECT/WITH executions with named read functions count here; authority schema metadata reads are separate from authority-row reads. Evidence classes are exclusive. A startCronScheduler origin is call-site evidence, not a captured command payload. Generic scheduler frames and unscoped reads do not prove startup. Read-class request counts can overlap; they must not be summed.

Read classes absent from the table had zero observed matching statements.

Any successful SQL with marker Base Candidate Δ median
boundedCatchup SQL frame 5 [5–5] 3 [3–3] -2
Explicit scheduler-start frame 0 [0–0] 0 [0–0] 0
startCronScheduler origin 1 [1–1] 1 [1–1] 0
Scheduler, start unproven 10 [10–10] 10 [10–10] 0

Zero named reads does not show whether catch-up was exercised. Marker coverage above makes that limit explicit; boundedCatchup can also run after a later clock discontinuity.

Scope and attribution limits

Operation Base SQL Candidate SQL Δ SQL Base requests Candidate requests Δ requests
Cron requests: SQL after/before window 0 [0–0] 0 [0–0] 0 0 [0–0] 0 [0–0] 0
Other-phase requests: SQL inside window 0 [0–5] 0 [0–0] 0 0 [0–1] 0 [0–0] 0
Window SQL without a linked request 72 [69–74] 70 [70–70] -2 0 [0–0] 0 [0–0] 0

Spill request counts are coverage of those sets, not additional dispatches. Whole-workload, cron-window and dispatch-cohort scopes overlap and must not be added. The cron window contains job creation, scheduled execution, polling and maintenance; it is not a scheduled-run causal identity. Stacks do not include SQL bindings or command payloads, nested requests have no parent ID, and SQL events have no timestamp. This ledger is not an exact execution timeline.

Excluded failure counter Base Candidate Δ median
Failed native executions 0 [0–0] 0 [0–0] 0
Failed prepares 0 [0–0] 0 [0–0] 0

Failed executions are excluded from successful SQL; a failed multi-statement exec counts as one failure. Fresh fixtures do not prove persisted startup-retry recovery or history/receipt overflow. Delivery mode is none; external sends are not exercised. Those behaviors require their separate focused regression proof.

Reuse the scheduler command-owned jobs through catch-up and keep execution authority at queue admission. Remove the receipt-existence read before first-link-wins diagnostic binding; a delayed callback after pruning may leave a harmless diagnostic link.
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T00:33:09.063570Z c78d824 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 15, 2026
@steipete
steipete merged commit c6558f6 into main Oct 15, 2026
214 of 288 checks passed
@steipete
steipete deleted the dbasync/croncatchup branch October 15, 2026 02:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…aw#172665)

Reuse the scheduler command-owned jobs through startup and clock-jump catch-up, removing duplicate row and runtime-authority reads. Keep exactly-once claim admission, persisted future retries, and settlement merging of current operator edits.

Bind execution diagnostics through the existing first-link-wins insert without rereading receipt existence. A callback delayed past receipt pruning may leave an orphan diagnostic link; that metadata grants no execution or delivery authority.

The changed owners remain entirely in workers (cron T1 0 to 0). Focused scheduler, queue, and settlement tests and exact-head PR CI passed. Knip findings match the same files and rules on current main; see the PR for proof and the inherited-static-failure exception.
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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant