Repository navigation
fix(update): retire database snapshots of earlier updates after a verified update - #202591
Conversation
|
🦞👀 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: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
|
Exact-head follow-up on |
…ed update Update cleanup now lists the pre-migration .databases snapshot directory each update recorded in update history and removes it once a later update that started after that run finished is verified successful. Unfinished runs, pending recoveries, the latest verified run and unrecorded directories keep theirs and are reported with size and reason.
…ified update OpenClaw-Publication: db146582-b8a2-8de7-9073-17ee98535f6f
…rate replaced roots
96e891b to
84954c9
Compare
|
Merged via squash.
|
…ified update (openclaw#202591) * fix(update): retire database snapshots of earlier runs after a verified update Update cleanup now lists the pre-migration .databases snapshot directory each update recorded in update history and removes it once a later update that started after that run finished is verified successful. Unfinished runs, pending recoveries, the latest verified run and unrecorded directories keep theirs and are reported with size and reason. * fix(update): keep ambiguous and unreadable snapshot locations out of cleanup * fix(update): retire database snapshots of earlier updates after a verified update OpenClaw-Publication: db146582-b8a2-8de7-9073-17ee98535f6f * fix(update): drop server captures before retiring a snapshot and tolerate replaced roots * test(update): keep snapshot cleanup tests within the test-line budget * docs(update): describe in-place Git snapshots as left by older updaters * fix(update): keep the triggering run snapshot and resume interrupted snapshot removal * test(update): keep snapshot cleanup tests within the test-line budget
…e Node (#203152) * fix(update): drain a Gateway that runtime recovery reran under another Node A service whose Node is unsupported or lacks a recommended security patch reruns the Gateway under a compatible Node as a child of the launcher, so the service's main PID never equals the PID the resident reports. Maintenance drain refused every such update with 'Gateway process changed during maintenance drain'. Accept the resident when every Gateway port listener is that process and its parent is the service's main process, matching restart port ownership. Refs #202954 * docs(update): runtime recovery reruns the Gateway only when its Node fails admission Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit a27f0c3) Release-companions: #204017 is a separate Linux release-install Doctor fallback when lsof/ss cannot attribute listeners; it is not required for this attributed-listener runtime-recovery case. #203486 pnpm recovery, #201668 data-risk repair, and #202591 snapshot cleanup only overlap documentation; #203236 is independent auto-update retry policy. The neighboring native drain suite remains unchanged. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
An update can leave a full copy of the databases in a
.databasesdirectory. Only the creating run's own verified completion removes it. Nothing removes one that a failed update, an update without automatic restoration, or an older updater left behind. On one host, eight of them held 63 GiB.On today's
main(after #200578 and #201711):<package-backup>.databasesbeside the package backup. A verified update removes its own; a failed one, or one whose restoration was unavailable, keeps it.<checkout>/.artifacts/dist-runtime.openclaw-update-<uuid>.tmp.databasesdirectories. No code onmainnames or removes those (the affected host has four, about 34 GiB)..migrated-<runId>files and original-state captures. It does not touch.databasesdirectories.User Impact
User impact: after a later update is verified healthy, update cleanup removes the snapshot directories earlier updates left behind, both automatically and through
openclaw update cleanup(and the Gateway'supdate.cleanup, including dry run). This includes the ones older updaters left in a Git checkout's.artifacts. The ones it keeps are listed with their size and reason. The latest verified update's own snapshot waits for the next verified update. Snapshots of a Git checkout outside the home directory are not found and stay, as do snapshots no listed update recorded. Withdatabase.postgres.recoveryCaptures: "server", cleanup drops a snapshot's PostgreSQL capture schemas before deleting it, and keeps and reports the snapshot when that drop fails.Why This Change Was Made
A snapshot directory's name carries a transaction id, not a run id, and nothing inside it names a run (
schema-discovery-ownership.jsonmaps databases to owners only). The only record linking it to an update is thedatabase snapshotlocation in update history. Cleanup now reads that location and treats a snapshot as superseded once a verified successful update started after its run finished. That is the rule original-state captures already follow, decided by run order and never by file times.orphan-database-snapshot; only file times could order it).<image>.postgresexport manifests are the only record of the capture schemas on the server. Cleanup passes the export directories that hold a manifest to the existingdiscardPostgresSchemaCapturesfirst, with the configuration cleanup already reads. If the drop fails, the directory stays and the item reportsfailed/database-snapshot-retirement-failedwithPostgreSQL capture cleanup remains pending at <directory>; a later cleanup retries. A.postgresdirectory without a manifest is a mirrored source directory or the rest of an interrupted removal, and does not block cleanup.~and redacts other install roots to[path], so a checkout outside the home directory cannot be resolved. When the OpenClaw home and the OS home differ,~names two directories and attributes none.Decisions for the maintainer:
--include-unmanifestedcannot select them.core/doctor/update-snapshotscheck still advises manual removal.openclaw update finishdoes for its own receipt. Accepted: if the configuration now names a different PostgreSQL server than the one the snapshot was captured on,DROP SCHEMA IF EXISTSfinds nothing there, the snapshot is deleted, and the capture schema on the old server stays.Evidence
Head
3d509d0, rebased ontomain4bedaed. The real runs below used9334a04;3d509d0differs from it in one test file only.Tests (each red on the base, green on the branch)
src/cli/update-cli/update-command-database-snapshot-cleanup.test.ts(new, 7 tests) runs the realupdateCleanupCommandandcleanupCompletedUpdateRecoveryover a temp home with real update-history rows:--yesand automatic cleanup remove only the two superseded snapshots (a legacy Git one under a previous checkout root, a package one outside home);ENOTDIR) no longer aborts cleanup;failedand the command exits 1.src/infra/database-engine/backup-schema-capture.test.tsagainst real PostgreSQL 17 (scripts/test-database-conformance.mjs, disposablepgvector/pgvector:pg17container): a real update capture creates arestore_…schema andupdateCleanupCommand({ yes: true })runs twice. With an unreachable connection the schema and manifest both remain and the item reportsfailed. With the real connection the capture schema is dropped, the live store's schema remains and the directory is gone. Run on84954c9, not repeated after the later two commits.main, and the PostgreSQL test fails the same way. The triggering-run and manifest cases were each red without their fix.pnpm check:changedon9334a04: exit 0. Net test lines against the merge base: +400 of 400 (9334a04failedchecks-fast-baseline-ratchetsat +409;3d509d0folds one test into another).It works: legacy Git snapshots (Crabbox
local-containeron the Mac Studio,node:24.22.1-trixie, leasecbx_d34709ead512, runrun_534ff1aa121f62943602014dc138d057, exit 0)44ec89e) updates a source checkout in place four times while the Gateway runs by hand: twice under~/Projects/openclaw/.worktrees/live-main-ba9f1ea, twice under~/Projects/openclawafter the install moves. Each run keeps its.artifacts/dist-runtime.openclaw-update-<uuid>.tmp.databases(17.8 MB together).failed/post-update-failed, a faileddatabase rollbackstep): two with the Oct 27 2026 wording, two with the Oct 3 to Oct 20 wording. This is the only state edit.main4bedaed. All four directories remain, andmain'sopenclaw update cleanup --dry-run --jsonlists nodatabase-snapshotartifact.serviceRunning,versionMatch,settled,coreReady, no plugin errors). Its automatic cleanup reportsRemoved …/.worktrees/live-main-ba9f1ea/.artifacts/dist-runtime.openclaw-update-26124ce4-….tmp.databases (4272383 logical bytes)and the other three. No snapshot directory remains.mainexited 1 (post-update-failed: the old checkout build refused the new state schema) although the Gateway then served from the release. So this run shows thatmainneither lists nor removes these directories, not that they survive a verified update onmain. That failure happened before any code from this PR was installed.It works: package install (lease
cbx_c94e7446a4a3, runrun_f7324d80b838230c88083cd349e11a46, exit 0)npm install -g [email protected], thenopenclaw update --tag <tarball>tomain~6(a27f0c3) and to this PR with the Gateway service running. Both finish verified. Each run snapshots to~/.npm-global/lib/node_modules/.openclaw.package-backup-<pid>-<ts>.databasesand removes it on its own verified completion; none remain and the dry run is empty.gateway-stop-unverified) before taking one.It does not break existing upgrades (repository upgrade lanes,
scripts/e2e/upgrade-survivor-docker.sh, run from leasecbx_fc8ff4647655through the Studio's Docker engine, candidate9334a04)[email protected]git-release(Git install, kill pointsstage build publish link-switch launcher-restore)v2026.11.6recovery-cleanup[email protected]package-swap, inheritedgit-release: the first run passed every phase throughgit-kill-build, then failed ingit-kill-publishbecause the harness missed its kill window ("missed":"the link moved before the release smoke was seen"). The second run, with kill pointspublish link-switch launcher-restore, passed (Git release survivor passed: route baseline.).recovery-cleanup:State schema inspection failed … during pre-migration database backup for …/client/credentials.sqlite … hardlink publication target changed, then a clean package rollback. fix(update): reclaim abandoned updater runtimes on a busy host #202590 saw the same signature onmain(leasecbx_e9fabf91f712). It was not rerun onmainhere.Earlier proof on
5fb7e5a, before the rebase (leasescbx_5fe14464ed65,cbx_892d7fe68601,cbx_f37a9e6d9f22): base kept three in-place Git snapshots after a verified update and did not list them; head listed them asawaiting-later-verified-updateand removed them after the verified update.Not proven
openclaw update cleanup --yesremoving a snapshot candidate through the real CLI: automatic cleanup always got there first.openclaw updatecycle on a PostgreSQL install.~\expansion, receipt wording of updaters before Oct 3 2026, and an install root failing withEACCES(same guard asENOTDIR, no test)./srv/p…law/.worktrees/…). Such a receipt does not resolve, so that snapshot stays.🦞 Made with OpenClaw