Skip to content

fix: clean up Docker volumes after failed gateway start - #337

Merged
cv merged 10 commits into
mainfrom
fix/issue-17-gateway-volume-cleanup
Mar 26, 2026
Merged

cv merged 10 commits into
mainfrom
fix/issue-17-gateway-volume-cleanup

Conversation

@ericksoa

@ericksoa ericksoa commented Mar 18, 2026 •

Copy link
Copy Markdown
Member

Closes #17.

Summary

  • Extract destroyGateway() helper that removes both the gateway and its Docker volumes (openshell-cluster-nemoclaw)
  • Call it pre-start (existing cleanup), on start failure (new), and on health check failure (new)
  • Add volume cleanup to uninstall.sh and scripts/setup.sh
  • Add 4 regression tests to CI

Problem

When openshell gateway start fails, it leaves behind a Docker volume (openshell-cluster-nemoclaw) in a corrupted state. openshell gateway destroy doesn't remove volumes. Rerunning onboard hits "Corrupted cluster state" with no guidance — users must manually run docker volume rm openshell-cluster-nemoclaw.

Fix

destroyGateway() calls openshell gateway destroy then removes matching Docker volumes via docker volume ls -q --filter "name=openshell-cluster-nemoclaw" | xargs -r docker volume rm. On failure, it prints "Stale state removed. Please rerun: nemoclaw onboard".

Test plan

  • 56/56 unit tests pass (52 existing + 4 new gateway cleanup regression tests)
  • Simulated corrupted volume: onboard cleans it up automatically, no "Corrupted cluster state"
  • Gateway start failure: volumes cleaned up before exit
  • Health check failure: volumes cleaned up before exit
  • uninstall.sh: volume cleanup works
  • Code review: all three files have volume cleanup on all failure paths

Summary by CodeRabbit

  • Bug Fixes
    • Improved gateway initialization to properly clean up stale state, including Docker volumes, that could prevent successful setup.
    • Enhanced error handling during gateway startup to ensure cleanup is performed on failures.
    • Standardized error messaging with clear guidance to retry when setup encounters issues.

Closes #17.

When openshell gateway start fails, it leaves behind a Docker volume
(openshell-cluster-nemoclaw) in a corrupted state. Rerunning onboard
hits "Corrupted cluster state" because openshell gateway destroy
doesn't remove the volume.

Extracts a destroyGateway() helper that removes both the gateway and
its Docker volumes. Called before start (pre-cleanup), after start
failure, and after health check failure. Adds the same volume cleanup
to uninstall.sh and scripts/setup.sh.
Static analysis tests that verify Docker volume cleanup exists in
all three code paths (onboard.js, uninstall.sh, setup.sh) and that
destroyGateway() is called on pre-start, start failure, and health
check failure. Will catch regressions in CI.

Refs: #17
@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Introduces destroyGateway() helper function in bin/lib/onboard.js that destroys OpenShell gateway and removes Docker volumes. Updates gateway startup and health-check error paths to call this helper. Adds Docker volume cleanup to scripts/setup.sh failure paths. Includes test file validating cleanup patterns.

Changes

