Skip to content

fix(update): agent databases falsely flagged as changed during snapshot capture - #170351

Merged
RomneyDa merged 6 commits into
openclaw:mainfrom
DonnieFi:fix/170335-snapshot-availability
Oct 13, 2026
Merged

RomneyDa merged 6 commits into
openclaw:mainfrom
DonnieFi:fix/170335-snapshot-availability

Conversation

@DonnieFi

@DonnieFi DonnieFi commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #170335 (closed by #170523)

What Problem This Solves

Fixes: during openclaw update with the Gateway already stopped, the database snapshot step reported agent databases as "Database changed during capture" and disabled automatic database restoration, even though nothing had written to them. The snapshot step's own read caused it.

User Impact

User impact: updates keep automatic database rollback for agent databases left with WAL sidecars by their last writer. Since #170523, unrestorable snapshots are retained after success, so these false alarms also left a snapshot directory behind on every update; that stops too. Real changes during capture are still detected and reported, and capture without confirmed Gateway custody is unchanged.

Why This Change Was Made

Opening a WAL database natively with no other holder makes SQLite rebuild its WAL index, which resets the -shm change counter that is part of the recorded write generation. The snapshot step opened live agent databases natively, so its "after" generation never matched its "before". With maintenance custody confirmed, capture now copies each database family privately (the existing preserveSourceArtifacts path) and never opens the source. The state database was not flagged in #170335 because it had been closed cleanly and took the raw-copy path.

Update behavior: the installed updater runs the snapshot, so this takes effect for updates driven from a release containing it.

