Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/lib/sandbox-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,21 @@ export function restoreSandboxState(
return { success: false, restoredDirs, failedDirs: [...localDirs] };
}

// Remove existing state dirs before extracting so stale files from
// later snapshots don't persist after restoring an earlier one.
const rmCmd = localDirs
.map((d) => `rm -rf "${writableDir}/${d}"`)
.join(" && ");
_log(`Cleaning target dirs before restore: ${rmCmd}`);
const rmResult = spawnSync(
"ssh",
[...sshArgs(configFile, sandboxName), rmCmd],
{ stdio: ["ignore", "pipe", "pipe"], timeout: 30000 },
);
if (rmResult.status !== 0) {
_log(`WARNING: pre-restore cleanup failed (exit ${rmResult.status}): ${(rmResult.stderr?.toString() || "").substring(0, 200)}`);
}

const extractCmd = `tar -xf - -C ${writableDir}`;
const sshResult = spawnSync(
"ssh",
Expand Down
10 changes: 10 additions & 0 deletions src/nemoclaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,16 @@ function sandboxSnapshot(sandboxName, subArgs) {
break;
}
case "restore": {
const isLive = captureOpenshell(["sandbox", "list"], { ignoreError: true });
if (isLive.status !== 0) {
console.error(" Failed to query live sandbox state from OpenShell.");
process.exit(1);
}
const liveNames = parseLiveSandboxNames(isLive.output || "");
if (!liveNames.has(sandboxName)) {
console.error(` Sandbox '${sandboxName}' is not running. Cannot restore snapshot.`);
process.exit(1);
}
const timestamp = subArgs[1] || null;
let backupPath;
if (timestamp) {
Expand Down
Loading