Cohort / File(s) Summary
Gateway Cleanup Helper
bin/lib/onboard.js
Adds destroyGateway() helper that destroys gateway and removes matching Docker volumes. Updates startGateway() to call helper on startup errors and health-check failures, with standardized "Stale state removed. Please rerun: nemoclaw onboard" message instead of previous logging.
Setup Script Error Handling
scripts/setup.sh
Converts gateway startup and health-check failure paths to call cleanup (gateway destroy + Docker volume removal) before failing. Adds fail message with rerun instruction instead of generic error messages.
Cleanup Validation Test
test/gateway-cleanup.test.js
New Vitest file that validates Docker volume cleanup presence by pattern-matching: destroyGateway() calls in onboard.js (3+ occurrences), Docker volume references in onboard.js and setup.sh, and cleanup function in uninstall.sh.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A gateway's gone, no trace remains,
Docker volumes cleared of stains,
When startup fails, we clean and reset,
Rerun again—no manual fret!
Fresh starts await our carrots bright. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the primary change: fixing Docker volume cleanup after failed gateway start, which is the core objective.
Linked Issues check ✅ Passed All acceptance criteria from issue #17 are met: automatic Docker volume cleanup on failed gateway start [#17], cleanup prevents corrupted cluster state [#17], clear error message on failure [#17], and regression tests added [#17].
Out of Scope Changes check ✅ Passed All changes are directly related to issue #17: Docker volume cleanup on gateway failure in onboard.js, setup.sh, uninstall.sh, and test coverage—no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-17-gateway-volume-cleanup

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bin/lib/onboard.js`:
- Around line 125-130: The destroyGateway function currently calls run(...) with
xargs -r (GNU-only) and swallows all errors via { ignoreError: true } and ||
true; remove the -r flag so xargs is portable on BSD/macOS, and change
destroyGateway (and its two run invocations that reference GATEWAY_NAME) to
propagate success/failure (e.g., return boolean or throw) instead of always
ignoring errors so callers can detect cleanup failures and show the manual
recovery command; update call sites that assume cleanup always succeeded to
check destroyGateway's result and display the manual docker volume rm
instruction when it fails.

In `@scripts/setup.sh`:
- Around line 77-97: The script uses the GNU-only xargs -r flag in the docker
volume removal pipelines (the commands that start with "docker volume ls -q
--filter \"name=openshell-cluster-nemoclaw\" | xargs -r docker volume rm ...")
which breaks on macOS/BSD; remove the -r flag so the pipeline becomes portable,
keeping the surrounding stderr redirection and the existing cleanup flow that
calls openshell gateway destroy -g nemoclaw, docker volume rm, warn and fail
unchanged to preserve behavior when cleanup is needed.
- Around line 80-85: The current check uses the exit of grep on the piped output
to decide success; instead run the openshell gateway start command and capture
both its exit code and output (e.g., capture output into a variable or tee it to
a temp log), then use the actual exit code of openshell (saved into a variable
like start_status or via PIPESTATUS[0]) to decide whether to run the cleanup;
you may still grep the captured output for logging/diagnostics but ensure the
cleanup block (the openshell gateway destroy and docker volume rm calls) is
executed only when the openshell gateway start exit status indicates failure.

In `@test/gateway-cleanup.test.js`:
- Around line 17-62: Tests only check source text and call counts; add an
integration-style test that actually exercises a failed gateway
start/health-check and asserts the cleanup command runs. Create a new test that
launches the real onboarding process (bin/lib/onboard.js or the bin script) via
child_process.spawn or fork with an env var that forces startGateway to fail (or
put a fake docker binary early in PATH that records invocations), wait for the
failure path, and then assert that destroyGateway was invoked by checking
captured stdout/stderr for the docker volume removal command (or that the fake
docker binary was called with "volume rm openshell-cluster") and/or that
remove_related_docker_volumes / uninstall.sh cleanup logic was executed;
reference startGateway, destroyGateway, remove_related_docker_volumes,
onboard.js, uninstall.sh, and scripts/setup.sh so the test locates and exercises
the real cleanup code rather than just matching strings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4efde2a0-67a9-4d4b-bfca-02f5d15477fe

📥 Commits

Reviewing files that changed from the base of the PR and between 241ffb2 and b1f1b4d.

📒 Files selected for processing (4)
  • bin/lib/onboard.js
  • scripts/setup.sh
  • test/gateway-cleanup.test.js
  • uninstall.sh

Comment thread bin/lib/onboard.js Resolved
Comment thread scripts/setup.sh Resolved
Comment thread scripts/setup.sh Resolved
Comment thread test/gateway-cleanup.test.js Resolved

@cv cv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean fix for the corrupted volume problem. destroyGateway() extracts the cleanup well, all failure paths covered, and the regression tests verify it.

@cv cv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent fix across all three code paths, tests verify the right invariants.

xargs -r is not portable to macOS

The volume cleanup command uses xargs -r (GNU extension — don't run if stdin is empty). macOS xargs doesn't support -r. On macOS with no matching volumes, xargs will call docker volume rm with no arguments, which prints a usage error. Harmless due to || true, but noisy. This applies to onboard.js, setup.sh, and uninstall.sh — all three run on macOS.

Options: pipe through grep . first, use an if guard, or use xargs without -r and accept the usage noise (already suppressed by 2>/dev/null || true).

Minor: possible double-cleanup in uninstall.sh

The new explicit calls to remove_related_docker_containers, remove_related_docker_volumes, and remove_related_docker_images (lines 570-578) run immediately after remove_docker_resources (line 568). If remove_docker_resources already handles some of these, this results in redundant cleanup attempts. Not harmful, but worth verifying there's no overlap.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
scripts/setup.sh (2)

115-120: ⚠️ Potential issue | 🟠 Major

Gate cleanup on openshell gateway start exit status, not grep match.

Line 115 currently ties failure handling to grep output. With set -o pipefail, a successful start can still enter cleanup if output stops matching "Gateway|✓|Error|error".

Suggested patch
-if ! openshell gateway start "${GATEWAY_ARGS[@]}" 2>&1 | grep -E "Gateway|✓|Error|error"; then
+set +e
+START_OUTPUT="$(openshell gateway start "${GATEWAY_ARGS[@]}" 2>&1)"
+START_RC=$?
+set -e
+printf '%s\n' "$START_OUTPUT" | grep -E "Gateway|✓|Error|error" || true
+if [ "$START_RC" -ne 0 ]; then
   warn "Gateway start failed. Cleaning up stale state..."
   openshell gateway destroy -g nemoclaw >/dev/null 2>&1 || true
-  docker volume ls -q --filter "name=openshell-cluster-nemoclaw" | xargs -r docker volume rm 2>/dev/null || true
+  docker volume ls -q --filter "name=openshell-cluster-nemoclaw" | xargs docker volume rm 2>/dev/null || true
   fail "Stale state removed. Please rerun: nemoclaw onboard"
 fi
#!/usr/bin/env bash
set -euo pipefail

echo "Case 1: command succeeds, grep misses => currently treated as failure"
if ! (echo "Starting gateway..." && exit 0) 2>&1 | grep -E "Gateway|✓|Error|error"; then
  echo "cleanup branch entered"
else
  echo "no cleanup"
fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/setup.sh` around lines 115 - 120, The cleanup branch currently
triggers based on the grep match rather than the actual exit status of the
starts command; change the logic so you run openshell gateway start
"${GATEWAY_ARGS[@]}" and check its exit code (e.g., if ! openshell gateway start
...; then cleanup) instead of relying on the pipe to grep for
"Gateway|✓|Error|error". If you still need to inspect stdout/stderr for error
patterns, capture the command output into a variable (or a temp file), examine
that with grep to log or decide additional actions, but always use the process
exit status of openshell gateway start as the primary condition for running the
cleanup steps that reference openshell gateway destroy and docker volume rm.

