Skip to content

fix: updates remove their own backups once verified and delete old updater backups - #201711

Merged
fuller-stack-dev merged 15 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-cleans-up-its-backups-after-verified-success
Nov 19, 2026
Merged

fuller-stack-dev merged 15 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-cleans-up-its-backups-after-verified-success

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

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 ours with its size, and the message names openclaw triage so 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.

  • Ownership proof. A file is deleted only when its name and location are ones the updater writes, a record links it to an update run, and the file still matches that record. Two record gaps are closed with additive metadata: the Doctor migration-backup manifest gains updateRunId (from the Doctor child's OPENCLAW_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.
  • Completion from the run outcome. For manifests with 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.
  • When. Through the existing owner, 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.
  • Live database required. No Doctor backup or moved-aside family is deleted, or offered for deletion in a preview, while the live database it belongs to is missing or aliased. An unreadable agent directory is skipped; the rest of the inventory still runs.
  • Bounded paths. Status and read-only Doctor never hash a backup and count receipt reads against their metadata budget; eligibility that needs a content check stays unverified there and is decided when cleanup runs.
  • Invariant (stated in 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.
  • Discovery. Receipts are found in 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.
  • Original-state captures (<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.
  • Cleanup after late verification. A cleanup recorded before the run's health verification is no longer final: the next cleanup point (Gateway boot outcome, next update) runs it again and releases that run's own backups. Older records without a completion time are treated the same way.
  • Pre-migration images (.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-restart success 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.
  • Never deleted: doctor-cron-*.bak, unmanifested or unreceipted files, a manifest naming a run with no record, anything a pending recovery or unfinished run references, .databases directories of earlier runs, anything outside the updater's locations, and any name the updater does not write.
  • Reporting. The recovery-artifact-cleanup step'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 via openclaw update cleanup --dry-run); the suggested --include-unmanifested path 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.ts changes 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, or openclaw update cleanup) applies the new rules. Older builds parse a manifest with updateRunId normally (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 updateRunId that never completed, .migrated-* copies from before receipts, Doctor cron backups) are left for a person or agent to decide by design; the result names openclaw triage and, for an unmanifested backup, the manual openclaw update cleanup --include-unmanifested <path>.

Evidence

Unit, at the owner, with the real producers (restoreUpdateDatabaseBackup writes the receipt, recordDoctorMigrationBackups the 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 in src/commands/update-automatic-cleanup.test.ts.
  • Invariant over generated combinations (the main evidence that no path deletes the last intact copy): 2 or 3 runs, each verified, failed (optionally with a pending recovery) or unfinished, each leaving for each of two databases no copy, a Doctor backup or a moved-aside family, each then left intact, changed or deleted; every fourth case also removes the agent's live database. Asserted after real retirement: every database with an intact backup and no verified update from that run on keeps one, and a database with no live file keeps all of them. 20 seeds plus crafted cases, including a moved-aside family with its live database missing.
  • RED on base, first version: product code at 6445f7e13ff, tests from af1bb9f4718: 7 failed. Recordings of red and green: fix: updates remove their own backups once verified and delete old updater backups #201711 (comment)
  • RED for the final review round: the four new and changed cases run against the product code of 8785b8e8dc7 fail (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.
  • Odin-shaped regression: Doctor backup taken under update R1, R1's rollback replaces the live agent database (new inode, asserted), R1 finishes rolled back; a later verified update removes the R1 Doctor backup and every .migrated-<R1> file plus receipts, and the summary's byte count equals their sizes.
  • Negative controls, each asserted to survive: a user's openclaw.sqlite.bak; an unmanifested *.pre-startup-migration-*.bak; a doctor-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 without updateRunId; 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.
  • Bounded status: with the scan clock frozen, collectRecoveryDiskUsage counts both backups as protected rather than hashing the newer one.
  • Changed tests: cleanup-summary expectations in update-command-migrate.test.ts, update-cli-failure-recovery.test-support.ts and the upgrade-survivor no-op checker (which still accepts the earlier one-sentence form); status.recovery.test.ts now expects a failed run's capture to be superseded by a later verified update; doctor-sqlite-nocow.test.ts mocks the two new history fields; six redundant cases in update-command-capture-cleanup.test.ts were folded into the policy tests; a duplicated verification fixture in update-automatic-cleanup.test.ts became 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:core and pnpm tsgo:core:test pass; oxlint on touched files clean; session-identity ratchet OK; test lines +754 against the 400 allowance with a 354-line allocation in config/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 --check clean. autoreview does not run on this machine.

Review and rating rounds (ClawSweeper):

  • Round 1 (2116991bbad, F/F/D): receipt writes could block a rollback; non-restorable images deleted on an unverified --no-restart success; a changed newest set could release an older one; ledger dropped report lines; docs overstated legacy behavior. All fixed.
  • Land round (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.
  • Round 2 (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.
  • Round 4, the final round under the landing bar (8785b8e8dc7, F/F/F): (1) a table-scoped newer backup could release an older full image (class a); (2) a stale OPENCLAW_UPDATE_RUN_ID could 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 except checks-node-compact-small-8, whose only failures are four test/scripts/package-acceptance-workflow.test.ts cases 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 on 55065057da6; 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.json commit 55065057da62; excerpts: #201711 (comment)):

  • Cell A, verified update across a schema change, then an already-current update. Published 2026.11.5 installed with a managed Gateway service and synthetic state; 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, run succeeded. Its recovery-artifact-cleanup step: 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 plain openclaw update reported skipped: already-current and removed its own new capture (5,582,805 bytes).
    • Measured: ~/.openclaw.update-captures holds only its 4 KiB privacy marker after both updates. Backup leftovers under the state dir and install prefix after either update: only openclaw.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.
    • For comparison, a real Git update to release/2026.11.6 without this change left a 529 MiB agent .bak, a 3 MiB state .bak and 533 MiB of captures after a successful update, and a following already-current update grew the captures to 1065 MiB.
  • Cell B, activated failure with rollback under this head's updater, twice. This head installed; the candidate activates, its post-activation Doctor fails, and the updater rolls back (doctor-failed, run rolled-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

  • Existing leftovers from before this change (manifests without updateRunId that 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.
  • .databases images that were not automatically restorable, and those of earlier runs, are not removed.
  • Run order uses ledger createdAtMs; a clock that steps backward can still misorder earlier runs (the run being finalized is guarded).
  • The Gateway boot upgrade's pre-images (branch fix/gateway-boot-migrates-in-place) are not covered: that branch has not merged. A Doctor run by the boot chain gets no updateRunId, so its backups follow the old rules.
  • The unreadable-agent-directory skip has no dedicated test (the fix is a try/catch around one readdir; a permission-based test is unreliable under root in CI).
  • Cells ran on Linux only; the PowerShell quoting of the suggested path was not exercised on Windows.

Follow-ups (not blocking under the agreed landing bar)

  • Failed updates that roll back keep every moved-aside family until a verified update runs; repeated failures on a large instance can grow disk use (cell B: one family set and one capture per attempt). A bounded rule needs a checksum in the receipt, which is a format change outside this PR's approval.
  • Whether an already-current run should take an original-state capture at all (this PR only removes it when the run ends).
  • Plugin databases outside state/, agents/*/agent/ and configured agent directories keep their .migrated-* families.
  • The test-line allocation (config/test-lines-allocations/201711-update-backup-cleanup-invariant.txt, 354 lines) needs maintainer approval.

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

clawsweeper Bot commented Nov 19, 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 docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations size: XL labels Nov 19, 2026
@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: 🧂 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

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

  • Before: R1's Doctor backup can remain protected because rollback replaced the live database inode, while its migrated database has no cleanup receipt.
  • After: New ownership records let cleanup remove both backup families while preserving unrecorded legacy files.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful owner-approved repair, with affected-consumer test failures, incomplete CI attribution, and no completed cleanup or upgrade runtime proof.
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: Complete
User problem: Updater-owned database recovery copies accumulate after later healthy updates, consuming disk space without clear explanations.
Reason: The maintainer-authored direction explicitly approves retiring provably owned backups and preserving uncertain legacy files.

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
Reviewed head: 2116991bbad36799007a86bb51be5ae57e0bbbd3

Before merge

  • Update the existing capture-policy consumer tests (P2) - This branch makes an older failed capture eligible after a verified successor, but leaves the existing cleanup and status tests asserting the previous policy. Exact-head CI reports six removals instead of five in update-command-capture-cleanup.test.ts, obsolete classification reasons, and an unresolved-versus-warning mismatch in status.recovery.test.ts. Update those fixtures and expectations for the approved policy while preserving their pending-recovery and unfinished-run controls; the affected-consumer gate currently fails because of this change.
  • 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] Update the existing capture-policy consumer tests — src/commands/update-capture-cleanup.ts:102-106

Tests

  • Missing end-to-end proof: Provide redacted installed-package update output showing rollback-created backups retired after a verified successor, protected controls retained, and a latest-stable upgrade preserving settings and data.
Agent review details

How this fits together

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

Technical review

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

  • [P2] Update the existing capture-policy consumer tests — src/commands/update-capture-cleanup.ts:102-106
    This branch makes an older failed capture eligible after a verified successor, but leaves the existing cleanup and status tests asserting the previous policy. Exact-head CI reports six removals instead of five in update-command-capture-cleanup.test.ts, obsolete classification reasons, and an unresolved-versus-warning mismatch in status.recovery.test.ts. Update those fixtures and expectations for the approved policy while preserving their pending-recovery and unfinished-run controls; the affected-consumer gate currently fails because of this change.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7db69bedeab6.

Provenance checked

  • Automatic cleanup admission and owner routing keeps the original intent (fb9e117: Automatically retire eligible recovery copies after durable completion while preserving state ownership and advisory failure handling.)
  • Original-state capture retention changes intended behavior with a stated reason (30d1342: Release the verified update's own capture while keeping failed, rolled-back, unverified, and already-current captures under prior rules.)
  • Non-restorable database snapshot retention changes intended behavior with a stated reason (c1579cf: Keep unsealed snapshots after successful activation because warnings promised manual recovery availability; late Doctor refusals received the same protection in 1d59169.)
  • Doctor recovery destination verification changes intended behavior with a stated reason (78d2d91: Retire originals only with verified preservation evidence; later repairs retained identity checks while tolerating owned destination writes.)
  • Upgrade-survivor cleanup diagnostics keeps the original intent (1b4914c: Permit intentional automatic retirement while continuing to reject unrelated mutations during an already-current update.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/cli/update-cli/update-command-capture-cleanup.test.ts src/cli/update-cli/status.recovery.test.ts
  • pnpm tsgo:test:src
  • git diff --check

What I checked:

PR surface

Source +700, Tests +400, Docs +56, Other +5. Total +1161 across 32 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 21 764 64 +700
Tests 7 411 11 +400
Docs 2 64 8 +56
Config 0 0 0 0
Generated 0 0 0 0
Other 2 8 3 +5
Total 32 1247 86 +1161

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:

  • add P2: Accumulating recovery backups can consume substantial disk space, but this is a bounded updater cleanup repair.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Accumulating recovery backups can consume substantial disk space, but this is a bounded updater cleanup repair.
  • 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 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.
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Proof recordings: owner tests, red on base, green on head

Terminal 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: src/commands/update-backup-cleanup-policy.test.ts (5) and the two new cases in src/commands/update-automatic-cleanup.test.ts.

  • Base / red: product code at origin/main 6445f7e13ff, test files from af1bb9f4718. Result: 7 failed | 27 skipped (34), exit 1. The failures are the behaviors this PR adds: the Doctor manifest records no update run, a rolled-back update's Doctor backup and .migrated-<runId> files survive a later verified update, older failed sets are never released, an already-current run keeps its capture, and a verification recorded after cleanup never triggers it again.
unit-base-red.mp4
  • Head / green: af1bb9f4718 (merged with main as 05ee07d7ef3, no conflicts). Result: 7 passed | 27 skipped (34), exit 0.
unit-head-green.mp4

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

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Installed-package Docker cells (head 05ee07d7ef3)

Raw logs are not attached because the artifact store rejected uploads from this machine; decisive excerpts follow (home directory shown as ~).

Cell A: published 2026.11.5 -> candidate (schema change), verified; then an already-current repeat
update: status=ok 2026.11.5 -> 2026.11.6
  Update backup cleanup removed 3 items and freed 7 MiB, 7847192 bytes.
  Removed ~/.openclaw/agents/main/agent/openclaw-agent.sqlite.pre-startup-migration-968180a8-7819-8f57-8610-285162d045a0.bak (1 MiB, 667648 bytes).
  Removed ~/.openclaw/state/openclaw.sqlite.pre-startup-migration-968180a8-7819-8f57-8610-285162d045a0.bak (3 MiB, 3244032 bytes).
  Removed ~/.openclaw.update-captures/75636fab-5a15-4149-bae9-39871ef54f3f (4 MiB, 3935512 bytes).
repeat: status=skipped reason=already-current 2026.11.6 -> 2026.11.6
  Update backup cleanup removed 1 item and freed 5 MiB, 5578709 bytes.
  Removed ~/.openclaw.update-captures/13cd8849-78a0-4efa-9177-e0b927479cad (5 MiB, 5578709 bytes).
before: cli=OpenClaw 2026.11.5 (e13cf15) serving=2026.11.5 lastRun=none stateBytes=6483968 captures=[] leftovers=[]
after: cli=OpenClaw 2026.11.6 (05ee07d) serving=2026.11.6 lastRun=succeeded stateBytes=8577024 captures=[{"name":".openclaw-private-update-capture","bytes":4096}] leftovers=[["~/.openclaw/openclaw.json.pre-update",4096]]
after-repeat: cli=OpenClaw 2026.11.6 (05ee07d) serving=2026.11.6 lastRun=skipped/already-current stateBytes=8663040 captures=[{"name":".openclaw-private-update-capture","bytes":4096}] leftovers=[["~/.openclaw/openclaw.json.pre-update",4096]]
Cell B: this head installed, candidate with an altered Gateway entry
update: status=error reason=global-install-failed 2026.11.5 -> 2026.11.5
  step updater-runtime-retention exit=0
  step package-install exit=0
  step package-verify exit=1
  step gateway recovery observation exit=0
  step recovery-artifact-cleanup exit=0 ["Update backup cleanup removed 1 item and freed 4 MiB, 4005399 bytes.","Removed ~/.openclaw.update-captures/9c10f310-67a7-4dc3-b4b0-e54769c055c1 (4 MiB, 4005399 bytes)."]

Package verification refused the altered file, so this failure never activated; it is not an activated rollback.

@fuller-stack-dev
fuller-stack-dev marked this pull request as draft November 19, 2026 11:09
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.
…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.
…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.
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Installed-package Docker cells on the final head (55065057da6)

Decisive excerpts (home directory shown as ~).

Cell A: published 2026.11.5 -> candidate (schema change), verified; then an already-current repeat
update: status=ok 2026.11.5 -> 2026.11.6
  step recovery-artifact-cleanup exit=0
  Update backup cleanup removed 3 items (7855384 logical bytes, 7 MiB).
  Removed ~/.openclaw/agents/main/agent/openclaw-agent.sqlite.pre-startup-migration-98b32130-9374-872b-8e76-3fe91c35c8a6.bak (667648 logical bytes, 1 MiB).
  Removed ~/.openclaw/state/openclaw.sqlite.pre-startup-migration-98b32130-9374-872b-8e76-3fe91c35c8a6.bak (3248128 logical bytes, 3 MiB).
  Removed ~/.openclaw.update-captures/4e8ac116-a8ed-4546-a366-c9002e56c21a (3939608 logical bytes, 4 MiB).
repeat: status=skipped reason=already-current 2026.11.6 -> 2026.11.6
  step recovery-artifact-cleanup exit=0
  Update backup cleanup removed 1 item (5582805 logical bytes, 5 MiB).
  Removed ~/.openclaw.update-captures/08e963bb-b8eb-4042-a610-8b7283e96930 (5582805 logical bytes, 5 MiB).
before: cli=OpenClaw 2026.11.5 (e13cf15) serving=2026.11.5 lastRun=none stateBytes=6483968 captures=[] leftovers=[]
after: cli=OpenClaw 2026.11.6 (5506505) serving=2026.11.6 lastRun=succeeded stateBytes=8581120 captures=[{"name":".openclaw-private-update-capture","bytes":4096}] leftovers=[["~/.openclaw/openclaw.json.pre-update",4096]]
after-repeat: cli=OpenClaw 2026.11.6 (5506505) serving=2026.11.6 lastRun=skipped/already-current stateBytes=8667136 captures=[{"name":".openclaw-private-update-capture","bytes":4096}] leftovers=[["~/.openclaw/openclaw.json.pre-update",4096]]
Cell B: this head installed; candidate activates, its post-activation Doctor fails, rollback; then a repeat that fails the same way
update: status=error reason=doctor-failed 2026.11.5 -> 2026.11.5
repeat: status=error reason=doctor-failed 2026.11.5 -> 2026.11.5
before: cli=OpenClaw 2026.11.5 (5506505) serving=2026.11.5 lastRun=none stateBytes=6684672 captures=[] leftovers=[]
after: cli=OpenClaw 2026.11.5 (5506505) serving=2026.11.5 lastRun=rolled-back/doctor-failed stateBytes=8798208 captures=[{"name":".openclaw-private-update-capture","bytes":4096},{"name":"652f6c89-c54f-46e3-ae1d-c77359e81d4b","bytes":4018176}] leftovers=[["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b",700416],["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b-wal",0],["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b.receipt.json",4096],["~/.openclaw/client/credentials.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b",49152],["~/.openclaw/client/credentials.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b.receipt.json",4096],["~/.openclaw/control/services.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b",16384],["~/.openclaw/control/services.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b.receipt.json",4096],["~/.openclaw/openclaw.json.pre-update",4096],["~/.openclaw/state/openclaw.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b",3264512],["~/.openclaw/state/openclaw.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b-shm",32768],["~/.openclaw/state/openclaw.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b-wal",0],["~/.openclaw/state/openclaw.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b.receipt.json",4096]]
after-repeat: cli=OpenClaw 2026.11.5 (5506505) serving=2026.11.5 lastRun=rolled-back/doctor-failed stateBytes=13008896 captures=[{"name":".openclaw-private-update-capture","bytes":4096},{"name":"652f6c89-c54f-46e3-ae1d-c77359e81d4b","bytes":4018176},{"name":"686fdda3-1afd-4e4c-9432-627a121b5b23","bytes":4063232}] leftovers=[["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b",700416],["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b-wal",0],["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b.receipt.json",4096],["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23",700416],["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23-wal",0],["~/.openclaw/agents/main/agent/openclaw-agent.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23.receipt.json",4096],["~/.openclaw/client/credentials.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b",49152],["~/.openclaw/client/credentials.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b.receipt.json",4096],["~/.openclaw/client/credentials.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23",49152],["~/.openclaw/client/credentials.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23.receipt.json",4096],["~/.openclaw/control/services.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b",16384],["~/.openclaw/control/services.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b.receipt.json",4096],["~/.openclaw/control/services.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23",16384],["~/.openclaw/control/services.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23.receipt.json",4096],["~/.openclaw/openclaw.json.pre-update",4096],["~/.openclaw/state/openclaw.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b",3264512],["~/.openclaw/state/openclaw.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b-shm",32768],["~/.openclaw/state/openclaw.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b-wal",0],["~/.openclaw/state/openclaw.sqlite.migrated-652f6c89-c54f-46e3-ae1d-c77359e81d4b.receipt.json",4096],["~/.openclaw/state/openclaw.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23",3280896],["~/.openclaw/state/openclaw.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23-shm",32768],["~/.openclaw/state/openclaw.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23-wal",0],["~/.openclaw/state/openclaw.sqlite.migrated-686fdda3-1afd-4e4c-9432-627a121b5b23.receipt.json",4096]]

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review November 19, 2026 14:35
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

CI on c9c5415fc32: one inherited failure

All checks pass except checks-node-compact-small-8 (and so openclaw/ci-gate). The only failing tests are four cases in test/scripts/package-acceptance-workflow.test.ts:

  • resolves broad release evidence and exact-binds every publish child
  • prepares one immutable candidate for release validation children
  • wires evidence attempts into the acceptance gate
  • keeps release publish artifacts and release-note ordering wired

Three of them fail with Expected workflow step Download full release validation manifest. #201802 (1579eb4dea9) removed that step from .github/workflows/openclaw-release-publish.yml without updating this test. This PR touches neither file. The same cases fail locally on this branch with scripts/e2e/lib/upgrade-survivor/run.sh (the only file this PR changes that the test reads) restored to the base version. Other PRs do not run this tooling shard because their diffs do not touch scripts/.

The earlier checks-node-compact-small-6 failure on 55065057da6 (compact github node test plan exceeds 77 jobs) was the main-plan capacity bug fixed by #201889 (edf77d9bab0); it passes on this head after merging main.

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Landing with an attributed pre-existing CI failure (maintainer-approved).

CI run 44556717551 (attempt 1) on head c9c5415fc32 has one failed test job, checks-node-compact-small-8, and openclaw/ci-gate fails only because of it. The job's only failures are four cases in test/scripts/package-acceptance-workflow.test.ts, inherited from main:

This PR changes neither .github/ nor that test, and both are identical in the tested merge's base (86441105b16) and the tested merge (8e3928be0). #201805 updates the test for both changes. The 354-line test-lines allocation in config/test-lines-allocations/201711-update-backup-cleanup-invariant.txt is maintainer-approved.

@fuller-stack-dev
fuller-stack-dev merged commit aecb49e into openclaw:main Nov 19, 2026
140 of 143 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

@fuller-stack-dev
fuller-stack-dev deleted the fix/update-cleans-up-its-backups-after-verified-success branch November 19, 2026 16:48
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 20, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL 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