Skip to content

Add nemoclaw_clean.sh to free ports 8080 and 18789 before re-onboarding - #399

Closed
sayalinvidia wants to merge 2 commits into
NVIDIA:mainfrom
sayalinvidia:fix/port-cleanup-script
Closed

sayalinvidia wants to merge 2 commits into
NVIDIA:mainfrom
sayalinvidia:fix/port-cleanup-script

Conversation

@sayalinvidia

@sayalinvidia sayalinvidia commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #397

This adds a helper script nemoclaw_clean.sh to improve the DX when re-running
nemoclaw onboard on DGX Spark.

  • Kills any processes listening on ports 8080 and 18789
  • Stops OpenShell forwards that use port 18789

This addresses repeated onboarding failures caused by lingering OpenShell
gateway / ssh-proxy processes that keep those ports occupied.

Summary by CodeRabbit

  • New Features

    • Added a cleanup utility to terminate local services and clear stale forwarding sessions so onboarding can be retried reliably.
  • Documentation

    • Added "Re-running onboard" troubleshooting guidance and Known Issues entry explaining that gateway/dashboard can occupy ports 8080 and 18789 and instructing users to run the cleanup utility then retry onboarding.

@coderabbitai

coderabbitai Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds an executable Bash script (nemoclaw_clean.sh) that kills local processes listening on TCP ports 8080 and 18789 (via sudo lsof + sudo kill) and stops OpenShell forwards (parses openshell forward list and calls openshell forward stop for matching entries). Documentation is updated to recommend running this script when re-running nemoclaw onboard fails due to those ports being in use.

Changes

Cohort / File(s) Summary
Port cleanup script
nemoclaw_clean.sh
New executable script: set -e; finds PIDs listening on ports 8080, 18789 via sudo lsof -iTCP:<port> -sTCP:LISTEN -t and kills them with sudo kill; lists openshell forward entries (stderr suppressed) and stops forwards whose port equals 18789 using openshell forward stop <port> <sandbox> in a piped loop.
Docs — quick note
README.md
Added “Re-running onboard” troubleshooting note instructing users to run ./nemoclaw_clean.sh and retry nemoclaw onboard when ports 8080 or 18789 are occupied.
Docs — troubleshooting
docs/reference/troubleshooting.md
Expanded “Port already in use” guidance to cover both gateway and dashboard using ports 8080 and 18789; added Re-running onboard workflow pointing to ./nemoclaw_clean.sh then nemoclaw onboard; generalized manual cleanup text to “one of these ports.”
Docs — known issues
spark-install.md
Added Known Issue entry and a “Re-running onboard” section describing stale OpenShell gateway/forward causing ports 8080/18789 to be held and advising ./nemoclaw_clean.sh && nemoclaw onboard as the workaround.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hop through ports both dim and bright,
8080 and 18789 take flight.
A gentle kill, a forwarded stop,
Then onboard runs — no more deadlock! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately and concisely summarizes the main change: adding a nemoclaw_clean.sh script to free ports 8080 and 18789 before re-onboarding.
Linked Issues check ✅ Passed The PR fulfills issue #397's requirements by providing nemoclaw_clean.sh script that kills processes on ports 8080/18789 and stops OpenShell forwards, directly addressing the poor UX around gateway/ssh-proxy lifecycle cleanup.
Out of Scope Changes check ✅ Passed All changes are scoped to the cleanup objective: the script implementation, README guidance, and troubleshooting documentation updates are all directly relevant to resolving port conflicts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

Tip

CodeRabbit can suggest fixes for GitHub Check annotations.

Configure the reviews.tools.github-checks setting to adjust the time to wait for GitHub Checks to complete.

@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: 2

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

Inline comments:
In `@nemoclaw_clean.sh`:
- Line 2: Replace the current shell option "set -e" with a combination that
enables pipefail so failures in pipeline stages (e.g., the lsof pipeline and the
"openshell forward list" pipeline) are not ignored; specifically update the
options to "set -e -o pipefail" (or "set -eo pipefail") at the top of the script
to ensure any failing command in a pipeline causes the script to fail and
trigger cleanup handling.
- Around line 10-13: The forward-cleanup silently hides failures and assumes a
stable column layout; add an upfront check for openshell (e.g., command -v
openshell) and fail loudly if missing, remove the global stderr suppression
(delete 2>/dev/null) so errors from openshell propagate, capture the output of
openshell forward list into a variable, validate it is non-empty before parsing,
and then parse lines more defensively (replace awk 'NR>1 {print $1, $2}' with a
check that each line contains both port and sandbox before calling openshell
forward stop "$port" "$sandbox"); keep the existing conditional that only stops
port 18789 but log or exit if openshell forward list fails.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 40e25594-3371-4c0b-bdcb-f36c288f71c8

📥 Commits

Reviewing files that changed from the base of the PR and between 3ba517d and 5c7573f.

📒 Files selected for processing (1)
  • nemoclaw_clean.sh

Comment thread nemoclaw_clean.sh
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -e
echo "Checking shell safety flags and pipeline usage in nemoclaw_clean.sh"
rg -n '^\s*set\s+-' nemoclaw_clean.sh
rg -n '\|' nemoclaw_clean.sh

python - <<'PY'
from pathlib import Path
text = Path("nemoclaw_clean.sh").read_text()
print("has_pipeline:", "|" in text)
print("has_pipefail:", "pipefail" in text)
if "|" in text and "pipefail" not in text:
    print("Potential masked pipeline failures detected.")
PY

Repository: NVIDIA/NemoClaw

Length of output: 373


🏁 Script executed:

cat nemoclaw_clean.sh

Repository: NVIDIA/NemoClaw

Length of output: 452


Enable pipefail so cleanup failures aren't silently ignored.

At Line 2, set -e alone does not catch failures in earlier pipeline stages (used at Line 6 and Line 10). Without pipefail, if lsof or openshell forward list fails, the script continues silently, leaving ports/forwards potentially uncleaned.

Proposed fix
- set -e
+ set -euo pipefail
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set -e
set -euo pipefail
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nemoclaw_clean.sh` at line 2, Replace the current shell option "set -e" with
a combination that enables pipefail so failures in pipeline stages (e.g., the
lsof pipeline and the "openshell forward list" pipeline) are not ignored;
specifically update the options to "set -e -o pipefail" (or "set -eo pipefail")
at the top of the script to ensure any failing command in a pipeline causes the
script to fail and trigger cleanup handling.

Comment thread nemoclaw_clean.sh
Comment on lines +10 to +13
openshell forward list 2>/dev/null | awk 'NR>1 {print $1, $2}' | while read port sandbox; do
if [ "$port" = "18789" ]; then
openshell forward stop "$port" "$sandbox"
fi

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

For the OpenShell CLI docs: does openshell forward list support a machine-readable output mode (e.g., --json/--format), and is the default table column order guaranteed/stable?

💡 Result:

I couldn’t find any official/public “OpenShell CLI” documentation pages that mention the openshell forward list command at all (nor any --json / --format flag for it), so I can’t confirm a machine-readable output mode or any guarantee of a stable/default table column order from docs. The only “--json” CLI doc I found was for a different project (“OpenHands”), not “openshell forward list.” (docs.openhands.dev)

If you share the URL of the OpenShell CLI docs you’re looking at (or the openshell forward list --help output), I can answer definitively from that source.

Citations:


🏁 Script executed:

fd -t f "nemoclaw_clean.sh" -x wc -l {}

Repository: NVIDIA/NemoClaw

Length of output: 81


🏁 Script executed:

fd -t f "nemoclaw_clean.sh" -x cat -n {}

Repository: NVIDIA/NemoClaw

Length of output: 550


🏁 Script executed:

find . -type f -name "*.sh" | head -20

Repository: NVIDIA/NemoClaw

Length of output: 499


🏁 Script executed:

rg "openshell" -t sh --max-count 20

Repository: NVIDIA/NemoClaw

Length of output: 10287


Add upfront check for openshell availability; stop suppressing errors in forward cleanup.

At Line 10, 2>/dev/null hides failures (missing tool, auth issues, config problems), and the awk-based table parsing depends on undocumented column layout with no guaranteed stability. Unlike most other scripts in the repo (e.g., setup.sh, uninstall.sh), this code doesn't verify that openshell is installed before using it. This makes forward cleanup silently fail rather than report the problem.

Proposed fix
+if ! command -v openshell >/dev/null 2>&1; then
+  echo "openshell not found; skipping forward cleanup" >&2
+  exit 0
+fi
+
-openshell forward list 2>/dev/null | awk 'NR>1 {print $1, $2}' | while read port sandbox; do
+openshell forward list | awk 'NR>1 {print $1, $2}' | while read -r port sandbox; do
   if [ "$port" = "18789" ]; then
     openshell forward stop "$port" "$sandbox"
   fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
openshell forward list 2>/dev/null | awk 'NR>1 {print $1, $2}' | while read port sandbox; do
if [ "$port" = "18789" ]; then
openshell forward stop "$port" "$sandbox"
fi
if ! command -v openshell >/dev/null 2>&1; then
echo "openshell not found; skipping forward cleanup" >&2
exit 0
fi
openshell forward list | awk 'NR>1 {print $1, $2}' | while read -r port sandbox; do
if [ "$port" = "18789" ]; then
openshell forward stop "$port" "$sandbox"
fi
done
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nemoclaw_clean.sh` around lines 10 - 13, The forward-cleanup silently hides
failures and assumes a stable column layout; add an upfront check for openshell
(e.g., command -v openshell) and fail loudly if missing, remove the global
stderr suppression (delete 2>/dev/null) so errors from openshell propagate,
capture the output of openshell forward list into a variable, validate it is
non-empty before parsing, and then parse lines more defensively (replace awk
'NR>1 {print $1, $2}' with a check that each line contains both port and sandbox
before calling openshell forward stop "$port" "$sandbox"); keep the existing
conditional that only stops port 18789 but log or exit if openshell forward list
fails.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/reference/troubleshooting.md (1)