112-112: ⚠️ Potential issue | 🟠 Major

Use portable xargs invocation for volume cleanup.

Line 112, Line 118, and Line 130 use GNU-only xargs -r. On macOS/BSD this can fail silently here (stderr redirected + || true), leaving stale volumes behind.

Suggested patch
-docker volume ls -q --filter "name=openshell-cluster-nemoclaw" | xargs -r docker volume rm 2>/dev/null || true
+docker volume ls -q --filter "name=openshell-cluster-nemoclaw" | xargs docker volume rm 2>/dev/null || true
Is `xargs -r` supported on macOS/BSD `xargs`, and is removing `-r` the portable fix when input may be empty?

Also applies to: 118-118, 130-130

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/setup.sh` at line 112, The xargs -r usage in the docker volume
cleanup commands (the lines invoking "docker volume ls -q --filter
\"name=openshell-cluster-nemoclaw\" | xargs -r docker volume rm") is GNU-only
and not portable to macOS/BSD; replace the pipeline with a portability-safe
check: capture the output of docker volume ls -q --filter "...", test if it's
non-empty (e.g. ids="$(docker volume ls -q --filter 'name=...')" and if [ -n
"$ids" ]; then echo "$ids" | xargs docker volume rm; fi) for each occurrence
(the three lines that currently use xargs -r) so you avoid relying on -r and
don't attempt to remove when there are no volumes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/setup.sh`:
- Around line 117-119: The script currently runs best-effort cleanup commands
(openshell gateway destroy, docker volume rm via docker volume ls | xargs) with
"|| true" then unconditionally calls fail("Stale state removed. Please rerun:
nemoclaw onboard"), which falsely claims success; update the cleanup blocks
around the openshell gateway destroy / docker volume ls | xargs sequences and
the duplicate block later (same pattern) to detect failures instead of
swallowing them: capture each command's exit status (or run them without "||
true"), aggregate any failures, and only emit a success message if all cleanup
steps succeeded — otherwise print a clear "Attempted to remove stale state;
manual recovery steps:" message listing the exact commands that failed (or the
full commands to run manually) and avoid calling fail with the misleading "Stale
state removed..." text.

