Skip to content

fix(update): finish managed updates when readers race the old updater's database capture - #200172

Merged
steipete merged 5 commits into
mainfrom
codex/update-capture-stale-admission
Nov 16, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/update-capture-stale-admission

Conversation

@steipete

@steipete steipete commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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 status call, 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:

  • keeps reporting unchanged: false, so the parent still refuses restore;
  • warns that SQLite rebuilt the index and restoration is unavailable;
  • attributes its own writes from the admitted state, so the update finishes forward.

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 repair recovers, as confirmed in #200022. A fix for the parent would need an 11.4.x patch release, which is a maintainer decision.

Evidence

  • Crabbox AWS reproduction, 11.4 → main f6d0c3ea69a (1 GB state DB, two openclaw update status pollers), monitored with auditd and a 100 ms watcher on the SQLite family. The run stranded: openclaw doctor failed 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. -shm went from iChange 0x7d to 0, while the frame checksum, WAL bytes and DB bytes were unchanged.
  • New regression test 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.
  • Existing refusals are unchanged: the 2026.9.34 changed-data cases, the outside-commit tests, the after-admission predecessor-stop case and the client-credential foreign-shared-write test all still pass.
  • tsgo:core and oxlint pass on the touched files.
  • autoreview at P2: one finding, declined and named in a code comment. A commit after capture that only read-only connections outlive, followed by a rebuild, matches the adopted shape (see Safety and Scope). A re-review with that context came back scoped-clean. An independent codex exec review of the narrowed diff found nothing.

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

clawsweeper Bot commented Nov 16, 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 16, 2026 16:39
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 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-16T18:25:49.694052Z c6c709c New commits
ℹ️ 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-repro Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

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

  • Before: An index rebuild changes the fingerprint, Doctor refuses migration, and recovery can leave the Gateway stopped.
  • After: Doctor migrates from its first admitted observation and warns that automatic database restoration is unavailable.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused production repair has clear value, but an introduced regression fixture fails and upgrade preservation of existing SQLite data and settings has not been demonstrated.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A managed update can leave the Gateway stopped after harmless concurrent readers change SQLite fingerprint evidence.
Reason: The maintainer-authored direction resolves a concrete forward-completion failure while explicitly retaining the broader linked reports and old-parent recovery limitations.

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
Reviewed head: 022978cdbdaa59e774a82c3c5c2453e5fe13c325

Before merge

  • Preserve the legacy fixture's same-content commit evidence (P2) - Closing the last writer here can erase the WAL commit history that the same-content case deliberately retained. On the reviewed head, checks-node-changed-compact-large-9 fails this case at line 398 because the receipt reports unchanged=true instead of false. Rework the fixture so its intended changed-generation evidence survives admission without preventing migration; retain a meaningful assertion that an actually mismatching capture leaves restoration refused.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Preserve the legacy fixture's same-content commit evidence — src/infra/update-doctor-migration-attribution.test.ts:391-392

Tests

  • Missing end-to-end proof: Provide a redacted after-fix managed upgrade from 2026.11.4 with concurrent status readers, showing successful finalization, Gateway readiness, and the restoration-unavailable warning.
Agent review details

How this fits together

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

Technical review

Best 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:

  • [P2] Preserve the legacy fixture's same-content commit evidence — src/infra/update-doctor-migration-attribution.test.ts:391-392
    Closing the last writer here can erase the WAL commit history that the same-content case deliberately retained. On the reviewed head, checks-node-changed-compact-large-9 fails this case at line 398 because the receipt reports unchanged=true instead of false. Rework the fixture so its intended changed-generation evidence survives admission without preventing migration; retain a meaningful assertion that an actually mismatching capture leaves restoration refused.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4a0e45492b89.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/infra/update-doctor-migration-attribution.test.ts --maxWorkers=1
  • pnpm exec oxlint src/infra/update-doctor-migration-attribution.test.ts
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ad1b598 adds src/infra/update-doctor-result.ts:295 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ad1b59858731; files: src/infra/update-doctor-result.ts)

PR surface

Source +11, Tests +40. Total +51 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 11 0 +11
Tests 1 48 8 +40
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 59 8 +51

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:

No label changes.

Label justifications:

  • P1: The reported released-updater failure can strand a previously serving Gateway after activation.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 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.
@steipete
steipete merged commit 8697342 into main Nov 16, 2026
129 checks passed
@steipete
steipete deleted the codex/update-capture-stale-admission branch November 16, 2026 18:55
@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 17, 2026
…'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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant