Skip to content

fix(update): a leftover snapshot copy fails the update even though the state read succeeded - #193702

Merged
fuller-stack-dev merged 2 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-candidate-snapshot-cleanup-best-effort
Nov 5, 2026
Merged

fuller-stack-dev merged 2 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-candidate-snapshot-cleanup-best-effort

Conversation

@fuller-stack-dev

Copy link
Copy Markdown
Member

Related: #193652, #193174

What Problem This Solves

Fixes: an update stops at its candidate state check with "SQLite snapshot cleanup failed" even though the state was read successfully, because the check's private SQLite copy could not be deleted afterwards.

User Impact

A leftover private copy no longer fails an update. The candidate state check returns its result, logs that the copy could not be removed (with its path), and leaves the copy to the exit retry and the Gateway's snapshot sweep. A read that fails still fails the check, as before.

This narrows the strict snapshot-cleanup contract for these update reads only. Every other caller keeps it, including the requireCleanup: true callers that copy sensitive databases (auth bootstrap, Gateway lock recovery, agent lease inspection and the others). For those, a leftover private copy should stay a loud failure.

Why This Change Was Made

withPreparedSqliteSnapshot throws when it cannot remove the private copy, even after the read succeeded. That is right for callers whose copy holds sensitive data, but in the update candidate worker it turns a disk leak into a failed update. The worker exits 1, and the update stops over a few leftover gigabytes the Gateway can reclaim later.

withPreparedSqliteSnapshot takes a new optional { bestEffortCleanup: true }; strict stays the default. With it, a failed removal is reported through emitSnapshotCleanupFailure and the read's result or error is returned unchanged. When the snapshot owner has already reported the failure, it isn't logged a second time. createVerifiedSqliteSnapshot passes the same option through sourceAcquisition.

Only the update candidate worker's two reads opt in: the versions read (withStateDatabaseSnapshot) and the candidate snapshot (createVerifiedSqliteSnapshot). requireCleanup and adoptPreparedLocation are unchanged. A copy left behind is reclaimed by the existing Gateway sweep; #193652 extends that sweep to the shared-cache layouts update runs and older releases leave.

Evidence

Head ccb064aea222, which contains origin/main cf80b26f093d. Red/green ran on base a19c5676afd4; after merging main (no changes on these paths), the two focused files were rerun: 36 passed.

src/infra/update-candidate-state.cleanup.test.ts runs the real update candidate worker in a subprocess. A preload fails the snapshot directory's removal: once for "transient", always for "persistent". The worker's file log is pointed at the fixture through a private config file. Three cases are rewritten to the new contract:

  • "versions: transient cleanup with readError=false" now expects exit 0 with the shared database's version in the output, the copy removed by the exit retry, and the failure logged with the copy's path.
  • "snapshot: persistent cleanup with readError=false" now expects exit 0 with the snapshot result, one copy left for the sweep, and the failure logged.
  • "versions: persistent cleanup with readError=true" still expects exit 1 with the read error, now without the cleanup failure mixed into it. The copy is left and the failure is logged.

On base all three fail (exit 1, "snapshot cleanup failed"). On this branch they pass. The unchanged "snapshot: healthy cleanup with readError=true" passes on both and logs nothing.

Negative control in src/infra/sqlite-readonly-location.cleanup.test.ts: "keeps the read result only for best-effort callers when removal fails". It uses a real prepared location whose removal keeps failing:

  • default (strict) caller: rejects with SQLite snapshot cleanup failed: <dir>, on base and on this branch.
  • best-effort caller: base fails (it rejects); this branch returns the read result.
  • in both cases the owner reports the failure once, and the copy stays until the later cleanup removes it.

Commands:

  • vitest run src/infra/update-candidate-state.cleanup.test.ts: 17 passed. vitest run src/infra/sqlite-readonly-location.cleanup.test.ts: 19 passed.
  • vitest run on the 125 test files that import the read-only location cleanup, sqlite-snapshot or the update candidate state: lint clean, and the only failures are 45 cases in src/cli/update-cli/update-command-lease.test.ts, update-command-post-update-repair.test.ts, update-command-post-update-recovery.test.ts and src/state/openclaw-state-db-readonly.test.ts. Rerunning those four files with this PR's source reverted to base gives the identical 45 failures (for example rollback-state-unverified, and a macOS /private/var temp-path alias).
  • oxlint and format check on the changed files: clean.
  • Test-lines ratchet: net growth +35, recorded exactly in config/test-lines-allocations/update-candidate-snapshot-cleanup-best-effort.txt. The check passes (slack 3).
  • Autoreview (Codex, branch mode against origin/main, P0–P2): scoped-clean.
  • Not run locally: the tsgo typecheck, which refuses this checkout's shared pnpm store. CI's typecheck is the gate for that.

Test file audit:

  • src/infra/update-candidate-state.cleanup.test.ts, read in full: only the scenario table's final assertions and the worker environment changed. The fixture's config and log live in the fixture directory, which afterEach removes. The other cases are unchanged, and nothing was pruned.
  • src/infra/sqlite-readonly-location.cleanup.test.ts, read in full: the new case reuses the file's fixture and busyError helpers, restores its rm spy with using, and drains cleanup before checking the directory is gone.

…ate check

The update candidate worker exited 1 with "snapshot cleanup failed"
after a successful read when its private SQLite copy could not be
removed. Let those two update reads opt out of strict cleanup: the
failure is logged, the read result is returned, and the copy is left
for the exit retry and the Gateway sweep. Every other caller keeps
strict cleanup.
@clawsweeper

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

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Let update candidate reads log temporary SQLite cleanup failures while preserving their read result or original error.

