Repository navigation
fix: updates remove their own backups once verified and delete old updater backups - #201711
Conversation
An update's Doctor backups now record the update run that took them, and a database rollback writes a receipt for the files it moves aside. Automatic cleanup decides from the run outcome instead of the live database inode, removes a verified update's own images and captures, deletes earlier updater-owned sets, keeps the newest unverified set and anything a pending recovery or unfinished run references, and reports what it freed and kept.
|
🦞👀 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: blocked before merge. What this changesThis PR links recovery backups to update outcomes, removes eligible updater-owned backups, and reports removed and retained files. Example: Update R1 rolls back and update R2 subsequently passes Gateway verification.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep open: this maintainer-authored PR addresses concrete cleanup gaps, but its retention change leaves affected consumer tests failing. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe updater and Doctor produce recovery artifacts; the existing state-owner cleanup operation classifies their ownership and update outcomes, deletes eligible artifacts, and returns diagnostics to CLI and Gateway completion. flowchart TD
A[Updater and Doctor] --> B[Backup manifests and rollback receipts]
C[Update run history] --> D[Recovery inventory]
B --> D
D --> E[State owner retirement]
E --> F[Cleanup diagnostics]
Technical reviewBest possible solution: Keep one owner-routed cleanup policy, update its affected consumer tests, and retain legacy files whose ownership cannot be proven. Do we have a high-confidence way to reproduce the issue? Current-main source preserves inode-based Doctor completion and has no displaced-database receipt lifecycle; the PR additionally reports owner-level red/green regressions, but no reproduction was executed during this read-only review. Is this the best way to solve the issue? Producer-linked ownership and outcome-based retirement address the cause through the existing cleanup owner; the added receipt lifecycle supplies the missing identity evidence without a parallel scheduler or user configuration. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7db69bedeab6. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +700, Tests +400, Docs +56, Other +5. Total +1161 across 32 files. Added test files: 1. 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:
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 19, 2026, 3:14 AM ET / 08:14 UTC. |
Receipt writes never block a database rollback and keep the database directory's mode. Non-restorable pre-migration images keep their existing retention. A changed newest set no longer releases older sets, the ledger keeps the cleanup report on every finished run, and a failed run's sealed capture is released by a later verified update.
…its-backups-after-verified-success
Proof recordings: owner tests, red on base, green on headTerminal recordings of the same command on both sides (local, macOS host). Idle gaps are capped at 1 s; nothing is re-typed. The command runs the 7 new cases:
unit-base-red.mp4
unit-head-green.mp4Installed-package Docker cells are pending; they will be added here. Full raw logs are not attached because the artifact store rejected uploads from this machine. |
Installed-package Docker cells (head
|
An older backup of a database is released only by a verified update after it or by an intact backup of the same database from a later run; a moved-aside family counts as intact only when every recorded member is present. Receipt reads count against the status scan budget, a cleanup rerun replaces the recorded report, sizes are reported as logical bytes and the suggested removal path is shell-quoted.
…its-backups-after-verified-success
…figured agent dirs A newer Doctor backup releases an older one only after its recorded content is re-verified, and moved-aside families never stand in for older backups. Released backups still require a present, unaliased live database. Receipts alone load run history, configured agent directories are scanned, a volume renumbered by a reboot keeps its receipt valid, and a settled rerun clears an earlier cleanup warning instead of restating it.
…its-backups-after-verified-success
…ort cleanup in text output Moved-aside families now need a present live database before removal, as Doctor backups do. Bounded status and read-only Doctor never hash a backup. The plain-text update report prints the cleanup summary, a warning-only attempt replaces the recorded summary, and the suggested removal path uses the CLI quoting helpers for the platform.
…its-backups-after-verified-success
…ive database for moved-aside copies
…its-backups-after-verified-success
Installed-package Docker cells on the final head (
|
…its-backups-after-verified-success
CI on
|
|
Landing with an attributed pre-existing CI failure (maintainer-approved). CI run 44556717551 (attempt 1) on head
This PR changes neither |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…dater backups (openclaw#201711) * fix(update): remove a verified update's backups and old updater backups An update's Doctor backups now record the update run that took them, and a database rollback writes a receipt for the files it moves aside. Automatic cleanup decides from the run outcome instead of the live database inode, removes a verified update's own images and captures, deletes earlier updater-owned sets, keeps the newest unverified set and anything a pending recovery or unfinished run references, and reports what it freed and kept. * fix(update): release already-current captures and rerun cleanup after verification * fix(update): keep rollbacks and unverified images safe while cleaning up Receipt writes never block a database rollback and keep the database directory's mode. Non-restorable pre-migration images keep their existing retention. A changed newest set no longer releases older sets, the ledger keeps the cleanup report on every finished run, and a failed run's sealed capture is released by a later verified update. * fix(update): release update backups per database, never per run An older backup of a database is released only by a verified update after it or by an intact backup of the same database from a later run; a moved-aside family counts as intact only when every recorded member is present. Receipt reads count against the status scan budget, a cleanup rerun replaces the recorded report, sizes are reported as logical bytes and the suggested removal path is shell-quoted. * fix(update): re-prove successors, keep live-database checks, scan configured agent dirs A newer Doctor backup releases an older one only after its recorded content is re-verified, and moved-aside families never stand in for older backups. Released backups still require a present, unaliased live database. Receipts alone load run history, configured agent directories are scanned, a volume renumbered by a reboot keeps its receipt valid, and a settled rerun clears an earlier cleanup warning instead of restating it. * fix(update): keep copies while their live database is missing and report cleanup in text output Moved-aside families now need a present live database before removal, as Doctor backups do. Bounded status and read-only Doctor never hash a backup. The plain-text update report prints the cleanup summary, a warning-only attempt replaces the recorded summary, and the suggested removal path uses the CLI quoting helpers for the platform. * fix(update): require full successor images, running-run tags, and a live database for moved-aside copies * test: record the test-line allocation for the round-four regressions * chore(pr): add the update run reader to the wrapper inventory
What Problem This Solves
Updates are supposed to remove their own backups once the new version is running, and to delete old backups from earlier updates. On a real Git install about 82 GiB of agent database backups stayed anyway: copies a rollback moved aside had no cleanup rule, Doctor backups could never be marked complete after the updater's own rollback replaced the database file, and an old Doctor backup without a manifest was protected forever. Every already-current update also kept another database-sized original-state capture. Nobody was told what was kept or why.
User Impact
After an update is verified successful (the new version serves and its health check passed), OpenClaw deletes the Doctor backups and rollback copies that update and earlier updates left, and an already-current update removes its own capture when it ends. The update result says what it removed, how much space it freed, and what it kept and why. Files it cannot prove it created are never deleted; each is listed as
Kept: not provably ourswith its size, and the message namesopenclaw triageso an agent can help decide.Why This Change Was Made
Owner-approved retention policy: remove a verified update's backups immediately and delete old updater backups; delete nothing the updater cannot prove it created. No config key, no database schema or protocol change.
updateRunId(from the Doctor child'sOPENCLAW_UPDATE_RUN_ID, recorded only while the ledger holds that run as running, so a stale inherited variable tags nothing), and a database rollback writes<db>.migrated-<runId>.receipt.json(device, inode, size, mtime of each moved file) before it moves anything. A receipt can name only its own family's files, must sit at the name its contents imply, and is re-read and compared before any unlink. A receipt that cannot be written never blocks the rollback; those files then stay protected.updateRunId, the run's outcome decides, not the live database's inode (the updater's own rollback and the startup swap replace that file, which is why the Nov 9 backups could never complete). Manifests without the field keep the old rules. An archive referenced by manifests naming different runs stays protected.cleanupCompletedUpdateRecovery, at its existing call points (CLI terminal path and Gateway boot outcome). A verified success releases its own backups and every backup of a run that finished before it started; its health verification covers the whole instance, so every database. Without one, backups are released per database, never per run: an older backup of database X goes only when a newer run left a full Doctor image of the same X (never a table-scoped.scoped.bak) whose recorded content (SHA-256) re-verifies, and only while no recovery is pending and no run is unfinished. A damaged or missing newer backup stands in for nothing; moved-aside.migrated-<runId>families never stand in for an older backup, because their receipt records no checksum. Backups taken by one Doctor run are kept or deleted together (the existing manifest dependency), which keeps more, never less. Finished failed runs also run this cleanup when no recovery is pending; when it removes nothing it adds no step. The run being finalized never releases its own backups unless it is itself verified, which guards against a clock that moved backward.update-run-artifact-ownership.ts, tested over generated combinations): after cleanup, every database that had at least one intact updater backup with no verified successful update after it still has at least one intact backup, and a database whose live file is missing keeps every intact backup.state/,agents/*/agent/and configured agent directories inside the state directory. A volume renumbered by a reboot (same inode, size and mtime, file on its directory's volume) keeps its receipt valid.<stateDir>.update-captures/<runId>: written by the update's initialization for direct CLI and Mac app runs, read only for manual recovery, removed today only by this cleanup). An already-current run's own capture is now removed when that run ends; it activated nothing, so the copy restores nothing. A failed or rolled-back run's capture is removed once a later verified successful update started after it finished. Captures of unfinished runs or with a pending recovery are kept. Whether an already-current run should take a capture at all is a separate copy-removal item; this PR does not change capture-taking..databases): unchanged. Restorable images are still retired at verified activation; images whose generations could not be sealed or whose restoration Doctor revoked stay, because a--no-restartsuccess is not proof the new Gateway was verified. Images skipped for space by fix(update): keep updating when a pre-migration database image does not fit #201579 leave nothing to remove.doctor-cron-*.bak, unmanifested or unreceipted files, a manifest naming a run with no record, anything a pending recovery or unfinished run references,.databasesdirectories of earlier runs, anything outside the updater's locations, and any name the updater does not write.recovery-artifact-cleanupstep's first diagnostic is a summary (removed N items (B logical bytes, X MiB); file lengths, since sparse or cloned files can release less disk), followed by up to 14 lines naming removed, kept, and not-provably-ours files (the rest viaopenclaw update cleanup --dry-run); the suggested--include-unmanifestedpath is quoted with the repo's CLI quoting helpers (PowerShell quoting on Windows). The plain-text update report prints the summary. Failed deletions and anything cleanup could not verify (blocked, unreadable history) are a warning on the update, never a failure; the next update retries. The run record keeps one fixed report, the summary and the warning: a rerun after late verification overwrites the summary and clears an earlier warning it no longer has, and a warning-only attempt replaces the summary with a line saying it did not finish.update-run-write.tschanges one condition so failed and rolled-back runs can record cleanup and a settled rerun can clear its warning.Update behavior for published updaters
The published updater runs first and cannot be patched. On the first hop from a published release, the candidate's Doctor already records
updateRunId, but a rollback driven by the published updater writes no receipt and its own cleanup uses the old rules. The first cleanup run by an updater or Gateway that carries this change (the next update, the Gateway boot outcome, oropenclaw update cleanup) applies the new rules. Older builds parse a manifest withupdateRunIdnormally (zod strips the unknown key) and keep their old rules; they ignore receipt files.Steps left to a person
None for files the updater can prove it created. Files it cannot prove (Doctor backups without a manifest, manifests from before
updateRunIdthat never completed,.migrated-*copies from before receipts, Doctor cron backups) are left for a person or agent to decide by design; the result namesopenclaw triageand, for an unmanifested backup, the manualopenclaw update cleanup --include-unmanifested <path>.Evidence
Unit, at the owner, with the real producers (
restoreUpdateDatabaseBackupwrites the receipt,recordDoctorMigrationBackupsthe manifest, cleanup runs through the real CLI terminal path or the real retirement owner):src/commands/update-backup-cleanup-policy.test.ts(new, 35 cases) and new cases insrc/commands/update-automatic-cleanup.test.ts.6445f7e13ff, tests fromaf1bb9f4718:7 failed. Recordings of red and green: fix: updates remove their own backups once verified and delete old updater backups #201711 (comment)8785b8e8dc7fail (4 failed): a table-scoped newer backup released the older full image; a Doctor backup was tagged with a finished run's id; the preview offered a moved-aside family as a candidate while its live database was missing; the stale-id negative control was attributed. GREEN on this head:35 passed..migrated-<R1>file plus receipts, and the summary's byte count equals their sizes.openclaw.sqlite.bak; an unmanifested*.pre-startup-migration-*.bak; adoctor-cron-*.bak; a.migrated-*file with no receipt; a Doctor backup run under an update id the ledger does not hold as running; a legacy manifest withoutupdateRunId; a forged receipt listing the user's.bak; an older full backup whose newer successor is table-scoped; an older backup whose newer successor no longer matches its recorded SHA-256; any backup while its live database is missing; a set referenced by a pending recovery; a set of an unfinished run; a displaced file that changed after the rollback (kept, warning). Failure path: an unlink that fails is a warning on a successful update, and the next verified update removes it.collectRecoveryDiskUsagecounts both backups as protected rather than hashing the newer one.update-command-migrate.test.ts,update-cli-failure-recovery.test-support.tsand the upgrade-survivor no-op checker (which still accepts the earlier one-sentence form);status.recovery.test.tsnow expects a failed run's capture to be superseded by a later verified update;doctor-sqlite-nocow.test.tsmocks the two new history fields; six redundant cases inupdate-command-capture-cleanup.test.tswere folded into the policy tests; a duplicated verification fixture inupdate-automatic-cleanup.test.tsbecame one helper.Checks on this head: focused Vitest across cleanup, inventory, retirement, restore, client-credential update, retention, migrate, status, CLI lifecycle, Gateway cleanup, upgrade-survivor no-op, update-restart-module-outcome and eager-import-closure suites, under umask 022: all pass.
pnpm tsgo:coreandpnpm tsgo:core:testpass; oxlint on touched files clean; session-identity ratchet OK; test lines +754 against the 400 allowance with a 354-line allocation inconfig/test-lines-allocations/201711-update-backup-cleanup-invariant.txt(needs maintainer approval: it is the generated-combination invariant test, its real-producer fixtures, and the regressions from the review rounds);git diff --checkclean.autoreviewdoes not run on this machine.Review and rating rounds (ClawSweeper):
2116991bbad, F/F/D): receipt writes could block a rollback; non-restorable images deleted on an unverified--no-restartsuccess; a changed newest set could release an older one; ledger dropped report lines; docs overstated legacy behavior. All fixed.05ee07d7ef3): supersession was per run, so a newer run intact for one database released another database's only backup. Fixed: per database, with the generated-combination test.418b966, F/C/F) and round 3 (ddcdb88, F/D/F): successors now need a re-verified SHA-256; a missing live database blocks deletion; receipt history; remounted volumes; configured agent directories; stale summary and warning in the run record; text output; Windows quoting. All fixed.8785b8e8dc7, F/F/F): (1) a table-scoped newer backup could release an older full image (class a); (2) a staleOPENCLAW_UPDATE_RUN_IDcould tag a standalone repair's backup with a finished verified run (classes a and b); (3) the preview listed a moved-aside family as a candidate while its live database was missing (class e); (4) an unreadable agent directory aborted the inventory (not on the blocking list; fixed because the fix is three lines). All four are fixed on this head with the red/green cases above.CI on the final head
c9c5415fc32: all checks pass exceptchecks-node-compact-small-8, whose only failures are fourtest/scripts/package-acceptance-workflow.test.tscases inherited from #201802 (it removed a release-workflow step the test still expects; this PR touches neither file). Attribution: #201711 (comment). The Docker cells ran on55065057da6; the only change since is a merge of main touching agent tools, dashboard, Gateway sessions, UI and the CI planner, none of the update, Doctor or cleanup paths.CI also showed that the receipt writer reset the database directory's mode to the umask default, which made the client-credential store refuse its directory during rollback; the writer now keeps the directory's own mode.
End to end on the final head (installed-package Docker cells, local OrbStack, update-matrix harness; candidate packed from
55065057da6,dist/build-info.jsoncommit55065057da62; excerpts: #201711 (comment)):openclaw update --yes --json(driven by the published 2026.11.5 CLI, finished by the candidate) to the candidate served as 2026.11.6:status: ok, runsucceeded. Itsrecovery-artifact-cleanupstep:Update backup cleanup removed 3 items (7855384 logical bytes, 7 MiB)., naming the agent and state Doctor backups (667,648 and 3,248,128 bytes) and the run's capture (3,939,608 bytes). So the Doctor child of a real update tags its backups through the running-run check. A second plainopenclaw updatereportedskipped: already-currentand removed its own new capture (5,582,805 bytes).~/.openclaw.update-capturesholds only its 4 KiB privacy marker after both updates. Backup leftovers under the state dir and install prefix after either update: onlyopenclaw.json.pre-update(4 KiB, config rollback file, out of scope). State dir 6,483,968 bytes before, 8,581,120 after the update (migrated databases), 8,667,136 after the repeat.release/2026.11.6without this change left a 529 MiB agent.bak, a 3 MiB state.bakand 533 MiB of captures after a successful update, and a following already-current update grew the captures to 1065 MiB.doctor-failed, runrolled-back, still serving 2026.11.5). The rollback wrote a receipt for each moved-aside family (agent, state, client credentials, services). A repeat failed the same way. Every family and capture of both runs is still there (two receipted families per database, two captures): with no verified update after them, nothing is released, and moved-aside families never stand in for each other. Cell A shows the release once a verified update runs; the owner-level tests prove the same for receipted families.Not proven
updateRunIdthat never completed,.migrated-*without a receipt, unmanifested Doctor backups) are not deleted automatically; they are listed with sizes for a person or agent to decide. On the Git install that motivated this, that is most of the 82 GiB..databasesimages that were not automatically restorable, and those of earlier runs, are not removed.createdAtMs; a clock that steps backward can still misorder earlier runs (the run being finalized is guarded).fix/gateway-boot-migrates-in-place) are not covered: that branch has not merged. A Doctor run by the boot chain gets noupdateRunId, so its backups follow the old rules.readdir; a permission-based test is unreliable under root in CI).Follow-ups (not blocking under the agreed landing bar)
state/,agents/*/agent/and configured agent directories keep their.migrated-*families.config/test-lines-allocations/201711-update-backup-cleanup-invariant.txt, 354 lines) needs maintainer approval.