fix(forward): stop default-port forward when custom dashboard port is set#2073
fix(forward): stop default-port forward when custom dashboard port is set#2073Sanjays2402 wants to merge 3 commits intoNVIDIA:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA port constant is exported to enable consistent usage across the codebase, and a regression test is added to validate that dashboard cleanup logic derives the forward-stop port from the shared exported constant rather than a hardcoded value. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Review rate limit: 9/10 reviews remaining, refill in 6 minutes. Comment |
|
✨ Thanks for submitting this PR that proposes a fix for the default-port forward when a custom dashboard port is set, which could help improve the reliability of the dashboard forwarding. Possibly related open issues: |
|
Hi @Sanjays2402 !
|
… set When NEMOCLAW_DASHBOARD_PORT is set to a non-default value, openshell sandbox create may auto-forward the default port 18789 in addition to the custom port. ensureDashboardForward only stopped the custom port before re-creating it, leaving the stale default-port forward running. Now, when the resolved port differs from the hardcoded default (18789), we explicitly stop the default-port forward first. Fixes NVIDIA#2007 Signed-off-by: Sanjays2402 <[email protected]>
Per maintainer feedback on NVIDIA#2073: - Export SANDBOX_DASHBOARD_PORT from src/lib/ports.ts (was file-private). - onboard.ts ensureDashboardForward() now imports the constant instead of redeclaring "18789" inline, so the cleanup branch tracks any future default-port change in one place. - Add a regression test in test/onboard.test.ts that asserts: * ports.ts exports SANDBOX_DASHBOARD_PORT * onboard.ts uses String(SANDBOX_DASHBOARD_PORT) for the cleanup * the literal 'const DEFAULT_SANDBOX_PORT = "18789"' is gone Signed-off-by: Sanjays2402 <[email protected]>
8d55eb7 to
3c54141
Compare
|
Thanks @brandonpelfrey — addressed all three points:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/onboard.test.ts (1)
996-1017: This regression test is structural, not behavioral.Line [996]–Line [1017] only validate source-text patterns, so runtime cleanup behavior can still regress while this test passes. Please add an execution-level test that asserts actual command behavior for both cases: custom dashboard port (must stop default + start custom) and default dashboard port (must not stop default).
Suggested test-shape diff
+ it("stops stale default forward when custom dashboard port is used, and skips stop on default port", async () => { + // Arrange: mock runner/openshell command capture + // Case 1: NEMOCLAW_DASHBOARD_PORT=19003 + // assert command stream includes: + // - forward stop <String(SANDBOX_DASHBOARD_PORT)> + // - forward start ... 19003 + // Case 2: default port + // assert command stream does NOT include forward stop <default> + // and includes forward start ... 18789 + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/onboard.test.ts` around lines 996 - 1017, Replace the pure-text/source-regex test with an execution-level test that spawns the onboarding logic and asserts actual commands run for both scenarios: when a custom dashboard port is provided the test for onboard.ts should observe calls to runOpenshell (or the CLI wrapper used) that first stop the default port (matching defaultPortStr derived from SANDBOX_DASHBOARD_PORT) and then start the custom port; and when no custom port is provided the test should observe that no stop command for the default port is issued. Locate symbols SANDBOX_DASHBOARD_PORT, defaultPortStr, and runOpenshell (or the onboarding entrypoint that triggers it) to hook/mock the command invocations, simulate both env/arg cases (custom port vs default), and assert the sequence and absence/presence of ["forward","stop", defaultPortStr] and ["forward","start", customPortStr] accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/onboard.test.ts`:
- Around line 996-1017: Replace the pure-text/source-regex test with an
execution-level test that spawns the onboarding logic and asserts actual
commands run for both scenarios: when a custom dashboard port is provided the
test for onboard.ts should observe calls to runOpenshell (or the CLI wrapper
used) that first stop the default port (matching defaultPortStr derived from
SANDBOX_DASHBOARD_PORT) and then start the custom port; and when no custom port
is provided the test should observe that no stop command for the default port is
issued. Locate symbols SANDBOX_DASHBOARD_PORT, defaultPortStr, and runOpenshell
(or the onboarding entrypoint that triggers it) to hook/mock the command
invocations, simulate both env/arg cases (custom port vs default), and assert
the sequence and absence/presence of ["forward","stop", defaultPortStr] and
["forward","start", customPortStr] accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: d3272ff6-f1dc-4206-bb4c-af45306ceb14
📒 Files selected for processing (3)
src/lib/onboard.tssrc/lib/ports.tstest/onboard.test.ts
|
@Sanjays2402 there are some new conflicts. please take a look. I locally made a fix to this, but I cannot push to your fork because it's protected. If you can unprotect your fork so I can push commits or otherwise perform the below:
|
Upstream's ensureDashboardForward now contains a generic stale-forward cleanup loop (iterating occupied forwards and stopping any owned by the current sandbox on a different port). This subsumes the original default-port-only cleanup from this PR. - src/lib/onboard.ts: take upstream version (no SANDBOX_DASHBOARD_PORT import needed; the new generic loop already handles the 18789 case) - src/lib/ports.ts: keep upstream (SANDBOX_DASHBOARD_PORT already exported) - test/onboard.test.ts: replace defaultPortStr regex with one matching the generic getOccupiedPorts cleanup loop, retain DEFAULT_SANDBOX_PORT and SANDBOX_DASHBOARD_PORT export guards Per maintainer comment on NVIDIA#2073.
|
@brandonpelfrey Thanks — sorry about the protected fork. Just merged Looking at the conflict, the original default-port-only cleanup is fully subsumed by the new generic stale-forward loop in
For the regression test in Let me know if you'd prefer a different approach (e.g., still keep an explicit constant import for clarity). |
Summary
When
NEMOCLAW_DASHBOARD_PORTis set to a non-default value (e.g. 19003),openshell forward listshows two forwards: one on the custom port and one on the default 18789.Root cause:
openshell sandbox createauto-forwards the default port 18789 (baked into the Docker image).ensureDashboardForward()then creates the correct custom-port forward but never cleans up the stale default-port forward.Related Issue
Fixes #2007
Changes
src/lib/onboard.ts— inensureDashboardForward(), when the resolved port differs from the hardcoded default (18789), explicitly stop the default-port forward before starting the custom one.Type of Change
Verification
npx prek run --all-filespassesnpm testpassesmake docsbuilds without warnings (doc changes only)Manual repro: set
NEMOCLAW_DASHBOARD_PORT=19003, run onboarding, confirmopenshell forward listshows only the custom-port forward.AI Disclosure
Summary by CodeRabbit
Refactor
Tests