Skip to content

fix: let updates finish when another tool briefly reads OpenClaw's databases - #202541

Merged
steipete merged 3 commits into
mainfrom
codex/issue-201085-schema-admission-lock
Nov 20, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/issue-201085-schema-admission-lock

Conversation

@steipete

@steipete steipete commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Related: #197083
Related: #201085

What Problem This Solves

An update could fail right after installing the new version if anything else, such as a monitoring script, a status probe or a sqlite3 query, happened to have one of OpenClaw's databases open for a moment. Doctor then stopped with database is locked at "Update schema admission", and the update ended with the Gateway stopped until openclaw update repair was run.

User Impact

User impact: updates now wait a few seconds for short-lived outside readers to close instead of failing. If some other tool keeps a database open for the whole update, Doctor still stops the migration, but the error now names the database it could not take over, so you know which tool to close before running openclaw update repair.

Why This Change Was Made

Before migrating a database, the update takes exclusive access to it. In SQLite's WAL mode that requires every other connection to be closed. Doctor's migration connections used SQLite's default busy timeout of zero, so any momentary reader made the migration fail at once.

The exclusive-access step (updateSqliteMigrationSteps in src/infra/update-doctor-migration-attribution.ts) now waits at least the standard 5 s busy timeout, then restores the connection's own setting. A connection that already uses a longer timeout keeps it. A database still held after the wait fails with a message that names its path.

Keeping exclusive access is deliberate: it is what lets the update attribute writes and keep rollback safe. Supporting a tool that holds a database open for the entire update would need a different design and a maintainer decision.

Production: +20/-1 in one file. Docs: +5 in docs/install/updating.md.

Evidence

  • Regression test (src/infra/update-doctor-migration-wal-rebuild.test.ts): an outside reader in a worker thread stays open until the migration's BEGIN EXCLUSIVE starts, then closes 200 ms later. Base fails deterministically with database is locked (errcode 5); the fix waits and passes.

  • Touched and consumer suites (attribution, WAL-rebuild, doctor-schema-migrations, state-db-open, client-credential-store): 105 passed.

  • Static checks: tsgo:core and tsgo:core:test clean; oxlint and oxfmt clean.

  • Live, Crabbox AWS (published 2026.11.5 to target via openclaw update, outside read-only reader polling every 0.1 s):

    Target Result
    Base main 6502a5769c0 3/3 failed: rc=1, Gateway down, state-migrated-no-rollback, database is locked at Update schema admission
    This fix 3/3 succeeded: readyz 200, no flagged log lines
  • Persistent busy-writer lane (outside writer holds the agent DB open for the whole update): still refused by design, now with Update migration could not take exclusive access to <path>. The Gateway recovered healthy.

  • Reviews:

    • $autoreview on the final head: scoped-clean.
    • Independent codex exec review, first pass: one P2. The timing-based test could pass on base, so the reader is now gated on the exclusion attempt (1a53212345f).
    • Independent codex exec review, final head: no findings.
  • CI: green on 1a53212345f.

Update migrations take native exclusion with PRAGMA locking_mode=EXCLUSIVE
and BEGIN EXCLUSIVE. In WAL mode that needs every other connection to the
database closed. Doctor's migration connections are opened with SQLite's
default busy timeout of 0, so an outside reader or probe that had the
database open at that instant failed the migration immediately with
"database is locked" and left the update post-update-failed.

Acquire the exclusion with at least the standard 5 s busy timeout, restoring
the connection's own policy afterwards, and name the held path when another
connection keeps the database open past that wait.

Refs #197083
Refs #201085
The reader now stays open until migration exclusion starts, so the regression test fails deterministically without the busy-timeout fix.
@clawsweeper

clawsweeper Bot commented Nov 20, 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.

@steipete
steipete marked this pull request as ready for review November 20, 2026 15:17
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Nov 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T15:19:31.858121Z 1a53212 Draft marked ready
ℹ️ 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 20, 2026
@clawsweeper

clawsweeper Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR waits for brief SQLite readers to close before acquiring migration exclusion and identifies the database when exclusion fails.

