[MacOS] Gateway destroy kills sandbox session with Broken pipe instead of graceful error
Description
Test Plan https://docs.google.com/document/d/14bIihtww1Jtzz9eU-FdmFixKRFO9WI_OuGw9yrEP9Cw/edit?pli=1&tab=t.0 4.4 - test case 4
When the OpenShell gateway is destroyed while a sandbox session is active, the sandbox connection is abruptly terminated with a Broken pipe error and exit code 255. The user receives no graceful error message indicating the gateway is restarting, and there is no automatic recovery once the gateway comes back. Active inference requests that were in-flight complete successfully, but subsequent requests and the sandbox session itself are killed without warning.
Steps to reproduce
- Complete
nemoclaw setupsuccessfully - Set inference route:
openshell inference set --provider ollama-local --model llama3.2:1b - Connect to sandbox in Terminal 1:
nemoclaw connect - Start a looping inference request inside the sandbox:
for i in $(seq 1 20); do echo --- Request $i at $(date +%H:%M:%S) --- curl -s -m 5 https://inference.local/v1/chat/completions \ -H Content-Type: application/json \ -d '{ model : llama3.2:1b , messages :[{ role : user , content : say hi }]}' \ | head -c 120 echo sleep 2 done - In Terminal 2 (host), destroy and restart the gateway:
export DOCKER_HOST= unix://$HOME/.colima/default/docker.sock openshell gateway destroy -g nemoclaw && openshell gateway start --name nemoclaw
- No graceful error message was shown inside the sandbox
- No automatic recovery.
Steps to reproduce
No steps provided.
[NVB# 5982642]
[NVB#5982642]
✨ Possibly related open PRs:
Architectural Context — Active Session Detection
Picking this up as part of a broader onboard.ts decomposition effort.
The fix for this bug, done right, creates reusable infrastructure that improves destroy, rebuild, stop, status, list, connect, and uninstall. The core issue isn't just the Broken pipe UX — it's that no destructive operation in the CLI checks for active SSH sessions before proceeding.
Proposed approach
Create a shared sandbox-session-state.ts module with an getActiveSandboxSessions(sandboxName) utility that detects active SSH connections (via openshell forward list output and/or process detection). This module would be consumed by:
| Consumer | File | Behavior |
|---|---|---|
sandboxDestroy() |
nemoclaw.ts | Warn: "⚠️ Active SSH session detected. Destroy anyway?" |
sandboxRebuild() |
nemoclaw.ts | Same warning pattern |
cleanupGatewayAfterLastSandbox() |
nemoclaw.ts | Check before automatic cleanup |
destroyGateway() |
onboard.ts | Graceful disconnect before teardown |
stopAll() |
services.ts | Warn about active sessions before stopping |
sandboxStatus() |
nemoclaw.ts | Show "Connected: yes" in status output |
nemoclaw list |
nemoclaw.ts | Show active indicator next to connected sandboxes |
sandboxConnect() |
nemoclaw.ts | Warn "Already connected in another terminal" |
This earns its place in the refactoring plan not because the destroy function itself needs extraction from onboard.ts, but because the solution creates a new typed, testable shared module that addresses a cross-cutting concern across 9 call sites in 4 files — exactly the architectural pattern we're driving toward.
Verified this issue on Nemoclaw v0.0.30, this is now resolved. Closing the bughttps://nvbugspro.nvidia.com/bug/5982642