97-102: ⚠️ Potential issue | 🟡 Minor

Manual cleanup example is incomplete for dual-port conflicts.

Line 97 says conflicts can be on either port, but the example only checks Line 100 (18789). Add 8080 too, otherwise users can miss the actual blocker.

Suggested doc fix
 **Manual cleanup:** Otherwise, identify the conflicting process, verify it is safe to stop, and terminate it:

 ```console
-$ lsof -i :18789
+$ lsof -i :8080
+$ lsof -i :18789
 $ kill <PID>
</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @docs/reference/troubleshooting.md around lines 97 - 102, The "Manual
cleanup" example only checks port 18789 but the text states conflicts can be on
either port; update the example under the "Manual cleanup" block to run lsof for
both ports (add lsof -i :8080 before or alongside lsof -i :18789) so users can
discover the actual blocking process, then use kill for the matched PID;
refer to the "Manual cleanup" heading and the port numbers 8080 and 18789 when
making the change.


</details>

</blockquote></details>

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

Outside diff comments:
In `@docs/reference/troubleshooting.md`:
- Around line 97-102: The "Manual cleanup" example only checks port 18789 but
the text states conflicts can be on either port; update the example under the
"Manual cleanup" block to run lsof for both ports (add lsof -i :8080 before or
alongside lsof -i :18789) so users can discover the actual blocking process,
then use kill <PID> for the matched PID; refer to the "Manual cleanup" heading
and the port numbers 8080 and 18789 when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8e962d68-a87c-497b-ae7b-b04fed43075c

📥 Commits

Reviewing files that changed from the base of the PR and between 5c7573f and 069f37e.

📒 Files selected for processing (3)
  • README.md
  • docs/reference/troubleshooting.md
  • spark-install.md
✅ Files skipped from review due to trivial changes (2)
  • README.md
  • spark-install.md

@kjw3

kjw3 commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for putting this together and for pushing on a real usability problem. The Spark re-onboard failure mode is worth fixing, and I appreciate the effort to give users a concrete recovery path.

I reviewed this against current main, and the main reason I'm closing the PR is that I don't think a separate cleanup script is the right layer for the fix anymore. NemoClaw already has product-level lifecycle cleanup in the onboarding flow, including stale-session cleanup before port checks and additional gateway/forward cleanup in bin/lib/onboard.js.

Because of that, this PR doesn't appear to add a needed core fix on top of main. Instead, it introduces a broad host-side cleanup script that:

  • kills whatever is listening on ports 8080 and 18789, even if those processes are not owned by NemoClaw/OpenShell
  • requires sudo and manual repo-root intervention
  • works around the symptom instead of tightening the lifecycle behavior in product code

So the closure here is about fix direction, not about the problem statement. If there is still a reproducible Spark issue on current main, I think the best next step would be to capture that repro and patch the remaining lifecycle gap directly in onboard rather than shipping nemoclaw_clean.sh as the supported path.

Appreciate the contribution and the issue write-up. If you want to take another pass in that direction, I’d be happy to re-review it.

@kjw3 kjw3 closed this Mar 19, 2026
mafueee pushed a commit to mafueee/NemoClaw that referenced this pull request Mar 28, 2026
@wscurran wscurran added feature PR adds or expands user-visible functionality platform: dgx-spark Affects DGX Spark hardware or workflows and removed Platform: DGX Spark labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature PR adds or expands user-visible functionality platform: dgx-spark Affects DGX Spark hardware or workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nemoclaw onboard fails with port 8080/18789 conflicts after prior run, even on “fresh” DGX Spark – poor UX around gateway / ssh‑proxy lifecycle

3 participants