fix(onboard): update sandbox openclaw.json with selected Ollama model (fixes #628)#630
Conversation
…fixes NVIDIA#628) When users select Local Ollama during onboarding, the sandbox's openclaw.json still showed the default cloud model because the Dockerfile was built before the model was selected. Fix: reorder the onboarding flow so inference provider/model selection (Step 3) happens before sandbox creation (Step 4). The selected model is then patched into the Dockerfile's ARG NEMOCLAW_MODEL default before the image build, ensuring openclaw.json is baked with the correct model at build time. This preserves the immutable config design from PR NVIDIA#588 — openclaw.json is still root:root 444 and never modified at runtime. The fix operates entirely at build time. Changes: - Rename setupNim() → selectInference() (no sandbox dependency) - Add patchDockerfileModel() to rewrite ARG NEMOCLAW_MODEL - Defer NIM container start to after sandbox creation - Move registry.updateSandbox() to main onboard() flow - Add tests for Dockerfile patching
📝 WalkthroughWalkthroughThis PR refactors the onboarding flow to ensure user-selected inference models are baked into the sandbox image at build time. It introduces Changes
Sequence DiagramsequenceDiagram
participant User
participant Onboard as Onboard Flow
participant Inference as selectInference()
participant Sandbox as createSandbox()
participant Patcher as patchDockerfileModel()
participant NIM as startNim()
User->>Onboard: onboard(gpu)
Onboard->>Inference: selectInference(gpu)
Inference-->>Onboard: {provider, model}
Onboard->>Sandbox: createSandbox(gpu, model)
Sandbox->>Patcher: patchDockerfileModel(path, model)
Patcher-->>Sandbox: Dockerfile updated
Sandbox-->>Onboard: sandboxName
Onboard->>NIM: startNim(sandboxName, model)
NIM-->>Onboard: Container ready
Onboard-->>User: Sandbox configured
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment Tip CodeRabbit can use oxc to improve the quality of JavaScript and TypeScript code reviews.Add a configuration file to your project to customize how CodeRabbit runs oxc. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
bin/lib/onboard.js (1)
298-314: Potential injection risk inpatchDockerfileModelif model contains regex special characters.The
modelparameter is interpolated directly into the replacement string. WhileisSafeModelId()validates the model against/^[A-Za-z0-9._:/-]+$/, none of these characters are problematic for the regex replacement. However, the function relies on validation happening upstream.Consider adding a defensive check or assertion:
🛡️ Optional: Add defensive validation
function patchDockerfileModel(dockerfilePath, model) { + if (!isSafeModelId(model)) { + throw new Error(`Invalid model identifier: ${model}`); + } const content = fs.readFileSync(dockerfilePath, "utf8"); const patched = content.replace( /^ARG NEMOCLAW_MODEL=.+$/m, `ARG NEMOCLAW_MODEL=${model}`, ); fs.writeFileSync(dockerfilePath, patched); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bin/lib/onboard.js` around lines 298 - 314, Add a defensive validation in patchDockerfileModel: before reading/writing, call the existing isSafeModelId(model) (or equivalent validator) and throw or exit if it returns false so unvalidated input never reaches the regex replacement; this prevents accidental injection or special-replacement sequences (e.g. $) from influencing the replacement. Keep the rest of patchDockerfileModel intact (read file, replace /^ARG NEMOCLAW_MODEL=.+$/m, write file) but fail fast if isSafeModelId(model) is false to ensure only validated model IDs are used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@bin/lib/onboard.js`:
- Around line 298-314: Add a defensive validation in patchDockerfileModel:
before reading/writing, call the existing isSafeModelId(model) (or equivalent
validator) and throw or exit if it returns false so unvalidated input never
reaches the regex replacement; this prevents accidental injection or
special-replacement sequences (e.g. $) from influencing the replacement. Keep
the rest of patchDockerfileModel intact (read file, replace /^ARG
NEMOCLAW_MODEL=.+$/m, write file) but fail fast if isSafeModelId(model) is false
to ensure only validated model IDs are used.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 431c6c0c-d278-4c60-9b3a-8804c8cd782c
📒 Files selected for processing (3)
bin/lib/onboard.jstest/onboard-selection.test.jstest/onboard.test.js
|
The gateway is actually swapping the correct LLM during the flight request, the default in openclaw.json is being ignored. |
|
Thanks for the context @andy-ratsirarson! That's an important distinction. So the actual behavior is:
This PR fixes the cosmetic issue — after onboarding,
Does the gateway always override |
Problem
When users select Local Ollama during onboarding, the sandbox's
~/.openclaw/openclaw.jsonstill shows the default cloud model (inference/nvidia/nemotron-3-super-120b-a12b) instead of the selected Ollama model (e.g.,nemotron-3-nano:30b).This happens because the Dockerfile bakes
openclaw.jsonat build time usingARG NEMOCLAW_MODEL(default:nvidia/nemotron-3-super-120b-a12b), and the sandbox is built before the user selects their inference provider/model.The gateway correctly routes requests to Ollama (via
openshell inference set), but the agent readsopenclaw.jsonand reports the wrong model identity.Root Cause
The onboarding flow was ordered:
openclaw.jsonwith default cloud model)So
openclaw.jsonalways contained the cloud default, regardless of what the user chose.Fix
Reorder the onboarding flow so inference selection happens before sandbox creation:
setupNim()→selectInference())ARG NEMOCLAW_MODELdefault to the selected model before buildingThis preserves the immutable config design from PR #588 —
openclaw.jsonremainsroot:root 444and is never modified at runtime. The fix operates entirely at build time by patching the Dockerfile's build arg.Changes
bin/lib/onboard.jsselectInference()beforecreateSandbox()bin/lib/onboard.jspatchDockerfileModel()helperbin/lib/onboard.jssetupNim()→selectInference()(no sandbox dependency)bin/lib/onboard.jstest/onboard.test.jspatchDockerfileModel()test/onboard-selection.test.jsselectInference()Testing
install-preflight.test.js)Fixes #628
Summary by CodeRabbit
New Features
Refactor