---

Duplicate comments:
In `@scripts/setup.sh`:
- Around line 115-120: The cleanup branch currently triggers based on the grep
match rather than the actual exit status of the starts command; change the logic
so you run openshell gateway start "${GATEWAY_ARGS[@]}" and check its exit code
(e.g., if ! openshell gateway start ...; then cleanup) instead of relying on the
pipe to grep for "Gateway|✓|Error|error". If you still need to inspect
stdout/stderr for error patterns, capture the command output into a variable (or
a temp file), examine that with grep to log or decide additional actions, but
always use the process exit status of openshell gateway start as the primary
condition for running the cleanup steps that reference openshell gateway destroy
and docker volume rm.
- Line 112: The xargs -r usage in the docker volume cleanup commands (the lines
invoking "docker volume ls -q --filter \"name=openshell-cluster-nemoclaw\" |
xargs -r docker volume rm") is GNU-only and not portable to macOS/BSD; replace
the pipeline with a portability-safe check: capture the output of docker volume
ls -q --filter "...", test if it's non-empty (e.g. ids="$(docker volume ls -q
--filter 'name=...')" and if [ -n "$ids" ]; then echo "$ids" | xargs docker
volume rm; fi) for each occurrence (the three lines that currently use xargs -r)
so you avoid relying on -r and don't attempt to remove when there are no
volumes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3aa03a49-975d-4e56-826f-886a576f758b

📥 Commits

Reviewing files that changed from the base of the PR and between b1f1b4d and 12bc293.

📒 Files selected for processing (3)
  • bin/lib/onboard.js
  • scripts/setup.sh
  • uninstall.sh
🚧 Files skipped from review as they are similar to previous changes (2)
  • uninstall.sh
  • bin/lib/onboard.js

Comment thread scripts/setup.sh Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/gateway-cleanup.test.js (1)

17-22: Assertion is weak—strings could appear anywhere in the file.

The test passes if "docker volume" and "openshell-cluster" appear anywhere in onboard.js, not necessarily within destroyGateway(). Consider tightening the assertion to match within the actual function body.

