Repository navigation
fix(update): finish managed updates when readers race the old updater's database capture - #200172
Conversation
A published updater (2026.11.3/11.4) can capture its database generations
while concurrent readers such as `openclaw update status` keep the WAL index
alive past its last ledger commit. When those readers exit, the next native
open rebuilds the index (iChange resets, same frames), so the committed
fingerprint changes without any write. The target Doctor then refused its
first attributed write ("SQLite migration source changed after update
capture"), the parent's rollback was refused by the same comparison, and the
parent's forward recovery migrated with the target Doctor and stranded the
Gateway stopped with "cannot open your existing data".
When the first admission already disagrees with the parent's capture, the
parent's restore is unavailable either way. Doctor now keeps reporting
unchanged=false (the parent still refuses restore), warns, and attributes its
own writes from the admitted observation, so the update completes forward.
Writes after admission, including between Doctor phases, still refuse.
|
🦞👀 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 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. |
|
Codex review: blocked before merge. What this changesDoctor rebases a stale database capture once at first admission so updates can finish forward while automatic restoration remains refused. Example: A managed update from 2026.11.4 captures a SQLite database while two update-status readers retain its WAL index.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 2 items remain Keep this PR open: it addresses a concrete managed-update failure, but the edited legacy regression fails on the reviewed head. Priority: P1 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe installed updater passes captured database generations to candidate Doctor; Doctor checks migration inputs and returns write receipts that the parent uses to decide whether restoration is safe. flowchart TD
A[Installed updater] --> B[Database capture]
B --> C[Candidate Doctor admission]
C --> D[Migration under maintenance custody]
D --> E[Database write receipt]
E --> F[Parent restoration decision]
E --> G[Forward update completion]
Technical reviewBest possible solution: Keep the focused first-admission repair in the existing capture owner, correct the legacy fixture, and demonstrate successful forward completion through the managed updater. Do we have a high-confidence way to reproduce the issue? The source and real-SQLite regression establish the stale-admission path, and the body reports a matching 2026.11.4 managed-update failure; this read-only review executed no target code. Is this the best way to solve the issue? The production change is a small, owner-approved repair that preserves restoration refusal and reuses existing migration custody without adding another recovery mechanism. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4a0e45492b89. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +11, Tests +40. Total +51 across 2 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: No label 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 Reviewed November 16, 2026, 12:19 PM ET / 17:19 UTC. |
Narrow the stale-capture rebase: a first admission that disagrees with the parent capture is adopted only when every differing database shows a WAL index rebuilt over its retained frames (iChange zero, frame checksum kept). Any other pre-admission change, including foreign shared writes, still refuses at the first attributed write as before.
|
Merged via squash.
|
…'s database capture (openclaw#200172) * fix(update): let Doctor migrate when the parent capture is already stale A published updater (2026.11.3/11.4) can capture its database generations while concurrent readers such as `openclaw update status` keep the WAL index alive past its last ledger commit. When those readers exit, the next native open rebuilds the index (iChange resets, same frames), so the committed fingerprint changes without any write. The target Doctor then refused its first attributed write ("SQLite migration source changed after update capture"), the parent's rollback was refused by the same comparison, and the parent's forward recovery migrated with the target Doctor and stranded the Gateway stopped with "cannot open your existing data". When the first admission already disagrees with the parent's capture, the parent's restore is unavailable either way. Doctor now keeps reporting unchanged=false (the parent still refuses restore), warns, and attributes its own writes from the admitted observation, so the update completes forward. Writes after admission, including between Doctor phases, still refuse. * Merge remote-tracking branch 'origin/main' into codex/update-capture-stale-admission * fix(update): adopt only a no-write WAL index rebuild at Doctor admission Narrow the stale-capture rebase: a first admission that disagrees with the parent capture is adopted only when every differing database shows a WAL index rebuilt over its retained frames (iChange zero, frame checksum kept). Any other pre-admission change, including foreign shared writes, still refuses at the first attributed write as before. * docs(update): name the accepted rebuilt-index admission edge * Merge remote-tracking branch 'origin/main' into codex/update-capture-stale-admission Co-authored-by: Peter Steinberger <[email protected]>
Related: #197083
Related: #200022
What Problem This Solves
Fixes: a managed update from 2026.11.3 or 2026.11.4 can leave the Gateway stopped and report "data at risk" when an
openclaw update statuscall, or another reader, is running while the updater snapshots the databases.User Impact
User impact: such updates now finish on the new version instead of stopping the Gateway. Automatic database restoration is still unavailable for that update, and Doctor now says so in a warning.
Why This Change Was Made
Published updaters record database fingerprints that include SQLite's WAL-index change counter. If readers keep the WAL index alive past the updater's last ledger commit, the next native open after they exit rebuilds that index. The counter resets, even though no data changed. The target Doctor then refused its first attributed write with "SQLite migration source changed after update capture". The parent refused rollback because its own comparison failed the same way. The parent's forward recovery then migrated with the target Doctor, could not read the migrated data, and kept the Gateway stopped.
Doctor now recognizes that one shape at its first admission. A database that differs from the parent's capture is adopted only if its WAL index was rebuilt over retained frames: the WAL is non-empty, iChange is zero and the last frame checksum is non-zero. Any commit after the rebuild would raise iChange again. In that case Doctor:
unchanged: false, so the parent still refuses restore;Any other change before admission, such as a foreign shared write, still refuses at the first attributed write, as before. Writes after admission also still refuse.
Old updaters (11.3 and 11.4) take this target-side path, so this fixes 11.x → next-release hops. A 2026.11.4 target (#200022, 11.3 → 11.4) is not changed by this PR.
Safety and Scope
What is adopted. Only databases whose difference matches the rebuilt-index shape are adopted. A real write before admission reaches that shape only if it commits frames and then every connection leaves without a checkpoint, so that the next open rebuilds the index. In practice this needs the last writer to crash, or a read-only connection to close last. Even then no data is lost: every parent's restore gate re-compares the live generations to its capture and refuses, because a restore would discard that write. The pre-fix flow also migrated the same bytes forward, through the parent's forward recovery. The existing foreign-shared-write refusal (
client-credential-update.test.ts) and the 2026.9.34 changed-data cases still refuse unchanged. Content identity cannot be compared directly: the fingerprint a published parent sends is sha256 over [dev, ino, birthtime, content digest, iChange, frame checksum], and the rebuild has already erased the old iChange.Main as the parent. Main's own generation reader is just as sensitive to rebuilds. In a local check, a capture taken while a reader holds the index, then a reader exit and a non-writing reopen, changed the committed generation both with and without a TRUNCATE checkpoint. With this PR, a main → future hop that loses that race completes forward, but automatic restore is unavailable for it. Making the fingerprint survive rebuilds is planned as a follow-up: compare against the generation with iChange normalized, since the frame checksum and content digest already record the writes. That follow-up changes how parents and targets interpret the same value across versions, so it is kept out of this fix.
What this does not fix. A later Doctor failure under an 11.3 or 11.4 parent still ends in "rollback refused → forward recovery → that parent's own settlement cannot open the migrated data → Gateway stopped". That code ships in the parent and hands off to the new driver only after Doctor succeeds, so the target cannot change it. On the installed new version,
openclaw update repairrecovers, as confirmed in #200022. A fix for the parent would need an 11.4.x patch release, which is a maintainer decision.Evidence
f6d0c3ea69a(1 GB state DB, twoopenclaw update statuspollers), monitored with auditd and a 100 ms watcher on the SQLite family. The run stranded:openclaw doctorfailed with "migration source changed", rollback was refused, settlement failed with "cannot open your existing data", and the Gateway was left inactive. At the end of capture the readers exited, and the 11.4 driver's next native open rebuilt the WAL index.-shmwent from iChange0x7dto0, while the frame checksum, WAL bytes and DB bytes were unchanged.migrates after a no-write WAL index rebuild while the parent's restore stays refused. It fails on base with the same error and passes with the fix.tsgo:coreandoxlintpass on the touched files.codex execreview of the narrowed diff found nothing.