Repository navigation
fix(update): ride out state database contention instead of failing the update - #168210
Conversation
Retry required update-run ledger transactions for up to two minutes and warn instead of aborting when expendable bookkeeping remains locked. Keep recovery admission and lifecycle receipts mandatory, preserving synchronous transaction and worker settlement boundaries. Refs #168072. Thanks @jlapenna for the contention report.
|
🦞👀 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. What this changesThis PR extends required CLI ledger waits, makes optional progress receipts best effort, and refreshes parent database admission after Doctor settles. Example: A competing SQLite writer blocks an optional updater-runtime-retention receipt after state handoff.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR provides useful updater resilience, and the earlier findings are resolved; no concrete introduced defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe update CLI sends phase and progress mutations to the shared-state worker, which checks recovery and live authority before writing SQLite receipts consumed by status, finalization, and recovery. flowchart TD
A[Update CLI] --> B[Execution guards]
B --> C[Shared state worker]
C --> D[Recovery receipt policy]
D --> E[SQLite writer]
E --> F[Update run ledger]
F --> G[Status and recovery]
C --> H[Optional receipt warning]
Technical reviewBest possible solution: Land the focused updater resilience change after required validation, while retaining separate ownership of the cron writer-hold repair. Do we have a high-confidence way to reproduce the issue? Current-main source propagates progress-write contention, and the linked report contains native failure traces plus a maintainer reproduction of the competing writer; this review ran no target code. Is this the best way to solve the issue? Separating recovery requirements from diagnostic retention is appropriate updater policy, while shortening cron's transaction-held host dependency remains a separate root-cause repair. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 654c8599da70. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +117, Tests +289, Docs +9, Other -1. Total +414 across 19 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel 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 10, 2026, 1:55 PM ET / 17:55 UTC (Revision 5). |
|
Merging at pinned head |
…penclaw#168210) Recovery-critical update history writes wait for a contended writer; bookkeeping steps use a 1 s budget and warn and continue when the database is locked; Gateway writes keep 5 s. Doctor invalidates cached schema admission after child-process migration. Refs openclaw#168072.
…168210) (2026.10.5 backport) Recovery-critical update history writes wait for a contended writer; bookkeeping steps use a 1 s budget and warn and continue when the database is locked; Gateway writes keep 5 s. Refs #168072. Backport notes: took the driver busy-wait budget, the bookkeeping-skip path, required-step classification, worker lock handling and their regression tests. Left out the Doctor-child revokeSqliteDatabaseAdmissionsForPath() call: main's cached schema-admission module (sqlite-database-admission.ts, #167739 and later) does not exist on 2026.10.5, so there is no cached admission to invalidate after Doctor migrates in a child process. The added update-command-doctor-child regression still verifies that the parent sees the child's newer schema on this branch. The contention test drops its isRetainedStep() precondition: the expanded retained-step list (#168290, #168409) is a separate diagnostics feature not on 2026.10.5; the bookkeeping-skip behavior under test is unchanged. Extracted-from: b2e11a2
…168210) Backport of b2e11a2 (#168210) adapted for 2026.10.3. Wait/bookkeeping logic only. Dropped the Doctor-child schema admission revocation (needs main's sqlite-database-admission module), its test, and unrelated test-support, mock-baseline and vitest-path churn. Mutation worker keeps #169283's pre-BEGIN grant. Contention tests drop main-only retained-step names and assertions. (cherry picked from commit b2e11a2)
What Problem This Solves
Updates must not abort because an optional progress receipt encounters a busy shared-state writer. This addresses the
updater-runtime-retentionincident in #168072. Thanks @jlapenna for the incident evidence.The latest CI failure exposed a production classification bug: main retained additional timing steps for diagnostic history, while this PR used that retention list to decide which writes recovery requires. Retaining a timer accidentally made its write fatal under contention.
User Impact
The update CLI explicitly allows required worker-backed writes up to 120 seconds for SQLite writer admission. Gateway-side callers keep their ordinary five-second budget. Optional progress and timing writes use a one-second budget, then warn and continue without claiming a committed receipt.
Recovery-critical phase, ownership, rollback, and failure receipts remain required. History eviction priority now has no effect on that decision. No schema, config, environment, CLI option, or dependency change is authored by this PR.
Why This Change Was Made
isRequiredUpdateRunStepnow owns an explicit recovery policy rather than borrowingisRetainedStepfrom bounded-history compaction. The recovery policy keeps phase transitions, finalization, driver identity, notice custody, reconciliation, database recovery diagnostics, rollback, and failed/signaled receipts. Timing-only retention, candidate, and handoff observations remain best effort.The long budget is opt-in from the update driver's existing asynchronous writer path. SQLite owns native busy retries; no transaction is held while an application retry loop waits, and admitted mutations are not replayed. Mutation and commit restore the ordinary five-second budget. The separate Doctor fix invalidates the parent's schema admission after its child settles, using the child's effective state path.
The exact failing CI merge base (
c3fcd1554c3405c942bc03ec85fcbac8a0bb12a3) was integrated normally, without rewriting history, so local proof includes main's new retained timing keys. The production fix is independent of platform timing.Evidence
Revision head:
7a069cbfa2785c001eef280c75228a676b4b2243.8cd4441af05756932b1d42125768e9941f3868b3, combining this branch with the base above. Main commit5c63a7867a80(fix: retain updater preparation and service handoff timings #168409) addedupdater-runtime-retentionand its diagnostic row to compaction retention. That made the old recovery predicate classify them as required. The unmerged branch passed standalone Linux; the actual merge policy reproduced the failure. Earlier macOS repetition was not proof against that merge.ERR_SQLITE_ERROR,errcode: 5, correctly recognized as contention; it was the required/bookkeeping decision that was wrong.node:24, digestsha256:3d27e5c11e5786e309ec3e03f93ae536eb36e6e5eb3714d5eb3300a36157add0; Node 24.21.0, Linux ARM64, SQLite 3.53.4. The worktree was mounted read-only and copied to a private volume; HOME and state were isolated. Command:OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/infra/update-run-contention.test.ts. Per-run wall time 14–21s; measured test time 5.489–6.257s (median 5.920s). Committed production/test hashes exactly match the tested copies.SQLITE_BUSYfailures to test policy directly, verifies no receipt or transaction admission is claimed, and checks warning/continued terminal-outcome behavior. Required writes preserve the driver's native busy budget and can succeed on a subsequent attempt. One real SQLite case keeps a competing transaction open with a zero busy timeout; there are no sleeps, global clocks, or timed-release simulations. The former simulated 107-second test is removed and is not claimed as current proof.madge: zero import cycles.check-changedpassed its initial guards, core typecheck, and all 27 test type graphs. It remains non-green for inherited base issues: UI test roots 722 exceed 720 intest/tsconfig/tsconfig.core.test.json; unuseddefaultintools/solid-lint/index.mjs; unusedresolveSessionConversationStub/resolveSessionTargetStubinsrc/agents/tools/sessions-channel-fixture.test-support.ts. Those files match the integrated base. Core lint initially caught three missing braces in the rewritten test; they were fixed, both changed files then passed the same typed core lint configuration, and the exact final test file passed the ten Linux runs above. Remaining ownership/cycle/script guards passed; no baseline was altered.38032195500; invalidating parent admission repaired it, and ten local Linux requester runs passed with the original assertion. The shared command-transport mock and legacy-handoff fixture use their actual helper/writer owners; no assertions were weakened.Cumulative numstat against the integrated CI base: production +151/-34 (+117 net); tests +292/-7; test support/routing/baseline +40/-37; docs +9/-0. Total +492/-78 across 19 files. Hosted CI on this head is pending. No PR merge or live operator update is performed.