A failed OpenClaw config publish is reported as a successful state restore
Investigation Summary
buildStateFileRestoreCommandjoins its copy-strategy steps with"; "(src/lib/state/state-file-restore.ts:133), so the remote script reports the exit status of its last step only.- On the OpenClaw config path the last step is
chmod 660 "$hash_file" 2>/dev/null || true(:129), which always exits 0. - The three steps that publish the config carry no
|| exitguard:cat > "$tmp"(:99),mv -f "$tmp" "$dst"(:122), and(cd "$parent" && sha256sum "$(basename "$dst")" > .config-hash)(:128). The anchor steps at:113-118do carry|| { echo …; exit 14; }guards, and thesqlite_backupbranch at:88joins with" && ", so unguarded steps in this branch are an omission, not the design. restoreStateFiletreats exit 0 as success (:189),restoreSandboxStateInternalthen reportssuccess: true(src/lib/state/sandbox.ts:2435), and the rebuild path prints✓ State restored (N directories, M files)(src/lib/actions/sandbox/rebuild-restore-phase.ts:243).- Reproduced in bash with the command the CLI generates: a blocked
.config-hashwrite and a config file that cannot be replaced both exit 0.
Description
nemoclaw rebuild, nemoclaw snapshot restore, and the sandbox recreation path in onboarding restore openclaw.json through restoreStateFile. agents/openclaw/manifest.yaml:110-112 declares openclaw.json with restore: merge: openclaw-config, so those flows always call buildStateFileRestoreCommand(dir, spec, true).
The generated shell script joins every step with ;. The script's exit status is therefore the status of its last step. On this path the last step is chmod 660 "$hash_file" 2>/dev/null || true, which cannot fail. Any failure in the steps that install the user's config is invisible to the caller.
openclaw.json holds the model and provider configuration, the MCP server list, custom agents, and the channel account blocks. When the publish fails, NemoClaw reports the restore as successful and the user keeps a sandbox with the previous or an absent configuration.
The > .config-hash redirect also truncates the OpenClaw integrity anchor before sha256sum runs. A failure after that point leaves a 0-byte .config-hash, so the reported-successful rebuild is followed by an agent whose integrity check no longer matches its own config.
Expected: a failed publish step ends the restore with a non-zero exit status, restoreStateFile returns false, and the sandbox rebuild reports the state file as failed.
Reproduction Steps
The defect is in the remote script, so the reproduction runs that script directly. restore.sh below is the exact string buildStateFileRestoreCommand(dir, { path: "openclaw.json", strategy: "copy" }, true) returns on main at 7d516f2ed, with its first step dst='<remote path>' replaced by dst="$1" so the path can be passed in.
-
Check out
mainat7d516f2ed. -
Write the generated command to a file:
cd "$(mktemp -d)" cat > restore.sh <<'CMD' dst="$1"; parent="$(dirname "$dst")"; [ ! -L "$parent" ] || { echo "refusing symlinked state parent: $parent" >&2; exit 10; }; [ ! -L "$dst" ] || { echo "refusing symlinked state target: $dst" >&2; exit 11; }; mkdir -p "$parent"; tmp="$(mktemp "${parent}/.nemoclaw-restore.XXXXXX")"; trap 'rm -f "$tmp" "${anchor_tmp:-}"' EXIT; cat > "$tmp"; chmod 660 "$tmp"; last_good="${dst}.last-good"; [ ! -L "$last_good" ] || { echo "refusing symlinked last-good target: $last_good" >&2; exit 13; }; anchor_tmp="$(mktemp "${parent}/.nemoclaw-lastgood.XXXXXX")" || { echo "failed to stage last-good anchor" >&2; exit 14; }; cat "$tmp" > "$anchor_tmp" || { echo "failed to write last-good anchor" >&2; exit 14; }; chmod 660 "$anchor_tmp" 2>/dev/null || true; mv -f "$anchor_tmp" "$last_good" || { echo "failed to install last-good anchor" >&2; exit 14; }; mv -f "$tmp" "$dst"; hash_file="${parent}/.config-hash"; [ ! -L "$hash_file" ] || { echo "refusing symlinked config hash target: $hash_file" >&2; exit 12; }; (cd "$parent" && sha256sum "$(basename "$dst")" > .config-hash); chmod 660 "$hash_file" 2>/dev/null || true CMD -
Block the config-hash write and run the restore:
mkdir -p state printf '{"model":"old"}\n' > state/openclaw.json mkdir state/.config-hash printf '{"model":"restored"}\n' | bash restore.sh "$PWD/state/openclaw.json" echo "exit=$?" -
Block the config replacement and run the restore:
rm -rf state && mkdir -p state/openclaw.json printf '{"model":"restored"}\n' | bash restore.sh "$PWD/state/openclaw.json" echo "exit=$?" wc -c state/.config-hash
Both steps print a failure on stderr and exit 0. In step 4 the restored config was never installed at openclaw.json, and .config-hash is 0 bytes.
Environment
- OS: macOS 26.5.1 (Darwin 25.5.0), Apple silicon
- Hardware: Apple silicon workstation
- Node.js: v26.7.0
- Docker: not required for this reproduction
- NemoClaw:
v0.0.109-151-g7d516f2ed(mainat7d516f2ed)
Debug Output
nemoclaw debug --quick does not cover this path. The defect is in the shell command NemoClaw sends over SSH, and the reproduction above runs that command directly. The command string is generated by src/lib/state/state-file-restore.ts:91-133 and is identical for every OpenClaw config restore:
$ # buildStateFileRestoreCommand("/home/sandbox/.openclaw", { path: "openclaw.json", strategy: "copy" }, true)
dst='/home/sandbox/.openclaw/openclaw.json'; parent="$(dirname "$dst")"; ...
...; mv -f "$tmp" "$dst"; hash_file="${parent}/.config-hash";
[ ! -L "$hash_file" ] || { echo "refusing symlinked config hash target: $hash_file" >&2; exit 12; };
(cd "$parent" && sha256sum "$(basename "$dst")" > .config-hash);
chmod 660 "$hash_file" 2>/dev/null || true
The last step is chmod … || true, so the script cannot report a non-zero status for any failure after the last guarded step.
Logs
Reproduction output on main at 7d516f2ed:
# step 3: the sandbox cannot write the config hash anchor
restore.sh: line 1: .config-hash: Is a directory
exit=0
# step 4: openclaw.json cannot be replaced
sha256sum: openclaw.json: Is a directory
exit=0
$ ls -l state
-rw-rw---- 0 .config-hash
drwxr-xr-x openclaw.json
-rw-rw---- 21 openclaw.json.last-good
$ wc -c state/.config-hash
0 state/.config-hash
For comparison, the same script reports the guarded failures correctly:
# state target is a symlink
refusing symlinked state target: .../state/openclaw.json
exit=11
# last-good anchor is a symlink
refusing symlinked last-good target: .../state/openclaw.json.last-good
exit=13
Checklist
- [x] I confirmed this bug is reproducible
- [x] I searched existing issues and this is not a duplicate