fix(cli): correct SANDBOX_NAME precedence in start-services.sh#1311
fix(cli): correct SANDBOX_NAME precedence in start-services.sh#1311BenediktSchackenberg wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
NEMOCLAW_SANDBOX was winning over a caller-set SANDBOX_NAME due to
the expansion order: ${NEMOCLAW_SANDBOX:-${SANDBOX_NAME:-default}}.
Fix: resolve NEMOCLAW_SANDBOX into a local default first, then use
${SANDBOX_NAME:-default} so an explicit caller-set SANDBOX_NAME takes
priority over a stale NEMOCLAW_SANDBOX export.
Precedence is now: --sandbox flag > SANDBOX_NAME env > NEMOCLAW_SANDBOX env > 'default'
Fixes NVIDIA#1309
Signed-off-by: Benedikt Schackenberg <6381261+BenediktSchackenberg@users.noreply.github.com>
📝 WalkthroughWalkthroughThe fix corrects environment variable precedence in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Fixes sandbox name resolution in start-services.sh so an explicitly caller-set SANDBOX_NAME is no longer overridden by a stale NEMOCLAW_SANDBOX environment variable, aligning PID directory/service routing with the intended sandbox selection.
Changes:
- Adjusted sandbox name defaulting logic to prefer
SANDBOX_NAMEoverNEMOCLAW_SANDBOX. - Added inline documentation explaining the intended precedence order and rationale.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # SANDBOX_NAME precedence: --sandbox flag > SANDBOX_NAME env > NEMOCLAW_SANDBOX env > "default" | ||
| # Using SANDBOX_NAME:-... (not NEMOCLAW_SANDBOX:-SANDBOX_NAME:-...) ensures an explicit | ||
| # caller-set SANDBOX_NAME is not silently overridden by a stale NEMOCLAW_SANDBOX export. | ||
| _SANDBOX_DEFAULT="${NEMOCLAW_SANDBOX:-default}" | ||
| SANDBOX_NAME="${SANDBOX_NAME:-$_SANDBOX_DEFAULT}" |
There was a problem hiding this comment.
The SANDBOX_NAME precedence has changed here, but the existing test coverage appears to still assert the old behavior (e.g., test/service-env.test.js has a case expecting NEMOCLAW_SANDBOX to override SANDBOX_NAME, and those tests also don’t execute start-services.sh directly). Please update/add tests to assert the new precedence (SANDBOX_NAME wins over NEMOCLAW_SANDBOX) and ideally exercise the script logic rather than duplicating a parameter-expansion snippet in the test.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/start-services.sh`:
- Around line 22-26: Update the test expectation and the sibling script to
reflect the new SANDBOX_NAME precedence: change the test in
test/service-env.test.js for "uses NEMOCLAW_SANDBOX over SANDBOX_NAME" to expect
SANDBOX_NAME to win when both SANDBOX_NAME and NEMOCLAW_SANDBOX are set (i.e.,
expect "old" instead of "from-env"), and edit scripts/debug.sh to use the same
two-step expansion pattern as start-services.sh (create a fallback var like
_SANDBOX_DEFAULT="${NEMOCLAW_SANDBOX:-default}" and then
SANDBOX_NAME="${SANDBOX_NAME:-$_SANDBOX_DEFAULT}") so both scripts share
identical precedence logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1453b19c-e4c6-4b1f-9fcf-7f3126a29123
📒 Files selected for processing (1)
scripts/start-services.sh
| # SANDBOX_NAME precedence: --sandbox flag > SANDBOX_NAME env > NEMOCLAW_SANDBOX env > "default" | ||
| # Using SANDBOX_NAME:-... (not NEMOCLAW_SANDBOX:-SANDBOX_NAME:-...) ensures an explicit | ||
| # caller-set SANDBOX_NAME is not silently overridden by a stale NEMOCLAW_SANDBOX export. | ||
| _SANDBOX_DEFAULT="${NEMOCLAW_SANDBOX:-default}" | ||
| SANDBOX_NAME="${SANDBOX_NAME:-$_SANDBOX_DEFAULT}" |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify which scripts still use the old precedence pattern
echo "=== Scripts with old NEMOCLAW_SANDBOX:-SANDBOX_NAME pattern ==="
rg -n 'NEMOCLAW_SANDBOX:-.*SANDBOX_NAME' --type sh
echo ""
echo "=== Test files referencing the old pattern ==="
rg -n 'NEMOCLAW_SANDBOX:-.*SANDBOX_NAME' --type js --type tsRepository: NVIDIA/NemoClaw
Length of output: 859
🏁 Script executed:
sed -n '120,160p' test/service-env.test.jsRepository: NVIDIA/NemoClaw
Length of output: 1646
🏁 Script executed:
sed -n '35,45p' scripts/debug.shRepository: NVIDIA/NemoClaw
Length of output: 310
Logic fix is correct; existing tests and debug.sh need updating to match new precedence.
The two-step expansion correctly implements the intended precedence (SANDBOX_NAME flag > SANDBOX_NAME env > NEMOCLAW_SANDBOX env > "default"). However, the following must be addressed:
-
Test failure:
test/service-env.test.jstest "uses NEMOCLAW_SANDBOX over SANDBOX_NAME" (around line 133) will fail. It expectsNEMOCLAW_SANDBOX="from-env"to take precedence overSANDBOX_NAME="old", but the new pattern gives SANDBOX_NAME precedence, so the test will return"old"instead of the expected"from-env". Update the test expectations to reflect the new precedence. -
Inconsistent sibling script:
scripts/debug.sh:39still uses the old pattern:SANDBOX_NAME="${NEMOCLAW_SANDBOX:-${SANDBOX_NAME:-}}"Update it to match the new precedence logic in
start-services.sh.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@scripts/start-services.sh` around lines 22 - 26, Update the test expectation
and the sibling script to reflect the new SANDBOX_NAME precedence: change the
test in test/service-env.test.js for "uses NEMOCLAW_SANDBOX over SANDBOX_NAME"
to expect SANDBOX_NAME to win when both SANDBOX_NAME and NEMOCLAW_SANDBOX are
set (i.e., expect "old" instead of "from-env"), and edit scripts/debug.sh to use
the same two-step expansion pattern as start-services.sh (create a fallback var
like _SANDBOX_DEFAULT="${NEMOCLAW_SANDBOX:-default}" and then
SANDBOX_NAME="${SANDBOX_NAME:-$_SANDBOX_DEFAULT}") so both scripts share
identical precedence logic.
|
✨ Thanks for submitting this pull request, which proposes a way to fix sandbox name resolution in start-services.sh by correcting the precedence of environment variables. Possibly related open issues: |
Summary
Fixes #1309.
start-services.shwas using${NEMOCLAW_SANDBOX:-${SANDBOX_NAME:-default}}, which meansNEMOCLAW_SANDBOXalways wins over a caller-setSANDBOX_NAME. Whennemoclaw startpassesSANDBOX_NAME=my-sandboxbut the shell environment has a staleNEMOCLAW_SANDBOX=something-else(e.g. from a previous session or.envfile), the PID directory and service routing uses the wrong sandbox name.Fix
Reverse the precedence by resolving
NEMOCLAW_SANDBOXinto a local default first:Precedence is now:
--sandboxCLI flag (highest)SANDBOX_NAMEenv var (caller-set)NEMOCLAW_SANDBOXenv var (session default)"default"literal fallbackTesting
Verified the fix with:
Signed-off-by: Benedikt Schackenberg 6381261+BenediktSchackenberg@users.noreply.github.com
Summary by CodeRabbit