feat(cli): add nemoclaw reconnect command for post-reboot recovery
Description
After a host reboot, users must manually run multiple commands to reconnect to their sandbox: start Docker, restart the OpenShell gateway, check sandbox state, then connect. This is documented in the troubleshooting guide but could be a single command.
A nemoclaw reconnect command would automate the recovery sequence:
- Verify the container runtime is running
- Start the OpenShell gateway if it's not running (
openshell gateway start --name nemoclaw) - Wait for the gateway to become healthy
- Check sandbox state (
openshell sandbox list) - Start port forward and connect to the default (or named) sandbox
Context
- Issue #469 requested documentation for reconnecting after a reboot — addressed by the docs PR
- PR #904 (by @WuKongAI-CMU) also attempted to document this but was closed due to PR limit
- The building blocks already exist in the codebase:
sandboxConnect()inbin/nemoclaw.jshandles port forwarding and connectionbin/lib/onboard.jshas gateway start, health check, and CoreDNS fix logicregistry.listSandboxes()provides the default sandbox name
Open questions
- Does
openshell gateway start --name nemoclawwork correctly when the gateway container exists but is stopped? Or does it require a destroy/recreate cycle? - Is the CoreDNS fix needed again after a reboot, or only on first setup?
- Should this be a new
nemoclaw reconnectcommand, or shouldnemoclaw <name> connectbe smarter about detecting and recovering from a stopped gateway?
Suggested implementation
async function reconnect(sandboxName) {
// 1. Check gateway
const gwInfo = runCaptureOpenshell(["gateway", "info", "-g", "nemoclaw"], { ignoreError: true });
if (!gwInfo || !gwInfo.includes("Running")) {
console.log(" Starting OpenShell gateway...");
runOpenshell(["gateway", "start", "--name", "nemoclaw"]);
// wait for health
}
// 2. Find sandbox
const name = sandboxName || registry.listSandboxes().defaultSandbox;
if (!name) {
console.error(" No sandbox registered. Run `nemoclaw onboard` first.");
process.exit(1);
}
// 3. Connect
sandboxConnect(name);
}
Related
- #469 — original user request for reboot recovery docs
- PR #904 — previous docs-only attempt (closed, PR limit)
Opened PR #960 to add a global nemoclaw reconnect [name] command that reuses the existing gateway recovery and sandbox connect path for post-reboot recovery.
Full post-reboot recovery script + systemd auto-start on WSL2
Until a nemoclaw reconnect command exists, here's a complete startup script we use that handles the full recovery sequence automatically on every boot.
~/start-all.sh — handles:
- Waits for Docker + OpenShell gateway to be ready (retry loop, up to 5 min)
- Starts the sandbox if not running
- Waits for sandbox to reach Ready state (retry loop, up to 3 min)
- Clears stale session lock files
- Re-sets the inference provider (survives sandbox recreates)
- Restores custom files (skills, env, model config) via SSH
- Starts bridge processes via pm2
#!/usr/bin/env bash
set -uo pipefail
source "$HOME/.nemoclaw_env"
SANDBOX="${SANDBOX_NAME:-my-assistant}"
# Wait for Docker + OpenShell gateway
for i in $(seq 1 30); do
if openshell gateway status 2>/dev/null | grep -qiE "running|ready|ok"; then break; fi
if docker info >/dev/null 2>&1; then break; fi
echo "($i/30) Docker not ready — waiting 10s..."
sleep 10
done
# Start sandbox if not running
nemoclaw status --json 2>/dev/null | grep -q '"running":true' || nemoclaw start 2>/dev/null &
# Wait for sandbox ready
for i in $(seq 1 36); do
nemoclaw status --json 2>/dev/null | grep -q '"running":true' && break
echo "($i/36) Sandbox not ready — waiting 5s..."
sleep 5
done
# Clear stale lock files
SSH_CONF=$(mktemp); openshell sandbox ssh-config "$SANDBOX" > "$SSH_CONF"
ssh -T -F "$SSH_CONF" "openshell-${SANDBOX}" \
'find /sandbox/.openclaw-data -name "*.lock" -delete 2>/dev/null'
rm -f "$SSH_CONF"
# Re-set inference
openshell inference set --provider your-provider --model your-model --no-verify 2>/dev/null || true
# Start bridges
pm2 start ecosystem.config.js
pm2 save
Auto-start on WSL boot via systemd user service (~/.config/systemd/user/nemoclaw.service):
[Unit]
Description=NemoClaw AI Assistant
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/%u/start-all.sh
TimeoutStartSec=600
[Install]
WantedBy=default.target
Enable with:
systemctl --user enable nemoclaw.service
loginctl enable-linger $USER
This gives full hands-off recovery after every reboot — no manual steps needed.
Closing as resolved via a different approach. The top-level nemoclaw reconnect command proposed here was explicitly considered and rejected in PR #960 (closed unmerged 2026-03-31). Instead, PR #1187 (merged same day) placed recovery directly on the nemoclaw <name> connect path.
What #1187 ships: when local registry state is missing or stale, nemoclaw <name> connect automatically probes openshell sandbox list, re-registers any live sandboxes it finds, clears stale SSH host keys on identity drift, and falls into connect — no separate command needed. Adjacent fixes #1466, #1087, #2064, and #1025 cover sandbox survival across gateway restarts, SSH key cleanup, identity drift, and proxy env persistence respectively.
Verified locally today: wiping the local registry entry for a sandbox and running nemoclaw <sandbox> connect triggered the live gateway probe, re-registered a running sandbox automatically, and returned the correct error for one that wasn't live. The recovery mechanism from #1187 addresses the scenario this issue described.