Example: An outside read-only connection holds source.sqlite until 200 ms after migration exclusion starts.

  • Before: A connection with a zero busy timeout immediately fails with database is locked.
  • After: Exclusion waits at least 5 seconds, allowing the reader to close and migration to proceed, then restores the connection's previous timeout.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation and meaningful SQLite regression support correctness; the published behavior evidence remains too thin for merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
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 fail and leave the Gateway stopped because another process briefly has a database open.
Reason: The maintainer-authored direction is a useful, bounded repair; its reference-only links appropriately leave the broader reports' other failures open.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a concrete update failure in the existing migration owner, and no introduced correctness or security defect was found.

Priority: P1
Reviewed head: 1a53212345f03b84968f658d3194de6b32d8ed3d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted terminal output or logs from a 2026.11.6-to-fixed-build CLI upgrade with the transient reader, successful readiness, and existing settings and data preserved; redact IPs, API keys, phone numbers, and non-public endpoints.
Agent review details

How this fits together

Candidate Doctor runs captured database migrations through the shared attribution owner, which acquires native exclusion and publishes generation evidence used for safe update settlement and rollback.

flowchart TD
  A[Candidate Doctor] --> B[Migration attribution owner]
  B --> C[Scoped SQLite busy timeout]
  C --> D[Native exclusive access]
  E[Outside SQLite reader] --> D
  D --> F[Migration and generation receipt]
  F --> G[Update settlement]
Loading

Technical review

Best possible solution:

Keep the bounded wait in the existing exclusion owner while preserving connection policy, native custody, generation checks, and rollback safeguards.

Do we have a high-confidence way to reproduce the issue?

Current main exposes the zero-timeout exclusion path, and the gated real-SQLite regression supplies a concrete reproducer; this read-only review executed no tests or product code.

Is this the best way to solve the issue?

The change addresses lock acquisition at its shared owner using existing timeout and error-classification utilities; every added hunk serves the reported contention failure, and the worker test catches a distinct boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4665e7ebd24e.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • RoboClaw: Raw commit 384e6a6 adds src/infra/update-doctor-migration-attribution.ts:186 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 384e6a6647b1; files: src/infra/update-doctor-migration-attribution.ts)

PR surface

Source +19, Tests +45, Docs +5. Total +69 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 20 1 +19
Tests 1 45 0 +45
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 70 1 +69

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P1: Brief SQLite contention can fail update activation and leave a managed Gateway stopped until manual recovery.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: Brief SQLite contention can fail update activation and leave a managed Gateway stopped until manual recovery.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish 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 execution lanes are retired.

Reviewed November 20, 2026, 10:35 AM ET / 15:35 UTC.