♻️ Suggested improvement
   it("onboard.js: destroyGateway() removes Docker volumes", () => {
     const content = fs.readFileSync(path.join(ROOT, "bin/lib/onboard.js"), "utf-8");
-    expect(
-      content.includes("docker volume") && content.includes("openshell-cluster"),
-    ).toBe(true);
+    // Extract destroyGateway function and verify volume cleanup is inside it
+    const destroyGwMatch = content.match(/(?:async\s+)?function\s+destroyGateway[\s\S]*?^}/m);
+    expect(destroyGwMatch).toBeTruthy();
+    expect(destroyGwMatch[0]).toMatch(/docker volume/);
+    expect(destroyGwMatch[0]).toMatch(/openshell-cluster/);
   });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/gateway-cleanup.test.js` around lines 17 - 22, The current test checks
for literal strings anywhere in the file which is too broad; update the test in
gateway-cleanup.test.js to assert those strings appear inside the destroyGateway
function body specifically by extracting that function (e.g., locate the
function declaration/assignment for destroyGateway and capture its source via a
regex or an AST parse) and then assert the captured body contains "docker
volume" and "openshell-cluster"; ensure the test fails if the function body does
not include both strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/gateway-cleanup.test.js`:
- Around line 24-36: The regex used to extract the async function startGateway
is brittle and can stop at the first unindented closing brace, truncating the
function and missing destroyGateway() calls; replace the regex with a more
robust parser approach (or a balanced-brace search) to reliably capture the
entire startGateway function body when scanning onboard.js, then recount
destroyGateway() occurrences inside that full body; also avoid reading
onboard.js twice by reusing the previously read content variable (content)
instead of calling fs.readFileSync a second time.

---

Nitpick comments:
In `@test/gateway-cleanup.test.js`:
- Around line 17-22: The current test checks for literal strings anywhere in the
file which is too broad; update the test in gateway-cleanup.test.js to assert
those strings appear inside the destroyGateway function body specifically by
extracting that function (e.g., locate the function declaration/assignment for
destroyGateway and capture its source via a regex or an AST parse) and then
assert the captured body contains "docker volume" and "openshell-cluster";
ensure the test fails if the function body does not include both strings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e48ef391-c346-438c-a8b6-6b90f1b1a31c

📥 Commits

Reviewing files that changed from the base of the PR and between c6548fb and 5e4a1b6.

📒 Files selected for processing (1)
  • test/gateway-cleanup.test.js

Comment thread test/gateway-cleanup.test.js Resolved
Merge origin/main and resolve conflicts in bin/lib/onboard.js.
Replace xargs -r (GNU-only) with a macOS-compatible pattern that
guards against empty stdin: grep . && ... | xargs docker volume rm.
Remove duplicate remove_related_docker_volumes definition and calls
from uninstall.sh that conflicted with main's implementation.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (2)
bin/lib/onboard.js (2)

1346-1350: ⚠️ Potential issue | 🟡 Minor

Same concern as gateway start failure path.

