Skip to content

Commit 54a2f09

Browse files
committed
feat(update): clean up retained migration recovery files
Add explicit, profile-aware recovery cleanup with read-only preview, offline consent, durable disposal receipts, and conservative protection of unique history. Preserve one untouched legacy transcript through bounded import repair and retain recovery mappings until their payloads are retired. Document rollback loss, portable-backup exclusions, and migration resource requirements. Refs #133805
1 parent a226416 commit 54a2f09

57 files changed

Lines changed: 7352 additions & 1587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/assertion-safety-baseline.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,14 +2487,14 @@ src/commands/doctor-session-incognito-key-repair-state.ts 8
24872487
src/commands/doctor-session-incognito-key-repair.ts 4
24882488
src/commands/doctor-session-snapshots.ts 5
24892489
src/commands/doctor-session-sqlite-compact.ts 1
2490-
src/commands/doctor-session-sqlite-migration-run.ts 8
2490+
src/commands/doctor-session-sqlite-migration-run.ts 6
24912491
src/commands/doctor-session-sqlite-readers.ts 5
24922492
src/commands/doctor-session-sqlite-recover-report.ts 3
2493-
src/commands/doctor-session-sqlite.ts 3
2493+
src/commands/doctor-session-sqlite.ts 2
24942494
src/commands/doctor-session-state-providers.ts 3
24952495
src/commands/doctor-session-transcript-headers.ts 5
24962496
src/commands/doctor-session-transcript-labels.ts 4
2497-
src/commands/doctor-session-transcripts.ts 5
2497+
src/commands/doctor-session-transcripts.ts 1
24982498
src/commands/doctor-skill-workshop-sqlite.ts 1
24992499
src/commands/doctor-skills.ts 1
25002500
src/commands/doctor-sqlite-compact.ts 3

