Repository navigation
fix(update): a leftover snapshot copy fails the update even though the state read succeeded - #193702
Conversation
…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.
…snapshot-cleanup-best-effort
|
🦞👀 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 changesLet 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherUpdate 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +34, Tests +35, Other +2. Total +71 across 7 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. Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 5, 2026, 2:43 PM ET / 19:43 UTC. |
|
Merged via squash.
|
…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.
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.
…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.
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.
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]>
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: truecallers 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
withPreparedSqliteSnapshotthrows 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.withPreparedSqliteSnapshottakes a new optional{ bestEffortCleanup: true }; strict stays the default. With it, a failed removal is reported throughemitSnapshotCleanupFailureand 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.createVerifiedSqliteSnapshotpasses the same option throughsourceAcquisition.Only the update candidate worker's two reads opt in: the versions read (
withStateDatabaseSnapshot) and the candidate snapshot (createVerifiedSqliteSnapshot).requireCleanupandadoptPreparedLocationare 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 containsorigin/maincf80b26f093d. Red/green ran on basea19c5676afd4; after merging main (no changes on these paths), the two focused files were rerun: 36 passed.src/infra/update-candidate-state.cleanup.test.tsruns 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: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:SQLite snapshot cleanup failed: <dir>, on base and on this branch.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 runon the 125 test files that import the read-only location cleanup,sqlite-snapshotor the update candidate state: lint clean, and the only failures are 45 cases insrc/cli/update-cli/update-command-lease.test.ts,update-command-post-update-repair.test.ts,update-command-post-update-recovery.test.tsandsrc/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 examplerollback-state-unverified, and a macOS/private/vartemp-path alias).oxlintand format check on the changed files: clean.config/test-lines-allocations/update-candidate-snapshot-cleanup-best-effort.txt. The check passes (slack 3).origin/main, P0–P2): scoped-clean.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, whichafterEachremoves. 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'sfixtureandbusyErrorhelpers, restores itsrmspy withusing, and drains cleanup before checking the directory is gone.