@steipete steipete changed the title fix(update): wait for short-lived readers before migration exclusion fix: let updates finish when another tool briefly reads OpenClaw's databases Nov 20, 2026
@steipete
steipete merged commit dc73ec0 into main Nov 20, 2026
220 of 224 checks passed
@steipete
steipete deleted the codex/issue-201085-schema-admission-lock branch November 20, 2026 18:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…tabases (openclaw#202541)

* fix(update): wait for short-lived readers before migration exclusion

Update migrations take native exclusion with PRAGMA locking_mode=EXCLUSIVE
and BEGIN EXCLUSIVE. In WAL mode that needs every other connection to the
database closed. Doctor's migration connections are opened with SQLite's
default busy timeout of 0, so an outside reader or probe that had the
database open at that instant failed the migration immediately with
"database is locked" and left the update post-update-failed.

Acquire the exclusion with at least the standard 5 s busy timeout, restoring
the connection's own policy afterwards, and name the held path when another
connection keeps the database open past that wait.

Refs openclaw#197083
Refs openclaw#201085

* docs(update): note the migration exclusion wait for outside readers

Refs openclaw#197083

* test(update): gate the outside reader on the exclusion attempt

The reader now stays open until migration exclusion starts, so the regression test fails deterministically without the busy-timeout fix.

Co-authored-by: Peter Steinberger <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 23, 2026
…tabases (#202541)

* fix(update): wait for short-lived readers before migration exclusion

Update migrations take native exclusion with PRAGMA locking_mode=EXCLUSIVE
and BEGIN EXCLUSIVE. In WAL mode that needs every other connection to the
database closed. Doctor's migration connections are opened with SQLite's
default busy timeout of 0, so an outside reader or probe that had the
database open at that instant failed the migration immediately with
"database is locked" and left the update post-update-failed.

Acquire the exclusion with at least the standard 5 s busy timeout, restoring
the connection's own policy afterwards, and name the held path when another
connection keeps the database open past that wait.

Refs #197083
Refs #201085

* docs(update): note the migration exclusion wait for outside readers

Refs #197083

* test(update): gate the outside reader on the exclusion attempt

The reader now stays open until migration exclusion starts, so the regression test fails deterministically without the busy-timeout fix.

Co-authored-by: Peter Steinberger <[email protected]>
(cherry picked from commit dc73ec0)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 2bd5eff4b58cd5ca3db3b53a9fb8da2cbf37e90a)
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…tabases (#202541)

Baseline adaptation: Give the existing predecessor receipt native exclusion a bounded busy timeout, retaining the original receipt checks and settled connection lifecycle. Preserve and restore the caller timeout.

(cherry picked from commit dc73ec0)

Co-authored-by: RomneyDa <[email protected]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…aw#194058)

Failed-update triage now captures the operator's environment before managed candidate admission, so a coding agent installed only on the operator's PATH is still offered when the Gateway service's PATH differs. Restores the operator-environment contract from openclaw#134490 and keeps the launch confirmation from openclaw#143139.

Proof: shipped CLI on isolated Linux (Crabbox) with a running systemd Gateway: accept launches the operator-only agent, decline starts nothing, base 18bee8e reports no agent found; published 2026.11.1 upgrades to the fix with settings intact.

Co-authored-by: TorstenW <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: steipete <[email protected]>

(cherry picked from commit 7c702c3)

Release adaptation: Capture invoking operator env before candidate admission, forward to interactive triage only; preserve latest target selectors, confirmation and lease cleanup ordering. Exact three authorized production paths plus real lifecycle regression.

Follow-up dispositions: ad4863d fix: preserve the running installation when an agent updates its Gateway (openclaw#201570); dc73ec0 fix: let updates finish when another tool briefly reads OpenClaw's databases (openclaw#202541); d07b530 fix: clarify PostgreSQL schema upgrades for Git installs (openclaw#202098); e60ea9f test(update): add a Git release upgrade-survivor scenario (openclaw#201956); 2ef6f7b fix(update): build and serve Git releases outside node_modules (openclaw#201917); dbc1aa0 fix: keep the openclaw command and Gateway working after updating a pnpm install (openclaw#201735); f5e7641 fix: Git checkout updates across a schema change no longer end as post-update-failed after the new release starts (openclaw#201600); 2183caf fix: Git checkout updates no longer fail before the new release starts on a schema change or a busy database (openclaw#201463); 47e8649 fix: explain why Doctor cannot restore a scheduled job’s account (openclaw#201550); 8f2cfd4 fix: remove updater-only restrictions from agent maintenance guidance; cb5cfb2 fix: keep a doubtful killed-update recovery on the repair path (openclaw#201361); 24cb734 fix: keep carried-over scheduled jobs running after updates (openclaw#200653); d1276e1 feat(doctor): check OpenClaw ID member roles and honor an optional roles default (openclaw#197785); 0a39956 fix: finish updates when another tool reads OpenClaw's databases during the update (openclaw#201330); ea1c9d5 fix(update): settle remounted package publications before admission (openclaw#201336); 66b5212 fix(update): isolate malformed retained-install markers (openclaw#201199); 7e79c83 fix: let the next update finish a killed source checkout update (openclaw#201009); d905d8a fix: let the next update finish a killed update after the machine restarted (openclaw#200994); fdf0c95 fix: let the next update finish a killed update that had already installed the new version (openclaw#200866); 0c19bcd chore(release): close out 2026.11.5 on main (openclaw#200577); a1940e0 fix(matrix): keep explicit recovery available during deferred migration (openclaw#200805); 18b4776 improve: explain package baseline drift during updates (openclaw#200802); 1ad4cad fix(doctor): reclaim macOS updater runtimes blocked by non-updater processes (openclaw#200732); 427c857 fix: keep one missing archived transcript from blocking every update (openclaw#200733); 802e3f7 fix(update): keep valid cold archives from blocking updates (openclaw#200659); 23fca1a fix: let the next update continue after a killed update when nothing is left to repair (openclaw#200680); 3afe212 fix: let Doctor publish unchanged plugin migrations in any order (openclaw#200658); f65e4db fix(doctor): reclaim runtimes blocked by unrelated Linux processes (openclaw#200657); dab086c fix(update): let candidate Doctor read plugin dependencies from the staged package (openclaw#200595); 3447bee fix(update): keep updates going when the predecessor writes during its stop (openclaw#200569); 0ce9c77 fix: let the next update settle a package publication that a killed update left behind (openclaw#200550); ae31ea3 fix(update): repair handoffs in the journal-pinned lease store (openclaw#200532); 74020ea fix: continue updates when initial SQLite capture is stale (openclaw#200328); 6747b1e feat(update): run Git checkout installs from releases behind the release link (openclaw#199706); e3f8a67 fix(state): keep completed retained agent stores out of startup upgrade (openclaw#200284); 3c512c5 fix(gateway): move managed update lease operations off the main thread (openclaw#200169); ea69fcb chore(release): close out 2026.11.4 on main (openclaw#199956); 618bf31 fix(state): bound startup upgrade copies and pruning to owned state (openclaw#199929); e4a3093 perf(update): replace the candidate canary with a runtime contract check (openclaw#198268); 5dbf569 fix(update): plugin failures never fail an update or Gateway health; 764761e fix(update): refuse missing host prerequisites in one line and record a cause per attempt; 4c4fef4 fix(ui): update dialog claims installation before progress is confirmed (openclaw#199254); 136e1f6 fix(update): retrying an update from a dev checkout is refused after a killed update (openclaw#198673); 3bd03da fix(update): avoid duplicate database copies while the Gateway is stopped (openclaw#198148); 68a839b fix: isolate held agent databases until explicit restoration (openclaw#198180); e333f7e chore(ci): drop retired test-lines allocation records (3/3) (openclaw#197657); fd6fa47 fix: converge Gateway updates with environment-only service overrides (openclaw#196371); 7cf5e75 fix: clarify split-install updates and blocked Doctor repairs (openclaw#196342); 6ff8c86 fix(update): retain lazy sqlite catalog generation (openclaw#197095); 930e1f7 fix: keep stable updates and recovery free of premature migrations (openclaw#196474); a15f737 fix: preserve external plugin data during update rehearsal (openclaw#196301); 92798ae fix: updates survive interrupted heartbeat runs (openclaw#195656); c1e55e2 fix(update): restore LaunchAgent registration after repair contention (openclaw#195406); 715c610 fix(doctor): repair retained ISO session end timestamps (openclaw#194685); 689cfc8 fix(update): reclaim dead closing triage repair leases (openclaw#194503); 86bc89e fix(doctor): keep standing Codex parameter advice out of retirement blockers (openclaw#193650); 691bc8d fix(backup): read the backup engine without copying the live database (openclaw#194234); 000542f fix(backup): backups and updates fail on slow storage when a header probe batch misses its deadline (openclaw#194239); 31a65d5 fix(update): skip --no-lazy-fetch on Git versions without it (openclaw#194198); e45e99d fix(update): preserve dev update sources in tag-only Git clones (openclaw#193109)

Validation: Baseline2 intended operator-agent failures/32 controls passed; candidate34/34passed (194058-green.log). Accept launches synthetic operator-only CLI with expected env, decline starts nothing. Isolated updater flow, not live systemd/upgrade qualification.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 6689fd575ada8fe40a9593784deac18ec73041cd)
(cherry picked from commit 92e7a9fa223b0dc35801f25f70be90b472d9a6b7)
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S 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