Repository navigation
fix: stop updates failing with "database is locked" when another OpenClaw process is writing - #200742
Conversation
|
🦞👀 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 SQLite lock-contended lease release to five seconds and includes exhausted releases in the existing background cleanup. Example: Another process holds the state database write lock for three seconds while Doctor releases its lease.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful: current main retains the shorter release budget and maintenance-only background retry; the reviewed patch fixes both without a blocking correctness or security finding. Priority: P0 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherDoctor and other state operations acquire persisted leases; the shared lease owner drains work and heartbeats, then deletes its own lease through native or worker storage. flowchart TD
A[Doctor or state operation] --> B[Shared lease owner]
B --> C[Operation and heartbeat settlement]
C --> D[Bounded lease release]
D --> E[SQLite state leases]
D --> F[Retained background cleanup]
F --> E
Technical reviewBest possible solution: Use the existing lease-release and retained-cleanup owners to absorb transient SQLite contention while preserving ownership, expiry, and error boundaries. Do we have a high-confidence way to reproduce the issue? The source exposes the two-second release failure, the added regressions exercise real SQLite contention through the lease owner, and the public report records failing base upgrades; this review ran no target code. Is this the best way to solve the issue? The patch is a focused repair at the shared owner, with separate regressions for foreground release and eventual cleanup and no additional lifecycle machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 00d105d9fa7c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +7, Tests +97. Total +104 across 3 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 (1 earlier review cycle)
Reviewed November 17, 2026, 7:14 PM ET / November 18, 2026, 00:14 UTC (Revision 2). |
… contention A state lease's release gave up after 2 s of SQLite lock contention and, for worker-cleanup leases, threw the raw lock error. Doctor maintenance steps that had already committed their work (media persistence, plugin session repair, transcript directives) then failed with a bare "database is locked", leaving updates post-update-failed and sometimes the Gateway stopped. The unreleased lease also blocked the next acquirer until its stored expiry. Lock contention during release now waits the same 5 s busy bound every shared-state writer uses, and a release that still loses to a writer is retried in the background like offline-maintenance contention. Refs #197083
8112a05 to
684b19d
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@clawsweeper re-review The merge conflict is resolved: rebased onto main, keeping both main's renewal tests and this PR's release tests. The body now includes the latest-stable proof. From published 2026.11.5 under writer load, base failed 4 of 4 and the fix passed 4 of 4, with config and data intact. |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…Claw process is writing (openclaw#200742) * fix(state): keep lease release waiting through ordinary SQLite writer contention A state lease's release gave up after 2 s of SQLite lock contention and, for worker-cleanup leases, threw the raw lock error. Doctor maintenance steps that had already committed their work (media persistence, plugin session repair, transcript directives) then failed with a bare "database is locked", leaving updates post-update-failed and sometimes the Gateway stopped. The unreleased lease also blocked the next acquirer until its stored expiry. Lock contention during release now waits the same 5 s busy bound every shared-state writer uses, and a release that still loses to a writer is retried in the background like offline-maintenance contention. Refs openclaw#197083 * test(state): restore the renewal test close after rebase Co-authored-by: Peter Steinberger <[email protected]>
…Claw process is writing (#200742) * fix(state): keep lease release waiting through ordinary SQLite writer contention A state lease's release gave up after 2 s of SQLite lock contention and, for worker-cleanup leases, threw the raw lock error. Doctor maintenance steps that had already committed their work (media persistence, plugin session repair, transcript directives) then failed with a bare "database is locked", leaving updates post-update-failed and sometimes the Gateway stopped. The unreleased lease also blocked the next acquirer until its stored expiry. Lock contention during release now waits the same 5 s busy bound every shared-state writer uses, and a release that still loses to a writer is retried in the background like offline-maintenance contention. Refs #197083 * test(state): restore the renewal test close after rebase Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit b1ec281) Release adaptation: keep the maintenance-line native/worker lease owner and existing-schema admission behavior; import only its existing busy-timeout constant. Resolve the append-only contention-test conflict without unrelated renewal tests. Retain the branch native best-effort fallback; exact-worker failed cleanup remains with the existing resource owner. No schema, SDK, config, or dependency changes. Companion audit: no later same-path commits or PR-number follow-ups for #200742 through main 74e5127. #200328 is already implemented at cef3501, with predecessor-stop custody retained; do not duplicate it or the separately owned #200659/#200805. The 97-line allocation covers two distinct real-SQLite regressions: completed work survives ordinary contention and failed release cannot strand its lease. Proof: both new regressions fail on 0678cec; all 19 selected lease tests pass after repair. The four #200328 owner suites pass 94 tests (3 skipped). Formatting and git diff --check pass. Targeted lint/type wrappers refuse shared symlinked dependencies; final isolated checks and full release validation remain with the release owner. No live Gateway or installed state was modified. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
#198968) * fix(update): keep the failure that started recovery in failure reports After any update failure, the recovery steps that follow also fail (gateway migration recovery, package-backup-retention, gateway recovery verification). The failure-report sanitizer kept only the latest three failed steps and pruned oldest first, so the step that started recovery was always dropped, and users could not report what went wrong. Keep the first failed step alongside the latest two, and when the byte budget forces pruning, drop middle records before it. The latest failure still wins when only two remain. Refs #197083 * test(update): expect the triggering failure in recovery triage prompts The recovery triage prompt fixture has five failed steps. Failure reports now keep the first failed step with the latest two, so the oldest failure replaces the second-latest one in the expected prompt details. Refs #197083 * fix(update): protect the latest failure when pruning failure reports Pruning removed the second record when the trigger came first, so a retained lint inventory record after the latest failure made the latest failure the one dropped. Protect the trigger and the latest failure by identity, drop other records first, and drop the trigger before the latest failure. Refs #197083 (cherry picked from commit 5df28e7) Backport review: source applies unchanged. #200322 is orthogonal SQLite diagnostic enrichment; #200742 repairs a separate lease owner. Both are outside this report-retention fix. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
…Claw process is writing (#200742) * fix(state): keep lease release waiting through ordinary SQLite writer contention A state lease's release gave up after 2 s of SQLite lock contention and, for worker-cleanup leases, threw the raw lock error. Doctor maintenance steps that had already committed their work (media persistence, plugin session repair, transcript directives) then failed with a bare "database is locked", leaving updates post-update-failed and sometimes the Gateway stopped. The unreleased lease also blocked the next acquirer until its stored expiry. Lock contention during release now waits the same 5 s busy bound every shared-state writer uses, and a release that still loses to a writer is retried in the background like offline-maintenance contention. Refs #197083 * test(state): restore the renewal test close after rebase Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit b1ec281) Release adaptation: Preserve baseline lease contention tests and append only the two source regressions; omit unrelated prior renewal tests from conflict context.: Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 1d229c5e82fc20ca32c0c8625942391dfa0101f3)
…Claw process is writing (#200742) Baseline adaptation: Use the .33 SQLite busy timeout for lock-contended release and retain aggregate-aware cleanup retry classification with exact lease ownership. (cherry picked from commit b1ec281) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 465a2c0b9aba69a4187ee6366f83af0a3b9c7b59)
Related: #197083
What Problem This Solves
Updating OpenClaw can fail at the very end with "database is locked" even though the update's data migration already finished. This happens when another OpenClaw process, such as a status check, the old updater, or a CLI command, briefly holds the state database. The update then reports
post-update-failed. In some runs the Gateway is also left stopped with "data at risk", and the user has to runopenclaw update repair.User Impact
User impact: updates and
openclaw doctor --fixno longer fail when another OpenClaw process holds the state database for a few seconds, and a step that finished its work is no longer reported as failed.Why This Change Was Made
Doctor's maintenance steps (media persistence, plugin session repair, transcript directives) run while holding a state lease. Releasing that lease retried SQLite lock contention for only 2 seconds, then threw the raw lock error. Every other shared-state writer waits 5 seconds. So a step whose work had already committed failed with a bare "database is locked". The lease row also stayed behind, so the next step waited on it and failed with "lease … is held by …".
Releasing a lease now waits the same 5-second busy bound as any other writer, but only for plain SQLite lock contention; offline-maintenance contention keeps its 2-second window. If a writer still holds the lock past that, lease cleanup retries in the background, as it already did for offline-maintenance contention, so an unreleased lease no longer blocks later steps until it expires.
Evidence
237e3e4fe0dthrough the Gateway'supdate.run, with a 400 MB state database and an outside writer holding the write lock.state-migrated-no-rollbackwith the Gateway stopped.post-update-failed, with "Plugin session repair did not settle: database is locked" or "plugin lifecycle lease … is held by …".237e3e4fe0dplus this patch) passed 11 of 12, against 12 of 18 failing on base. The one remaining failure has a different cause: the old 11.4 Gateway acquired a plugin lifecycle lease during its own startup maintenance and was stopped for the update without releasing it, so main's Doctor met a lease held for up to 300 s. It is tracked as a separate follow-up.src/state/openclaw-state-lease-contention.test.ts:database is locked(errcode 5); green with the fix.pnpm tsgo:core, oxlint, and oxfmt are clean.