Skip to content

fix(update): ride out state database contention instead of failing the update - #168210

Merged
steipete merged 8 commits into
mainfrom
upd/upd-l1532
Oct 10, 2026
Merged

steipete merged 8 commits into
mainfrom
upd/upd-l1532

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Updates must not abort because an optional progress receipt encounters a busy shared-state writer. This addresses the updater-runtime-retention incident 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

isRequiredUpdateRunStep now owns an explicit recovery policy rather than borrowing isRetainedStep from 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.

  • CI run 38068510314, job 114261240504 tested merge 8cd4441af05756932b1d42125768e9941f3868b3, combining this branch with the base above. Main commit 5c63a7867a80 (fix: retain updater preparation and service handoff timings #168409) added updater-runtime-retention and 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.
  • Linux negative control on the integrated base: 6 failed / 8 passed. Four retained-timing policy cases, the synchronous warning case, and the real SQLite lock case failed before the production predicate fix. The native error was ERR_SQLITE_ERROR, errcode: 5, correctly recognized as contention; it was the required/bookkeeping decision that was wrong.
  • Final Linux Docker: 10/10 file runs, 14/14 tests each. Image node:24, digest sha256: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.
  • The replacement suite injects native-shaped SQLITE_BUSY failures 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.
  • Direct production importers and ledger/diagnostic siblings: 9 files, 114 tests passed, 166.13s wrapper wall. madge: zero import cycles. check-changed passed 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 in test/tsconfig/tsconfig.core.test.json; unused default in tools/solid-lint/index.mjs; unused resolveSessionConversationStub / resolveSessionTargetStub in src/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.
  • Earlier requester regression proof remains relevant to unchanged Doctor code: the exact migrated requester case failed on main hourly run 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.
  • Fresh independent read-only review found no actionable P1/P2 or omitted recovery consumer. Managed Codex review was attempted with isolation and returned timeout/HTTP 401 without a verdict.

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.

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.
@clawsweeper

clawsweeper Bot commented Oct 10, 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 cli CLI command changes size: L labels Oct 10, 2026
@steipete
steipete marked this pull request as ready for review October 10, 2026 05:06
@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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The receipt failure can abort the update.
  • After: The receipt waits up to one second, warns if still blocked, and lets the update continue without claiming persistence.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation preserves recovery boundaries and resolves earlier findings; evidence remains primarily harness-level, and the broader linked incident is only partially addressed.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence covers Linux policy regressions, a real zero-timeout SQLite lock, and Doctor admission tests, but does not establish the shipped upgrade and subsequent-update scenario.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: An update can abort when a progress receipt encounters a temporarily busy state database.
Reason: The maintainer-authored direction improves updater resilience, but the linked incident's cron transaction-held authority dependency remains unresolved.

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
Reviewed head: 7a069cbfa2785c001eef280c75228a676b4b2243

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not show a latest-stable driver/candidate upgrade and subsequent installed-driver update under real contention with settings and data preserved.
Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

  • Optional progress receipt persistence changes intended behavior with a stated reason (2bf30ba: Retain update history and reports across execution and recovery.)
  • Worker-owned phase and progress writes keeps the original intent (ce38326: Preserve captured authority and join accepted worker writes through native settlement before cleanup.)
  • Recovery admission keeps the original intent (8879e5e: Inspect completed recovery history without granting execution authority or ignoring pending recovery.)
  • Doctor child settlement keeps the original intent (8f364a7: Join write-capable Doctor descendants before recovering a migrated Gateway.)
  • Diagnostic timing retention keeps the original intent (5c63a78: Preserve timing observations within existing history bounds without changing update or recovery decisions.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +117, Tests +289, Docs +9, Other -1. Total +414 across 19 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 11 151 34 +117
Tests 6 332 43 +289
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 19 492 78 +414

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +151/-34; tests +292/-7 Production growth implements explicit receipt classification, worker contention handling, and Doctor admission invalidation; test growth covers those distinct contracts.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The change addresses a concrete update failure under shared-state contention, with limited demonstrated incidence and no established data loss.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-10T05:12:56.637Z sha 536957d :: needs changes before merge. :: [P1] Keep the contention retry loop off the serving Gateway thread
  • reviewed 2026-10-10T07:05:58.943Z sha d18812e :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T12:04:47.838Z sha ae70092 :: needs changes before merge. :: [P2] [P2] Repair the new bookkeeping contention regressions
  • reviewed 2026-10-10T16:46:19.641Z sha 3cf2c9f :: needs changes before merge. :: [P2] [P2] Use expendable steps in the bookkeeping-skip fixtures

Reviewed October 10, 2026, 1:55 PM ET / 17:55 UTC (Revision 5).

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 Oct 10, 2026
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: L and removed size: M labels Oct 10, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 10, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Merging at pinned head 7a069cbfa2785c001eef280c75228a676b4b2243 past one inherited red: check-lint fails on scripts/lib/managed-cleanup-handoff.mts:224 (consistent-return). That file is not in this PR's diff; the error came from main and is already fixed there by 493a499 ("fix(tooling): return a promise from every cleanup release path"). All PR-owned checks are green, including the Linux update-run-contention shard that failed earlier.

@steipete
steipete merged commit b2e11a2 into main Oct 10, 2026
158 of 161 checks passed
@steipete
steipete deleted the upd/upd-l1532 branch October 10, 2026 18:01
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…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.
RomneyDa pushed a commit that referenced this pull request Oct 13, 2026
…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
RomneyDa pushed a commit that referenced this pull request Oct 13, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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