‎config/knip.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const repositoryScriptEntries = [
7474
"scripts/upgrade-survivor-diagnostics.mjs!",
7575
"scripts/e2e/lib/upgrade-survivor/probe-gateway.mjs!",
7676
"scripts/e2e/lib/upgrade-survivor/probe-volume-gateway.mjs!",
77+
"scripts/e2e/lib/upgrade-survivor/recovery-cleanup.mjs!",
7778
// update-restart-auth.sh installs this manager/launch adapter into the fixture bin directory.
7879
"scripts/e2e/lib/upgrade-survivor/systemd-fixture.mjs!",
7980
"scripts/embedded-run-abort-leak.ts!",

‎config/max-lines-baseline.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ src/commands/doctor-gateway-services.ts
512512
src/commands/doctor-legacy-config.migrations.test.ts
513513
src/commands/doctor-memory-search.test.ts
514514
src/commands/doctor-memory-search.ts
515-
src/commands/doctor-session-sqlite-migration-run.ts
516515
src/commands/doctor-session-sqlite.test.ts
517516
src/commands/doctor-session-sqlite.ts
518517
src/commands/doctor-state-integrity.ts

‎docs/cli/doctor.md‎

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,25 @@ migration sources. Hot transcript JSONL files are imported and archived after
311311
successful import; archive-tier JSONL files remain support artifacts, not
312312
runtime fallbacks.
313313

314-
The import stages transcript payloads in a private, temporary SQLite database
315-
instead of retaining complete batches of histories in memory. Keep free space
316-
on the system temporary volume as well as the volume holding OpenClaw state.
314+
The public Doctor migration path stages transcript payloads and performs branch
315+
and provider repairs in a private, temporary SQLite database instead of retaining
316+
complete histories in memory. It keeps the raw transcript untouched until archiving it through an
317+
exclusive same-filesystem move, avoiding both an extra full `.pre-doctor` raw
318+
copy and a rewritten intermediate file. Standalone transcript repair retains
319+
its original backup behavior.
320+
321+
For large histories, plan space for the original JSON/JSONL files, the temporary
322+
SQLite spool, and the destination database and WAL at the same time. Keep free
323+
space on both the system temporary volume and the volume holding OpenClaw state;
324+
the resulting SQLite database can be larger than the original JSONL. Streaming
325+
reduces whole-history memory pressure, but individual records are still parsed
326+
in memory and SQLite also uses native memory. Do not size a host from the JSONL
327+
byte count or JavaScript heap limit alone; there is no fixed disk, RAM, or
328+
migration-time guarantee.
329+
317330
Staging is removed when the operation finishes and is never used as a runtime
318331
store or resumed after an interruption; retries use the original sources and
319-
committed session data. Individual transcript records are still parsed in memory.
320-
After import, Doctor checkpoints and incrementally vacuums databases that already
332+
committed session data. After import, Doctor checkpoints and incrementally vacuums databases that already
321333
support auto-vacuum, retaining full integrity and foreign-key checks before and
322334
after cleanup. Databases without auto-vacuum still need a full `VACUUM` to enable
323335
it. Incremental cleanup frees unused pages but does not repack partially filled
@@ -434,10 +446,21 @@ copies created by older writers. Distinct nonempty indexes, distinct transcript
434446
archives, invalid archives, and archives missing without a recorded prior
435447
restore fail closed so restore cannot silently replace or hide recoverable data.
436448

449+
After verifying the migration and current history, use
450+
`openclaw update cleanup --dry-run` to inspect retained recovery data without
451+
stopping the Gateway. Apply with `openclaw update cleanup` or
452+
`openclaw update cleanup --yes --json` only after stopping the Gateway and other
453+
SQLite maintenance for the same profile/state directory. This permanently
454+
retires eligible rollback originals; it does not remove current SQLite history
455+
or operator backups. Manifests remain while retained or pending artifacts need
456+
them, so interrupted cleanup can be resumed. Restore distinguishes intentional
457+
disposal, pending cleanup, and unexpected missing files. See
458+
[Update cleanup](/cli/update#update-cleanup).
459+
437460
### Downgrading After Session SQLite Migration
438461

439-
Before starting an older file-backed OpenClaw version, restore the archived
440-
legacy transcript artifacts:
462+
With the Gateway stopped, use the current CLI to restore archived legacy
463+
transcript artifacts before starting an older file-backed OpenClaw version:
441464

442465
```bash
443466
openclaw doctor --session-sqlite restore --session-sqlite-all-agents
@@ -449,6 +472,11 @@ transcripts into `session-sqlite-import-archive/`, so the older runtime cannot
449472
see that history until restore moves those manifest-recorded artifacts back to
450473
their original paths.
451474

475+
If `openclaw update cleanup` already disposed of the originals, restore reports
476+
that outcome and cannot recreate them. You need an independent backup containing
477+
those legacy files; see [Pre-update backups](/install/updating#before-updating-create-a-verified-backup)
478+
for portable-archive exclusions.
479+
452480
Restore does not delete SQLite data. Sessions created after the SQLite flip
453481
exist only in SQLite and will not appear to the older runtime. If you later
454482
upgrade again, run the normal migration validation sequence above so OpenClaw can

‎docs/cli/update.md‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
2-
summary: "CLI reference for `openclaw update` (safe-ish source update + gateway auto-restart)"
2+
summary: "CLI reference for `openclaw update` (updates, repair, and recovery cleanup)"
33
read_when:
44
- You want to update a source checkout safely
55
- You are debugging `openclaw update` output or options
6+
- You want to inspect or retire migration recovery originals after an update
67
- You need to understand `--update` shorthand behavior
78
title: "Update"
89
---
@@ -21,6 +22,7 @@ updates go through the package-manager flow described in
2122
openclaw update
2223
openclaw update status
2324
openclaw update repair
25+
openclaw update cleanup --dry-run
2426
openclaw update wizard
2527
openclaw update --channel extended-stable
2628
openclaw update --channel beta
@@ -151,6 +153,76 @@ automation can use `openclaw update repair --accept-capabilities`. Acceptance
151153
applies to each artifact's recomputed declared surface during this invocation;
152154
it does not approve future capability additions.
153155

156+
## `update cleanup`
157+
158+
Retire migration recovery originals after you have verified that the upgrade and
159+
session history work. Start with a preview, which can run while the Gateway is
160+
active:
161+
162+
```bash
163+
openclaw update cleanup --dry-run
164+
openclaw --profile work update cleanup --dry-run --json
165+
```
166+
167+
Cleanup targets the selected profile and `OPENCLAW_STATE_DIR` / `OPENCLAW_CONFIG_PATH`
168+
overrides. It displays that state directory and does not redirect to a managed
169+
service. Confirm the displayed directory is the installation you intend to clean.
170+
`--dry-run` reads only configuration and recovery metadata, without opening
171+
databases, taking a maintenance lock, loading plugins, or creating state.
172+
Candidate bytes still require identity verification; historical artifacts are
173+
listed separately as requiring verification. Protected and blocked artifacts
174+
include reason codes.
175+
176+
Before applying, stop the Gateway for that same profile/state directory and wait
177+
for other SQLite maintenance commands to finish. Cleanup requires exclusive
178+
offline state ownership and never stops or restarts a service itself.
179+
180+
<Warning>
181+
Cleanup permanently removes the selected rollback originals, including branches
182+
and metadata intentionally removed by a verified repair. Doctor restore cannot
183+
recreate them afterward. Keep them, or preserve an independent backup containing
184+
them, if you still need that rollback path. Current SQLite history stays in place.
185+
</Warning>
186+
187+
```bash
188+
openclaw update cleanup
189+
openclaw update cleanup --yes --json
190+
```
191+
192+
Interactive confirmation defaults to **No**. JSON mode never prompts or grants
193+
consent; unattended deletion requires `--yes`. Consent does not override
194+
ownership, file identity, or dependency checks. Applicable flags (`--dry-run`,
195+
`--yes`, and `--json`) work before or after `cleanup`; update-only flags
196+
`--channel`, `--tag`, `--timeout`, `--no-restart`, and `--accept-capabilities`
197+
are rejected.
198+
199+
Only owner-recorded recovery artifacts with complete import evidence are
200+
eligible. Unknown or unimported history, malformed inputs, trajectories,
201+
forensic corrupt databases, operator backups, and unmanifested artifacts stay
202+
protected. Old manifests are verified offline where possible; missing evidence
203+
is a reason to retain an artifact. Cleanup has no automatic expiration policy.
204+
205+
The JSON result contains `stateDir`, `status`, `artifacts`, and `totals`. Each
206+
artifact reports its path, run ids, logical bytes, outcome, and reason. Totals
207+
separate candidates, verification-required, protected, blocked, and removed
208+
bytes. Removal failures exit nonzero. Keep the recovery manifests and rerun
209+
cleanup to finish recorded interrupted work; a retry does not delete a recreated
210+
file. Removed logical bytes do not promise
211+
equivalent physical space reclamation on cloned or snapshotted filesystems.
212+
When a path cannot be inspected, its logical size comes from recorded artifact
213+
metadata when available. Cleanup records durable intent before removal and uses
214+
exclusive no-copy publication. Failures are reported; retries reconcile file
215+
operations that already completed. Manifest files are synchronized before removal;
216+
parent directories are synchronized where supported. Windows does not provide the
217+
same parent-directory durability guarantee.
218+
219+
Doctor restore reports intentionally disposed originals and pending cleanup
220+
explicitly. Neither update nor cleanup creates an automatic full-state backup;
221+
these recovery originals are **not a full pre-upgrade backup**. See
222+
[Before updating: create a verified backup](/install/updating#before-updating-create-a-verified-backup)
223+
for backup coverage and [Doctor recovery](/cli/doctor#session-sqlite-migration)
224+
for restoring retained originals.
225+
154226
## `update wizard`
155227

156228
Interactive flow to pick an update channel and confirm whether to restart the

‎docs/install/updating.md‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ For Docker, Podman, and Kubernetes image replacements, see
1313
gateway runs startup-safe upgrade work before readiness and exits if mounted
1414
state needs manual repair.
1515

16+
Before a significant update, [create a verified backup](#before-updating-create-a-verified-backup).
17+
Automatic config copies and migration recovery originals are not a full-state
18+
backup.
19+
1620
## Recommended: `openclaw update`
1721

1822
Detects your install type (npm, pnpm, Bun, or git), fetches the latest version, runs `openclaw doctor`, and restarts the gateway.
@@ -77,6 +81,29 @@ default/latest release.
7781

7882
See [Release channels](/install/development-channels) for channel semantics.
7983

84+
## Retire update recovery data
85+
86+
Once you have verified the update and your conversations, preview retained
87+
migration originals:
88+
89+
```bash
90+
openclaw update cleanup --dry-run
91+
```
92+
93+
Use the same profile and state/config overrides as the update, and check the
94+
state directory printed in the report. The metadata-only preview can run while
95+
the Gateway is active. To apply, stop that Gateway yourself, wait for other
96+
SQLite maintenance to finish, then run `openclaw update cleanup`. Cleanup never
97+
stops or restarts the Gateway. Confirmation defaults to **No**; automation must
98+
explicitly pass `--yes`, including when using `--json`.
99+
100+
Cleanup permanently gives up rollback to eligible originals, including repaired
101+
branches and old provider metadata. Current SQLite history, operator backups,
102+
and protected or unknown artifacts remain. It is not a substitute for a
103+
[pre-update backup](#before-updating-create-a-verified-backup). See
104+
[Update cleanup](/cli/update#update-cleanup) for eligibility, JSON output, and
105+
resuming interrupted deletion.
106+
80107
## Switch between npm and git installs
81108

82109
Installer-driven switches verify the replacement before the working owner is retired. Source wrappers are published atomically; same-path npm shim transitions use an identity-checked backup that is restored on failure, so a failed candidate leaves the previous command runnable. The `openclaw update` command prints its final success result only after post-core convergence and requested restart health checks succeed.
@@ -473,7 +500,16 @@ omitted files.
473500

474501
For a byte-for-byte recovery point that includes volatile artifacts omitted by
475502
the portable archive, stop the Gateway and use a filesystem, volume, or VM
476-
snapshot provided by your platform.
503+
snapshot provided by your platform. This matters for older file-backed installs:
504+
the portable archive omits matching JSONL transcripts and logs even when they
505+
are no longer being written.
506+
507+
When migrating large legacy histories, leave room for the original files, a
508+
temporary SQLite spool, and the destination database/WAL simultaneously. SQLite
509+
can be larger than the original JSONL; streaming import does not imply a fixed
510+
RAM requirement or migration time. Check free space on both the system temporary
511+
volume and the state volume. See [Session SQLite migration](/cli/doctor#session-sqlite-migration)
512+
for staging and memory details.
477513

478514
### Roll back a package install
479515

‎docs/reference/session-management-compaction.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ Normal Gateway writes flow through the session accessor, which serializes per-ag
7979

8080
OpenClaw no longer creates automatic `sessions.json.bak.*` rotation backups during Gateway writes. The current schema rejects the legacy `session.maintenance.rotateBytes` key, and `openclaw doctor --fix` removes it from older configs.
8181

82+
Migration recovery originals and exact pre-Doctor recovery files are separate
83+
from ordinary session retention: they are excluded from the live session disk
84+
budget and have no automatic expiration. After verifying the upgrade, use
85+
`openclaw update cleanup --dry-run` to inspect them online. Explicit offline
86+
[update cleanup](/cli/update#update-cleanup) can retire verified originals
87+
without removing current SQLite history; exclusion from the disk budget is not
88+
deletion authority.
89+
8290
Transcript mutations pass through the session accessor and SQLite writer queue.
8391
Each mutation verifies the active run's durable writer claim inside its commit
8492
transaction, so a superseded run cannot write to the transcript.
@@ -103,6 +111,12 @@ Restore uses migration manifests, moves only recorded archived artifacts whose
103111
original paths are missing, reports conflicts rather than overwriting existing
104112
files, and leaves the SQLite database in place for forward recovery.
105113

114+
Originals retired by `openclaw update cleanup` can no longer be restored from
115+
the migration archive. Restore reports intentional disposal or pending cleanup
116+
instead of treating either as an unexpectedly missing file. An independent
117+
backup containing the legacy artifacts is required if you need them after
118+
disposal; see [Pre-update backups](/install/updating#before-updating-create-a-verified-backup).
119+
106120
Restore does not export changes made only in SQLite after migration. Sessions
107121
created after the SQLite flip are SQLite-only and will not appear to an older
108122
file-backed runtime. If you re-upgrade after a downgrade, run the Doctor

‎scripts/e2e/lib/upgrade-survivor/assertions.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const SCENARIOS = new Set([
2626
"versioned-runtime-deps",
2727
"cron-scheduled-authority",
2828
"sqlite-volume",
29+
"recovery-cleanup",
2930
"auth-profile-v2026-7-2-beta-5",
3031
]);
3132

‎scripts/e2e/lib/upgrade-survivor/config-recipe.mts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,26 @@ const configuredPluginInstallSteps = [
178178
];
179179

180180
const scenarioConfigSteps = new Map<string, ConfigStep[]>([
181+
[
182+
"recovery-cleanup",
183+
[
184+
{
185+
id: "recovery-agents",
186+
intent: "recovery-cleanup",
187+
argv: [
188+
"config",
189+
"set",
190+
"agents.list",
191+
JSON.stringify([
192+
...JSON.parse(readConfigSection("agents.json")).list,
193+
{ id: "recovery-clean", workspace: "~/workspace/recovery-clean" },
194+
{ id: "recovery-protected", workspace: "~/workspace/recovery-protected" },
195+
]),
196+
"--strict-json",
197+
],
198+
},
199+
],
200+
],
181201
[
182202
"acpx-openclaw-tools-bridge",
183203
[

0 commit comments

Comments
 (0)