Skip to content

Commit b37e142

Browse files
yanyunl1991claudeapurvvkumaria
authored
fix(upgrade): warn that non-.openclaw sandbox data is not preserved on recreate (#7073) (#7093)
## Context Part of #7073. A legacy `v0.0.55 → current` upgrade recreates the managed sandbox and restores it from a pre-upgrade backup. That backup scopes to `/sandbox/.openclaw` only (see `rebuild-backup-phase.ts` manifest `dir: "/sandbox/.openclaw"`), so any files the user keeps elsewhere in the sandbox (e.g. `/sandbox/user-data`) are dropped by the recreate with no prior notice. I reproduced the loss on real hardware: after a legacy-recreate, non-`.openclaw` paths are absent from the recreated sandbox while `.openclaw` state is restored intact. > Note: the **messaging-channel** loss facet of #7073 is being addressed separately via the maintainer's recommended `v0.0.63` migration bridge (which writes the plan-based `messaging` registry entry that #5123 made authoritative). I validated that bridge on a fresh `v0.0.63` install and reported the migrated-sandbox residual behavior in the issue thread. This PR does **not** claim to close that facet, so it does not `Fixes #7073`. ## Change Print a warning in the prepared-backup-recovery summary. It shows in both `upgrade-sandboxes --check` (dry run) and the real recreate, immediately after the list of sandboxes that will be recovered — i.e. before the destructive step — so users can back up non-`.openclaw` paths externally first. ``` Prepared backup recovery: my-assistant 2026-07-17T08-27-20-142Z (non-Ready) ⚠ Recovery restores /sandbox/.openclaw state only. Files outside .openclaw (e.g. /sandbox/user-data) are NOT preserved by the recreate — back them up before upgrading. ``` ## Verification - New unit test drives the real `upgradeSandboxes` through the prepared-recovery branch and asserts the warning is emitted. - Verified end-to-end on an x86_64 Ubuntu 24.04 host: forced a registered sandbox non-Ready with a validated backup and confirmed the live binary prints the warning in the `--check` output. - `typecheck:cli` and the full `upgrade-sandboxes-recovery` suite (35 tests) pass. ## Independent validation The reporter independently ran the full `v0.0.55 → v0.0.63 → v0.0.81` bridge on their own hardware and confirmed: the messaging bridge preserves the Slack channel (schema-v1 `messaging.plan` written on the v0.0.63 re-apply, survives to v0.0.81), while `/sandbox/user-data` seeded before the final upgrade is still lost afterward — i.e. the non-`.openclaw` data loss this PR warns about is the tracked concern of the issue, and an external backup remains required. ## Scope Deliberately narrow: a warning only. It does not change backup scope or restore behavior (widening the backup to cover arbitrary sandbox paths is a larger design decision about what the managed lifecycle owns). This just closes the silent-data-loss gap by making the boundary explicit before the irreversible recreate. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved sandbox upgrade/recovery messaging by adding a warning that recreate restores only the validated managed-state directory recorded in the recovery manifest, not other directories such as `/sandbox/user-data`, and reminding users to back up those paths beforehand. * **Tests** * Enhanced the recovery test harness to support per-agent restore manifest directories and added a parameterized test (issue `#7073`) verifying upgrade warning order and that `rebuildSandbox` runs only in `{ auto: true }` mode (none in `{ check: true }`). <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Yanyun Liao <[email protected]> --------- Signed-off-by: Apurv Kumaria <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Apurv Kumaria <[email protected]>
1 parent aa3dd78 commit b37e142

2 files changed

Lines changed: 112 additions & 16 deletions

File tree

‎src/lib/actions/upgrade-sandboxes-recovery.test.ts‎

Lines changed: 105 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,26 @@ import { upgradeSandboxes, upgradeSandboxesDependencies } from "./upgrade-sandbo
1212

1313
type UpgradeSandboxes = typeof upgradeSandboxes;
1414

15-
function makeManifest(sandboxName: string) {
15+
type ManifestAgentType = "openclaw" | "hermes";
16+
17+
const MANIFEST_DIR_BY_AGENT: Record<ManifestAgentType, string> = {
18+
openclaw: "/sandbox/.openclaw",
19+
hermes: "/sandbox/.hermes",
20+
};
21+
22+
function makeManifest(sandboxName: string, agentType: ManifestAgentType = "openclaw") {
1623
const timestamp = `2026-07-01T06-50-4${sandboxName.length}-044Z`;
1724
return {
1825
version: 1,
1926
sandboxName,
2027
timestamp,
21-
agentType: "openclaw",
28+
agentType,
2229
agentVersion: "2026.5.27",
2330
expectedVersion: "2026.5.27",
2431
stateDirs: ["workspace"],
2532
backedUpDirs: ["workspace"],
2633
stateFiles: [],
27-
dir: "/sandbox/.openclaw",
34+
dir: MANIFEST_DIR_BY_AGENT[agentType],
2835
backupPath: `/tmp/rebuild-backups/${sandboxName}/${timestamp}`,
2936
blueprintDigest: null,
3037
policyPresets: [],
@@ -40,16 +47,19 @@ function createRecoveryHarness(
4047
gatewayPort?: number;
4148
liveOutput?: string;
4249
latestBackup?: ReturnType<typeof makeManifest> | null;
43-
registryOverrides?: Record<
44-
string,
45-
Partial<{
46-
agent: "openclaw" | "hermes" | "langchain-deepagents-code" | null;
47-
agentVersion: string | null;
48-
createdAt: string;
49-
nemoclawVersion: string | null;
50-
fromDockerfile: string | null;
51-
pendingRouteReservation: true;
52-
}>
50+
manifestAgentTypes?: Partial<Record<string, ManifestAgentType>>;
51+
registryOverrides?: Partial<
52+
Record<
53+
string,
54+
Partial<{
55+
agent: "openclaw" | "hermes" | "langchain-deepagents-code" | null;
56+
agentVersion: string | null;
57+
createdAt: string;
58+
nemoclawVersion: string | null;
59+
fromDockerfile: string | null;
60+
pendingRouteReservation: true;
61+
}>
62+
>
5363
>;
5464
confirmedLegacyManagedNames?: string[] | string;
5565
staleNames?: string[];
@@ -107,9 +117,12 @@ function createRecoveryHarness(
107117
});
108118
const latestBackupSpy = vi
109119
.spyOn(sandboxState, "getLatestBackup")
110-
.mockImplementation((...args: unknown[]) =>
111-
options.latestBackup === undefined ? makeManifest(String(args[0])) : options.latestBackup,
112-
);
120+
.mockImplementation((...args: unknown[]) => {
121+
const sandboxName = String(args[0]);
122+
return options.latestBackup === undefined
123+
? makeManifest(sandboxName, options.manifestAgentTypes?.[sandboxName])
124+
: options.latestBackup;
125+
});
113126
vi.spyOn(sandboxState, "validateRebuildRecoveryManifest").mockImplementation(
114127
(...args: unknown[]) => ({
115128
ok: true as const,
@@ -190,6 +203,82 @@ describe("upgrade-sandboxes prepared backup recovery (#6114)", () => {
190203
}
191204
});
192205

206+
it.each([
207+
{
208+
mode: "automatic",
209+
options: { auto: true },
210+
expectedRebuilds: 2,
211+
expectedSequence: [
212+
"warning:/sandbox/.openclaw",
213+
"warning:/sandbox/.hermes",
214+
"rebuild:openclaw-box",
215+
"rebuild:hermes-box",
216+
],
217+
},
218+
{
219+
mode: "check-only",
220+
options: { check: true },
221+
expectedRebuilds: 0,
222+
expectedSequence: ["warning:/sandbox/.openclaw", "warning:/sandbox/.hermes"],
223+
},
224+
] as const)("warns with each agent's restore path before $mode mixed recovery (#7073)", async ({
225+
options,
226+
expectedRebuilds,
227+
expectedSequence,
228+
}) => {
229+
const sequence: string[] = [];
230+
const warningMessages: string[] = [];
231+
const statePaths = ["/sandbox/.openclaw", "/sandbox/.hermes"];
232+
const harness = createRecoveryHarness(["openclaw-box", "hermes-box"], {
233+
manifestAgentTypes: { "openclaw-box": "openclaw", "hermes-box": "hermes" },
234+
registryOverrides: {
235+
"openclaw-box": { agent: "openclaw" },
236+
"hermes-box": { agent: "hermes" },
237+
},
238+
});
239+
vi.mocked(console.log).mockImplementation((...args) => {
240+
const message = String(args[0]);
241+
warningMessages.push(...[message].filter((entry) => entry.includes("⚠ Recovery restores")));
242+
sequence.push(
243+
...statePaths
244+
.filter((candidate) =>
245+
message.includes(`Recovery restores ${JSON.stringify(candidate)} state only`),
246+
)
247+
.map((statePath) => `warning:${statePath}`),
248+
);
249+
});
250+
harness.rebuildSpy.mockImplementation(async (name: string) => {
251+
sequence.push(`rebuild:${name}`);
252+
});
253+
254+
await expect(harness.upgradeSandboxes(options)).resolves.toBeUndefined();
255+
256+
expect(warningMessages).toHaveLength(statePaths.length);
257+
expect(
258+
warningMessages.map((message) =>
259+
statePaths.filter((statePath) =>
260+
message.includes(`Recovery restores ${JSON.stringify(statePath)} state only`),
261+
),
262+
),
263+
).toEqual(statePaths.map((statePath) => [statePath]));
264+
for (const statePath of statePaths) {
265+
expect(console.log).toHaveBeenCalledWith(
266+
expect.stringContaining(
267+
`Recovery restores ${JSON.stringify(statePath)} state only for this sandbox`,
268+
),
269+
);
270+
}
271+
expect(console.log).toHaveBeenCalledWith(
272+
expect.stringContaining("Files outside this recorded managed state path"),
273+
);
274+
expect(console.log).toHaveBeenCalledWith(expect.stringContaining("/sandbox/user-data"));
275+
expect(console.log).toHaveBeenCalledWith(
276+
expect.stringContaining("NOT preserved by the recreate"),
277+
);
278+
expect(harness.rebuildSpy).toHaveBeenCalledTimes(expectedRebuilds);
279+
expect(sequence).toEqual(expectedSequence);
280+
});
281+
193282
it("continues through all eligible sandboxes before reporting a recovery failure", async () => {
194283
const harness = createRecoveryHarness(["alpha", "beta"]);
195284
harness.rebuildSpy.mockRejectedValueOnce(new Error("alpha failed"));

‎src/lib/actions/upgrade-sandboxes.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ export async function upgradeSandboxes(
364364
console.log(
365365
` ${recovery.sandbox.name} ${D}${recovery.manifest.timestamp}${R} (non-Ready)`,
366366
);
367+
// #7073: the validated manifest records the agent-specific managed state
368+
// root restored for this sandbox. Warn before the destructive recreate so
369+
// users can back up paths outside that exact root rather than silently
370+
// losing them.
371+
console.log(
372+
` ${YW}⚠ Recovery restores ${JSON.stringify(recovery.manifest.dir)} state only for this sandbox. Files outside this recorded managed state path (e.g. /sandbox/user-data) are NOT preserved by the recreate — back them up before upgrading.${R}`,
373+
);
367374
}
368375
}
369376
if (rejectedRecoveries.length > 0) {

0 commit comments

Comments
 (0)