Example: A versions worker reads database user_version 3, then temporary-copy removal fails with EACCES.

  • Before: The worker exits 1 with SQLite snapshot cleanup failed.
  • After: The worker returns version 3, logs the cleanup failure, and retains the existing cleanup retry.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, correct patch with meaningful production-worker regression coverage; supplied execution evidence remains below the complete shipped update flow.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied base/head results exercise the real candidate worker subprocess with injected removal failures, rather than a full CLI update.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An update candidate check fails after reading state successfully because its disposable SQLite copy cannot be removed.
Reason: The maintainer-authored direction accepts logged cleanup residue for update reads while retaining existing cleanup custody and strict behavior elsewhere.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still rejects successful update-worker reads when temporary-copy cleanup fails, and this focused change introduces no actionable correctness or security finding.

Priority: P2
Reviewed head: ccb064aea222e947f57aca7bfd83a7b98108fe76

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not exercise the complete shipped update CLI with injected cleanup failure.
Agent review details

How this fits together

Update workers inspect private SQLite copies and publish schema versions or verified rehearsal snapshots; the shared snapshot owner manages their cleanup.

flowchart TD
  A[Update coordinator] --> B[Candidate state worker]
  B --> C[Acquire private SQLite copy]
  C --> D[Read versions or publish verified snapshot]
  D --> E[Existing cleanup owner]
  E --> F[Return result and log removal failure]
  E --> G[Exit cleanup retry]
Loading

Technical review

Best possible solution:

Keep cleanup policy in the existing snapshot owner, with update-only best effort, preserved read errors, and strict behavior for other consumers.

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

Current-main source shows successful reads becoming failures on refused cleanup, and the supplied base/head worker results cover that trigger; this review ran no reproduction.

Is this the best way to solve the issue?

The opt-in is the smallest complete policy change using existing owners, and the maintainer-authored rationale explains why update reads now differ from strict consumers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0ab5fde497bb.

Provenance checked

  • Fatal cleanup after successful update inspection changes intended behavior with a stated reason (fix(update): report temporary state snapshot cleanup failures #143844: Make retained raw copies visible as inspection failures; the shared helper later carried that contract in fix(update): shorten database rehearsal preparation #157115.)
  • Prepared-image custody and verified publication keeps the original intent (6c672d4: Reuse the admitted private generation without another acquisition while preserving identity, integrity, and cleanup ownership.)
  • Owner-issued cleanup diagnostics and retries keeps the original intent (9746e39: Warn from the cleanup owner without replacing successful best-effort results, and retain directories for later cleanup.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +34, Tests +35, Other +2. Total +71 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 44 10 +34
Tests 2 42 7 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 7 88 17 +71

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.

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +44/-10; tests +42/-7 Growth adds a narrow policy to existing owners and distinct worker-result and strict-default coverage without another cleanup subsystem.

Labels

Label changes:

  • add P2: The patch prevents a conditional update-worker failure after successful inspection, with no demonstrated widespread outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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:

  • P2: The patch prevents a conditional update-worker failure after successful inspection, with no demonstrated widespread outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add redacted CLI update output showing candidate inspection continuing after an injected temporary-copy removal failure.

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 5, 2026, 2:43 PM ET / 19:43 UTC.

@fuller-stack-dev
fuller-stack-dev merged commit 38cfa9e into openclaw:main Nov 5, 2026
147 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/update-candidate-snapshot-cleanup-best-effort branch November 5, 2026 21:13
steipete added a commit that referenced this pull request Nov 5, 2026
The hourly Windows cleanup cases write JSON log records, which escape backslashes. Match the exact encoded path while retaining the deletion, retry, and source-preservation assertions. First exposed by 38cfa9e (#193702). No runtime behavior changes.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
…ate check (openclaw#193702)

The update candidate worker exited 1 with "snapshot cleanup failed"
after a successful read when its private SQLite copy could not be
removed. Let those two update reads opt out of strict cleanup: the
failure is logged, the read result is returned, and the copy is left
for the exit retry and the Gateway sweep. Every other caller keeps
strict cleanup.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 6, 2026
The hourly Windows cleanup cases write JSON log records, which escape backslashes. Match the exact encoded path while retaining the deletion, retry, and source-preservation assertions. First exposed by 68466d5 (openclaw#193702). No runtime behavior changes.
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 6, 2026
…ate check (openclaw#193702)

The update candidate worker exited 1 with "snapshot cleanup failed"
after a successful read when its private SQLite copy could not be
removed. Let those two update reads opt out of strict cleanup: the
failure is logged, the read result is returned, and the copy is left
for the exit retry and the Gateway sweep. Every other caller keeps
strict cleanup.
wangmiao0668000666 pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 6, 2026
The hourly Windows cleanup cases write JSON log records, which escape backslashes. Match the exact encoded path while retaining the deletion, retry, and source-preservation assertions. First exposed by 38cfa9e (openclaw#193702). No runtime behavior changes.
RomneyDa added a commit that referenced this pull request Nov 16, 2026
Required minimal dependency of P1 NFS fix #195409. Preserve beta.4's
SqliteSnapshotCleanupError import while adding withPreparedSqliteSnapshot.
Focused cleanup regression: 2 passed; targeted lint/format and diff check passed.

(cherry picked from commit 38cfa9e)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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