History: this PR originally reworded the snapshot-lifetime messages (DonnieFi's commits, kept in the branch). #170523 merged a different retention policy and owns that wording now, so the merge from main takes main's text, tests, and docs; the remaining diff is only the capture fix. Credit to DonnieFi for the report analysis and the original PR.

Evidence

Installed-updater proof (Docker, synthetic state)

These runs use the packed branch head 2c5441bc576 installed with npm install -g as the driver. Each one sets up Doctor, a managed Gateway (systemd shim) and a durable session, then updates to the same build relabeled 2026.10.6. A synthetic SQLite writer stays active on the shared database until original capture.

The "unfixed" control is the same tarball with only the preserveSourceArtifacts line removed from the compiled capture module, which matches main.

Driver Candidate Capture warning Outcome
unfixed succeeds Database changed during capture … openclaw-agent.sqlite Update completes. Restoration is disabled at capture.
this PR succeeds none (database snapshot warnings: []) Update completes. Later: Automatic database restoration unavailable: databases changed after snapshot capture; the writer is unknown
unfixed real Doctor writes agent state, then fails Database changed during capture … Package rolls back to the driver. Databases are not restored: the candidate's row remains.
this PR real Doctor writes agent state, then fails none database rollback refuses: Databases changed after snapshot capture: …/openclaw-agent.sqlite. The candidate stays installed and the Gateway serves the preserved state.

In every run, the session written before the update is still present afterward, /readyz returns 200, and openclaw.json is byte-identical.

Result: the capture-time false warning is fixed. Automatic restoration is still not eligible in the installed-updater flow, so this PR does not yet restore the rollback contract.

A timestamped watcher on the agent database's WAL and -shm header shows the cause:

  • The Gateway's clean stop leaves an empty WAL with -shm iChange=4. The snapshot leaves it unchanged, which is the fix working.
  • About 25 s later, the candidate Doctor's database preflight (state/openclaw-agent-schema-inspection.worker.js → withSqliteSourceReadDatabase) natively opens the source with no holder. The WAL index rebuilds (iChange=0) before the Doctor write capture's admit() reads fromGenerations.
  • That Doctor run also writes the agent database (WAL grows, iChange=1). By design, createUpdateDoctorDatabaseWriteCapture treats any change during Doctor as unattributed (unchanged=false).

Remaining work needs the rollback owner's direction:

  • Doctor's pre-admit preflight should use artifact-preserving reads when update generations are supplied, or the capture should admit before preflight.
  • Decide how Doctor-time writes may keep restoration eligible.

Published driver → candidate

scripts/e2e/published-driver-update-docker.sh ran with published [email protected] as the driver and this branch as the candidate:

  • PASS: phase finished, readyz 200, running version and build verified.
  • Durable session content was preserved across the update. Incognito content was correctly dropped.
  • No capture or restoration warnings appeared in the update output.

Verified activation deletes the pre-migration snapshot directory. The
snapshot step still recorded that those copies remain available, and the
success report reprints that warning after cleanup.

Refs: openclaw#170335
@clawsweeper

clawsweeper Bot commented Oct 12, 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.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: XS labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR uses private database-family copies during snapshot capture under confirmed maintenance custody.

Example: An update captures agents/main/agent/openclaw-agent.sqlite with WAL sidecars left by an exited writer.

  • Before: Opening the source rebuilds its WAL index, producing a false changed-during-capture warning and disabling restoration at capture.
  • After: Private acquisition preserves the source generation and removes the false capture warning; later database changes can still prevent restoration.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct capture repair with installed-CLI evidence; the service environment is fixture-backed, and broader Doctor restoration remains unchanged.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The installed CLI at the reviewed head runs updates in Docker with synthetic durable state and a systemd fixture; recorded output shows the capture warning removed relative to an unfixed control, while subsequent Doctor changes still cause guarded refusal. The published 2026.10.2-to-candidate run additionally reports preserved durable session content and configuration. Successful full rollback is outside this capture-only change and is not claimed by the new evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An update can falsely report unchanged agent databases as changed and disable automatic restoration during capture.
Reason: The narrow repair removes capture's own source mutation through an existing acquisition owner, with maintainer adoption and preserved recovery safeguards.

Merge readiness

✅ Ready for maintainer review

This PR owns a useful capture fix that current main lacks; no introduced defect was found, and the supplied installed-updater evidence demonstrates the changed behavior.

Priority: P2
Reviewed head: 2c5441bc5765a1daac89e7e258f464264db5728c

Before merge

None.

Findings

None.

Agent review details

How this fits together

The installed updater captures shared and agent SQLite databases before candidate activation, producing verified snapshots and generation records consumed by guarded rollback.

flowchart TD
A[Installed updater] --> B[Maintenance custody]
B --> C[Private database acquisition]
C --> D[Verified snapshots and generations]
D --> E[Candidate Doctor]
E --> F[Guarded database rollback]
D --> G[Update report]
Loading

Technical review

Best possible solution:

Land the focused private-acquisition repair while preserving existing rollback refusals for later database changes.

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

Source establishes the native-open and generation-comparison failure path, supported by the reported base-failing regression and installed unfixed control; this review ran no target code.

Is this the best way to solve the issue?

Reusing artifact-preserving acquisition fixes capture's own source mutation without weakening generation checks; Doctor pre-admission changes are a separate existing limitation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9ffb5595942b.

Provenance checked

  • Snapshot acquisition changes intended behavior with a stated reason (979a8be: Online acquisition supports consistent snapshots while a Gateway writes; artifact-preserving acquisition remains a separate existing contract.)
  • Database generation safeguards keeps the original intent (0ac1c24: Generation fingerprints tolerate checkpoint-only transitions while retaining committed-content, identity, and WAL write evidence.)
  • Recovery documentation keeps the original intent (8f364a7: Recovery requires settled writers and verified maintenance ownership; an installed older updater cannot gain ordering changes from its candidate.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced production change enables the existing artifact-preserving acquisition option only when maintenance custody is available; generation and restoration checks remain unchanged. (src/cli/update-cli/update-command-database-backup.ts:112, 2c5441bc5765)
  • Current main still needs the fix: Current main's capture call supplies postgresOffline but does not supply preserveSourceArtifacts, leaving SQLite acquisition susceptible to the reported source-open effect. (src/cli/update-cli/update-command-database-backup.ts:105, 9ffb5595942b)
  • Existing snapshot owner and format: Artifact-preserving acquisition prepares a private family, then uses the existing integrity verification, row-preserving snapshot publication, permissions, and consolidated snapshot format. (src/infra/sqlite-snapshot.ts:607, 2c5441bc5765)
  • Installed-updater behavior evidence: The full PR body reports Docker runs using installed head 2c5441b: the unfixed control emits the agent capture warning, while the patched driver records database snapshot warnings as []. Both successful and Doctor-failure runs preserve the durable session and exact config bytes, with readyz returning 200. (2c5441bc5765)
  • Later refusal is existing behavior: Doctor write capture intentionally classifies changed generations during its interval as unattributed; the rollback documentation explicitly preserves Doctor-time changes instead of restoring over them. (src/infra/update-doctor-result.ts:257, 2c5441bc5765)
  • Independent regression assertions: The exited-writer scenario uses real capture and restore owners, asserts no capture warnings and a recorded generation, and inherits checks that original rows and schemas are restored; service verification and Doctor behavior are fixture-backed. (src/cli/update-cli/update-command-database-rollback.test.ts:722, 2c5441bc5765)

Likely related people:

  • Peter Steinberger: Raw commit 9863e3f adds src/cli/update-cli/update-command-database-backup.ts:85 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9863e3f97ab4; files: src/cli/update-cli/update-command-database-backup.ts)

PR surface

Source +7, Tests +36, Docs +3. Total +46 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 8 1 +7
Tests 2 36 0 +36
Docs 1 4 1 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 48 2 +46

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: False capture warnings unnecessarily disable database restoration, with no demonstrated loss of live data or unavailable core runtime.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (8 earlier review cycles)
  • reviewed 2026-10-12T22:51:27.504Z sha 4257503 :: needs real behavior proof before merge. :: [P2] Scope the removal promise to package cleanup
  • reviewed 2026-10-12T23:12:36.943Z sha 06488ad :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T00:33:22.389Z sha 19f15e8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T01:44:05.012Z sha 19f15e8 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T02:03:28.144Z sha 64c5b9b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T02:14:01.196Z sha 64c5b9b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T04:35:53.848Z sha 64c5b9b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T05:02:08.621Z sha 2c5441b :: needs real behavior proof before merge. :: none

Reviewed October 13, 2026, 6:03 PM ET / 22:03 UTC (Revision 9).

Package activation retires snapshots only when cleanup finishes. Git
snapshots stay under .artifacts, and a recoverable package cleanup
warning can leave them in place. One removal sentence covered none of
those cases.

Refs: openclaw#170335
@DonnieFi DonnieFi changed the title fix(update): stop promising retained database snapshots after success fix(update): scope snapshot lifetime to package cleanup or git retention Oct 12, 2026
Package and git updater runs now keep the lifetime sentences on the report
and check the snapshot directory when activation does not succeed. Git
runtime cleanup still leaves the .artifacts copy in place.

Refs: openclaw#170335
@DonnieFi

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

A native open of a WAL family left by an exited writer rebuilds its WAL
index and resets iChange, so the snapshot step's own read changed the
recorded generation and disabled automatic restoration (openclaw#170335).

Capture under confirmed maintenance custody now preserves source artifacts;
unconfirmed custody keeps the online backup path. Reword the per-database
capture warning so it no longer reads as an action item after success.
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 13, 2026
@RomneyDa
RomneyDa marked this pull request as ready for review October 13, 2026 04:28
openclaw#170523 now keeps unrestorable snapshots after verified activation and owns
their wording, so take main's text, tests, and docs for that policy. This
branch keeps only the capture fix: copy database families privately under
maintenance custody so the snapshot step's own read cannot change the
recorded generation.
@RomneyDa RomneyDa changed the title fix(update): scope snapshot lifetime to package cleanup or git retention fix(update): agent databases falsely flagged as changed during snapshot capture Oct 13, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Oct 13, 2026
@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 13, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 13, 2026
@RomneyDa
RomneyDa merged commit 648fb53 into openclaw:main Oct 13, 2026
149 of 151 checks passed
RomneyDa added a commit that referenced this pull request Oct 14, 2026
…ot capture (#170351)

* fix(update): stop promising retained database snapshots after success

Verified activation deletes the pre-migration snapshot directory. The
snapshot step still recorded that those copies remain available, and the
success report reprints that warning after cleanup.

Refs: #170335

* fix(update): scope snapshot lifetime to package cleanup or git retention

Package activation retires snapshots only when cleanup finishes. Git
snapshots stay under .artifacts, and a recoverable package cleanup
warning can leave them in place. One removal sentence covered none of
those cases.

Refs: #170335

* test(update): record snapshot lifetime on the update report

Package and git updater runs now keep the lifetime sentences on the report
and check the snapshot directory when activation does not succeed. Git
runtime cleanup still leaves the .artifacts copy in place.

Refs: #170335

* fix(update): copy database families privately under maintenance custody

A native open of a WAL family left by an exited writer rebuilds its WAL
index and resets iChange, so the snapshot step's own read changed the
recorded generation and disabled automatic restoration (#170335).

Capture under confirmed maintenance custody now preserves source artifacts;
unconfirmed custody keeps the online backup path. Reword the per-database
capture warning so it no longer reads as an action item after success.

---------

Co-authored-by: Dallin Romney <[email protected]>
(cherry picked from commit 648fb53)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…ot capture (openclaw#170351)

* fix(update): stop promising retained database snapshots after success

Verified activation deletes the pre-migration snapshot directory. The
snapshot step still recorded that those copies remain available, and the
success report reprints that warning after cleanup.

Refs: openclaw#170335

* fix(update): scope snapshot lifetime to package cleanup or git retention

Package activation retires snapshots only when cleanup finishes. Git
snapshots stay under .artifacts, and a recoverable package cleanup
warning can leave them in place. One removal sentence covered none of
those cases.

Refs: openclaw#170335

* test(update): record snapshot lifetime on the update report

Package and git updater runs now keep the lifetime sentences on the report
and check the snapshot directory when activation does not succeed. Git
runtime cleanup still leaves the .artifacts copy in place.

Refs: openclaw#170335

* fix(update): copy database families privately under maintenance custody

A native open of a WAL family left by an exited writer rebuilds its WAL
index and resets iChange, so the snapshot step's own read changed the
recorded generation and disabled automatic restoration (openclaw#170335).

Capture under confirmed maintenance custody now preserves source artifacts;
unconfirmed custody keeps the online backup path. Reword the per-database
capture warning so it no longer reads as an action item after success.

---------

Co-authored-by: Dallin Romney <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Oct 16, 2026
…ot capture (openclaw#170351)

* fix(update): stop promising retained database snapshots after success

Verified activation deletes the pre-migration snapshot directory. The
snapshot step still recorded that those copies remain available, and the
success report reprints that warning after cleanup.

Refs: openclaw#170335

* fix(update): scope snapshot lifetime to package cleanup or git retention

Package activation retires snapshots only when cleanup finishes. Git
snapshots stay under .artifacts, and a recoverable package cleanup
warning can leave them in place. One removal sentence covered none of
those cases.

Refs: openclaw#170335

* test(update): record snapshot lifetime on the update report

Package and git updater runs now keep the lifetime sentences on the report
and check the snapshot directory when activation does not succeed. Git
runtime cleanup still leaves the .artifacts copy in place.

Refs: openclaw#170335

* fix(update): copy database families privately under maintenance custody

A native open of a WAL family left by an exited writer rebuilds its WAL
index and resets iChange, so the snapshot step's own read changed the
recorded generation and disabled automatic restoration (openclaw#170335).

Capture under confirmed maintenance custody now preserves source artifacts;
unconfirmed custody keeps the online backup path. Reword the per-database
capture warning so it no longer reads as an action item after success.

---------

Co-authored-by: Dallin Romney <[email protected]>
(cherry picked from commit 648fb53)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

2 participants