Repository navigation
fix: finish updates when another tool reads OpenClaw's databases during the update - #201330
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 recognizes read-only SQLite WAL-index rebuilds without treating unchanged databases as outside writes during an update. Example: During an upgrade from 2026.11.5, a Python sqlite3 monitoring connection opens retained WAL data using mode=ro.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses a verified update failure still present on fetched main. The prior finding is resolved, and no actionable introduced defect was found; current-head CI remains pending. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe updater captures database generations before candidate Doctor runs; isolated inspection workers and migration attribution produce receipts that determine whether automatic database restoration remains safe. flowchart TD
A[Managed updater] --> B[Captured database generations]
B --> C[Candidate Doctor]
C --> D[Isolated generation inspection]
E[Outside SQLite reader] --> D
D --> F[Migration attribution and settlement]
F --> G[Update and restoration outcome]
Technical reviewBest possible solution: Land the existing generation-owner repair after its current-head CI gate passes, keeping distinct lock and recovery failures tracked separately. Do we have a high-confidence way to reproduce the issue? The supplied managed-upgrade traces reproduce the failure with a Python mode=ro monitor, and fetched main retains the rejecting predicates; this read-only review executed no target code. Is this the best way to solve the issue? The smallest complete fix belongs in the existing generation owner: recognize only the no-write rebuild, retain its equivalent generation through Doctor admissions, and preserve commit-sensitive refusal. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 107bf531ef30. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +72, Tests +201, Docs +8, Other 0. Total +281 across 13 files. Added test files: 1. 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. 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 (1 earlier review cycle)
Reviewed November 18, 2026, 1:34 PM ET / 18:34 UTC (Revision 2). |
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 head is now |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…ng the update (openclaw#201330) * test(update): reproduce WAL-index rebuild refusals at migration publication * fix(update): accept a WAL index rebuilt by an outside reader at migration publication * refactor(update): drop redundant rebuilt-index guards * test(update): include rebuilt-index alternates in generation-pair mocks * refactor(update): compare accepted generations by membership; keep settlement unchanged * fix(update): keep rebuilt-index alternates across repeated Doctor admissions * test(update): keep the same-content control's committed rows identical Co-authored-by: Peter Steinberger <[email protected]>
…ng the update (#201330) * test(update): reproduce WAL-index rebuild refusals at migration publication * fix(update): accept a WAL index rebuilt by an outside reader at migration publication * refactor(update): drop redundant rebuilt-index guards * test(update): include rebuilt-index alternates in generation-pair mocks * refactor(update): compare accepted generations by membership; keep settlement unchanged * fix(update): keep rebuilt-index alternates across repeated Doctor admissions * test(update): keep the same-content control's committed rows identical Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 0a39956) Co-authored-by: RomneyDa <[email protected]>
Main made rebuiltIndexAlternates a required field of UpdateDatabaseGenerationPair (openclaw#201330), and admit() reads it. The digest-sharing capture test mocked the pair without it.
…ng the update (openclaw#201330) * test(update): reproduce WAL-index rebuild refusals at migration publication * fix(update): accept a WAL index rebuilt by an outside reader at migration publication * refactor(update): drop redundant rebuilt-index guards * test(update): include rebuilt-index alternates in generation-pair mocks * refactor(update): compare accepted generations by membership; keep settlement unchanged * fix(update): keep rebuilt-index alternates across repeated Doctor admissions * test(update): keep the same-content control's committed rows identical Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit 0a39956) Release adaptation: Adapted capture field and matching calls into existing synchronous migration-attribution owner rather than importing future async/extracted context. Preserved synchronous native custody. Removed unrelated future client credential fixture. Retained WAL frame/salt/checksum identity and true-write tests; no persistent schema change. Co-authored-by: RomneyDa <[email protected]>
…4095) Closes #204078 ## What Problem This Solves On Windows, opening a read-only SQLite connection during an update's Doctor step can fail the update with “SQLite migration source changed after update capture.” A status reader, backup tool, or database browser can trigger this without writing anything. Users then need `openclaw update status` and `openclaw update repair`. ## User Impact Read-only readers no longer count as database writes after a WAL checkpoint. A real change to committed content or file identity still refuses migration. This fix is in the candidate's Doctor, so it applies to first hops from published v2026.11.7; the installed updater needs no backport. No schema, stored-field, fingerprint-format, option, or lock changes. ## Why This Change Was Made A checkpoint can leave an empty WAL with a nonzero shared-memory index counter and commit checksum. A read-only reopen rebuilds that disposable index and clears both values while preserving database bytes and identity. The existing rebuilt-index equivalent covered only nonempty WALs. Extend that existing equivalent to a reader rebuild completed between capture and source verification. The equivalent still includes the original file identity and committed-content hash. The same-observation guard is unchanged. No new state, hook, retry, or reader lock. Existing native-generation and migration tests keep real-write refusal, including a checkpointed retained index followed by a reader rebuild. Accepted edge: a reader inside the guard's own observation window can still cause a rare, visible refusal; recover with `openclaw update status`, then `openclaw update repair`. The separate SHM-absent/coarse-metadata rapid-write window in #204101 exists on main and is unchanged here; its fixture and evidence limits are recorded in that issue. ## Evidence - Controlled original Windows failure: `8c73a489-9f22-4a56-936a-81b2f33182ce`; one read-only connection during Doctor. Clean no-reader control succeeded. - Native Windows probe: counter `03000000` → `00000000`, checksum `0443775e300eeaf7` → `0000000000000000`, WAL length 0, with identical database SHA-256/device/inode/birthtime. Linux and macOS show the same transition; real-write controls change database hashes. - Owning migration regression fails on unchanged main at the exact source-changed guard. - Formatting/lint passed on the narrowed head. An earlier local test attempt failed collection because concurrent packaging rewrote `package.json`; that was setup contamination, not a product verdict. - Narrowed head `57dc1a001943` built and passed canonical tarball validation on isolated AWS. First-hop archive SHA-256: `9e4fb9cc0fcef5f0e3bcfff94e87c75ebde704e73d41ecc2a1f4ee0ab5856714`. Its build ID is bound to that exact commit. Hosted CI is green on this head, including the Node and Bun write-refusal controls; the serial focused run on AWS passed. - Final-head local ClawSweeper review (`4ff5ebdd239a..57dc1a0`) completed: patch correct, zero findings, security cleared. - Windows, reader case: a first hop from published v2026.11.7 to this head with one read-only reader after the capture succeeded (run `39c3fcbb-281c-4cda-8a86-38dcccb09ad4`; the candidate serves). [Proof](#204095 (comment)). - Windows, write control: the same first hop with one committed write during Doctor was refused at the source-changed guard (run `2c8af5ee-189c-4b6c-a39c-5f5ac745d6e5`), the user recovers by following `openclaw update status` (stop the service, then `openclaw update repair`; repair run `7a6aff24-8779-4594-833d-8d389de371a0` succeeded with warnings). - Accepted edge case: a reader that opens inside the guard's own short observation window, while the WAL index is absent, behaves as on main (#204101). (cherry picked from commit ab24e71) Release adaptation: Add only the checkpointed-index explanation next to stable retained-frame documentation. Inline the checkpointed setup in the existing generation writer control because stable has the retained-frame reader coverage in update-doctor-migration-wal-rebuild.test.ts rather than the upstream retainedWalFixture. Preserve the stable malformed-anchor fixture and include the upstream attribution scenarios unchanged. Companion audit: #201330 is present-equivalent via stable 0446f25, including retained-frame custody and repeated admission tests. 2c47390 is already selected earlier in this lane. Later same-path overlaps affect only updating.md for separate changes and are not-applicable; 1f4e88f cites this SHA as a green baseline for unrelated operator-authority tests. Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: RomneyDa <[email protected]>
…ng the update (#201330) Baseline adaptation: Carry the verified no-write WAL-index alternate through the shipped isolated Doctor capture and predecessor-stop receipt writer. Keep the flat generation inventory for older drivers and leave rollback publication and journal-mode restoration unchanged. (cherry picked from commit 0a39956) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 37a272dd5846a07b5723b58a0d65a2742695c54f)
…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)
Related: #197083
Related: #201085
What Problem This Solves
An update could fail and leave the Gateway stopped when anything outside OpenClaw briefly opened its SQLite databases read-only during the update. A monitoring script using Python
sqlite3withmode=rois enough. Doctor then reportedAutomatic database restoration cannot attribute migration writes: SQLite migration publication could not be verified, refused rollback because "the writer is unknown", and kept the Gateway down (state-migrated-no-rollback). One reporter was offline for 13 hours.User Impact
User impact: updates now finish when an outside tool reads OpenClaw's databases during the update. Automatic restoration stays available because nothing was written. Any real write after Doctor admits a database still refuses as before.
Why This Change Was Made
A database's WAL file can keep committed frames after the last writer exits, for example when a status or monitoring reader is still open at the time. The next process that becomes the only connection rebuilds SQLite's WAL index (
-shm) from those frames. A read-only open is enough. The rebuild resets the index change counter to zero and recomputes the header checksum. The frame count, last-frame checksum and salts stay the same, and so do the committed data. Doctor's write evidence includes that counter, so a no-write rebuild after Doctor's admission looked like a foreign commit. That happened in two places:The owner of the generation fingerprint (
update-database-generations.ts) now handles both:Doctor's update capture remembers that alternate from its own admission. It accepts the alternate at the migration pre-read, at companion checks, at every repeated admission and at settlement.
Why the signal stays sound. The alternate binds the digest of the committed content and the last frame's cumulative checksum. Any commit after admission appends frames and changes that checksum, including a commit that restores identical content. A WAL restart changes the salts. So the alternate cannot match a real write, and those cases still refuse. A regression test covers the same-content commit. The policy for a stale initial capture (#200328) and for predecessor-stop writes (#200569) is unchanged.
Rejected alternative: extending #200328's "warn and continue" policy to changes after admission. Maintainers deliberately kept post-admission checks strict, and a rebuild with no write can be proven, so it does not need a policy exception.
Production LOC: about +75 / −12 across five files, plus a doc paragraph in
docs/install/updating.md. Most of the growth is passing the new alternate field through the worker schema and the Doctor capture.Evidence
Live reproduction and fix on Crabbox AWS (Ubuntu, c7a.8xlarge). Each lane is a managed
update.runwith a 400 MB state database and an outside Pythonsqlite3mode=roreader. The reader holds a read transaction while the Gateway stops, which is how frames survive. It releases when the post-install Doctor starts and opens the databases again 10–60 s later, then keeps polling.05d1e6f1f1f)The fix runs include alternating base/fix lanes on the same box. The last four fix runs used a package built from this PR's exact head.
Every base failure:
failed.state-migrated-no-rollback).SQLite migration source changed after update capture.cannot open your existing data.Every successful fix run: the update
succeeded, the Gateway was active on the target, and none of the watched failure signatures appeared.The one failed fix run has a different cause. Under the aggressive 1.3 s polling, Doctor's own schema-admission step hit
database is lockedfrom the outside reader's lock. No rebuild or publication signature appeared. I'm tracking it as a separate follow-up.Regression tests:
update-database-generations.test.ts: a rebuild during the read binds the rebuilt generation and equals the earlier observation's alternate.update-doctor-migration-wal-rebuild.test.ts: migration is attributed when the rebuild happens during Doctor's read and after admission, with no warnings andunchanged: true. A same-content commit before the rebuild still refuses, and a rebuild between two Doctor admissions stays attributable.On base, the first two migration cases fail with the exact user signatures (
SQLite WAL commit publication could not be verified,SQLite migration source changed after update capture); with the fix they pass.Checks:
completes retirement …cases fail locally on base and on the fix alike: Node strip-only cannot load a parameter property inupdate-doctor-result.ts. They are unrelated.doctor-maintenancesettlement and worker suites: 54/54.tsgo:core, type-awareoxlint(core shard) andoxfmtare clean.Reviews: autoreview at P2 came back
scoped-cleanon the final head. An independentcodex execreview found one real issue: two test mocks lacked the new pair field. That is fixed ineaad4658610, and it found no other P0–P2 defect.Head delta since the live proof. The Crabbox lanes ran a package built from
eaad4658610. The landing head adds production edits, not a rebase. They fix thesession-identitybaseline ratchet that failed oneaad4658610, and they are behavior-equivalent to the proven head:readMatchingUpdateDatabaseGenerationnow takes the accepted generations as a list. It accepts the same values as before. The only theoretical widening, an empty-reader alternate equal to the rebuilt alternate, cannot occur: rebuilt alternates exist only when the WAL has frames, and empty-reader alternates only when it has none.admit()and at settlement, exactly when the observed generation equals it. It is now written as a loop over the remembered alternates.An intermediate commit (
4d705cc6ff5) briefly dropped the admit/settlement acceptance. The independent review caught that this breaks the production sequence of repeated admissions (finalization, predecessor stop, maintenance).7c40b6de1berestores it, with a regression test that fails without the restored acceptance and passes with it.Other changes:
src/infra/update-doctor-migration-wal-rebuild.test.ts, because the original file hit the 1000-line cap.update-database-generations.tsshrinks from 2 to 1.Follow-up from ClawSweeper, the same-content control now updates and restores one row (
WHERE value = …) and asserts the committed rows equal the admitted ones before expecting the refusal. That makes the refusal come from the new frames' checksum alone. The change is test-only.Redacted lane output (exact
eaad4658610build as 2026.11.28; base main as 2026.11.30)readyz=coremeans the core is ready. The lane uses a fake Telegram token, so the channel readiness probe reports degraded by design. These lane criteria check update status, the Gateway service, version, readiness and failure signatures. They do not count seeded rows separately; config is preserved, because the sameopenclaw.jsonserved the target.Head:
72e9f047d12