This health-check failure branch also prints "Stale state removed" unconditionally. The same fix (checking cleanup success or showing the manual recovery command) applies here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/lib/onboard.js` around lines 1346 - 1350, The health-check failure branch
unconditionally prints "Stale state removed" after calling destroyGateway();
change it to check the result or catch errors from destroyGateway (or inspect a
boolean/throwing behavior) and only print "Stale state removed. Please rerun:
nemoclaw onboard" when cleanup actually succeeded; if destroyGateway fails, log
the error and instead print a clear manual recovery command (e.g., rerun or
specific cleanup instructions). Locate the block using the variables i (equal to
4) and the function destroyGateway to implement a try/catch or conditional
around the cleanup and adjust the console.error messages accordingly.

1331-1337: ⚠️ Potential issue | 🟡 Minor

Unconditional "Stale state removed" message may mislead users if cleanup fails.

Since destroyGateway() suppresses errors and returns void, line 1335 claims cleanup succeeded even when it may not have. If Docker volumes couldn't be removed (e.g., in use by another process), the user will retry and encounter the same "Corrupted cluster state" error.

Per the PR's acceptance criteria: "If automatic cleanup cannot be performed, the error message must include the exact recovery command."

Consider having destroyGateway() return a boolean or checking for remaining volumes, then conditionally printing the manual command:

docker volume rm openshell-cluster-nemoclaw
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bin/lib/onboard.js` around lines 1331 - 1337, The cleanup message is
unconditional even though destroyGateway() currently suppresses errors; change
destroyGateway() to return a success boolean (or throw on failure) and update
the startup error path that uses startResult to check that return value (or
catch the thrown error) before printing "Stale state removed"; if
destroyGateway() reports failure, print a clear recovery instruction including
the exact docker command (e.g., docker volume rm openshell-cluster-nemoclaw) and
any relevant guidance, otherwise print the success message and exit as before —
update references in this block that call destroyGateway(), runOpenshell,
startResult, and gatewayEnv accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@bin/lib/onboard.js`:
- Around line 1346-1350: The health-check failure branch unconditionally prints
"Stale state removed" after calling destroyGateway(); change it to check the
result or catch errors from destroyGateway (or inspect a boolean/throwing
behavior) and only print "Stale state removed. Please rerun: nemoclaw onboard"
when cleanup actually succeeded; if destroyGateway fails, log the error and
instead print a clear manual recovery command (e.g., rerun or specific cleanup
instructions). Locate the block using the variables i (equal to 4) and the
function destroyGateway to implement a try/catch or conditional around the
cleanup and adjust the console.error messages accordingly.
- Around line 1331-1337: The cleanup message is unconditional even though
destroyGateway() currently suppresses errors; change destroyGateway() to return
a success boolean (or throw on failure) and update the startup error path that
uses startResult to check that return value (or catch the thrown error) before
printing "Stale state removed"; if destroyGateway() reports failure, print a
clear recovery instruction including the exact docker command (e.g., docker
volume rm openshell-cluster-nemoclaw) and any relevant guidance, otherwise print
the success message and exit as before — update references in this block that
call destroyGateway(), runOpenshell, startResult, and gatewayEnv accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a9403e57-95b6-40d6-a526-f3b6d5a4c470

📥 Commits

Reviewing files that changed from the base of the PR and between 5e4a1b6 and 72618bf.

📒 Files selected for processing (2)
  • bin/lib/onboard.js
  • scripts/setup.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/setup.sh

The e2e gateway isolation test used head -21 to source the PATH export
from nemoclaw-start.sh. The capsh fix (#929) added lines, pushing PATH
past line 21. Use grep to find the export line dynamically.
@cv
cv merged commit 1e1243d into main Mar 26, 2026
6 checks passed
@cv
cv deleted the fix/issue-17-gateway-volume-cleanup branch March 26, 2026 00:14
lakamsani pushed a commit to lakamsani/NemoClaw that referenced this pull request Apr 4, 2026
* fix: clean up Docker volumes after failed gateway start

Closes NVIDIA#17.

When openshell gateway start fails, it leaves behind a Docker volume
(openshell-cluster-nemoclaw) in a corrupted state. Rerunning onboard
hits "Corrupted cluster state" because openshell gateway destroy
doesn't remove the volume.

Extracts a destroyGateway() helper that removes both the gateway and
its Docker volumes. Called before start (pre-cleanup), after start
failure, and after health check failure. Adds the same volume cleanup
to uninstall.sh and scripts/setup.sh.

* test: add regression tests for gateway volume cleanup

Static analysis tests that verify Docker volume cleanup exists in
all three code paths (onboard.js, uninstall.sh, setup.sh) and that
destroyGateway() is called on pre-start, start failure, and health
check failure. Will catch regressions in CI.

Refs: NVIDIA#17

* fix: convert assert.ok to vitest expect in policies.test.js

* fix: convert node:test to vitest in gateway-cleanup.test.js

* fix(test): use grep instead of hardcoded line count for PATH check

The e2e gateway isolation test used head -21 to source the PATH export
from nemoclaw-start.sh. The capsh fix (NVIDIA#929) added lines, pushing PATH
past line 21. Use grep to find the export line dynamically.

---------

Co-authored-by: Carlos Villela <[email protected]>
@wscurran wscurran added area: packaging Packages, images, registries, installers, or distribution platform: container Affects Docker, containerd, Podman, or images and removed area: packaging Packages, images, registries, installers, or distribution Docker labels Jun 3, 2026
@wscurran wscurran added the bug-fix PR fixes a bug or regression label Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression platform: container Affects Docker, containerd, Podman, or images

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure failed gateway startup is fully cleaned up so reruns do not require manual Docker volume deletion

3 participants