fix(onboard): propagate context window, max tokens, and reasoning to sandbox image#1956
Conversation
📝 WalkthroughWalkthroughAdded three Nemoclaw build args/env vars— Changes
Sequence Diagram(s)sequenceDiagram
participant Host as Host (process.env)
participant Patcher as onboard.patchStagedDockerfile
participant Dockerfile as Staged Dockerfile
participant Builder as Image build / Python config generator
Host->>Patcher: provide NEMOCLAW_* env vars
Patcher->>Dockerfile: read & validate ARG lines
Patcher->>Dockerfile: replace ARG defaults when valid
Dockerfile->>Builder: build image with updated ENV
Builder->>Builder: Python reads env, computes contextWindow/maxTokens/reasoning
Builder->>GeneratedConfig: write models with computed values
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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.
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 `@src/lib/onboard.ts`:
- Around line 1027-1040: POSITIVE_INT_RE currently permits "0", so update the
validation used for contextWindow and maxTokens to only accept positive integers
> 0 (e.g., change POSITIVE_INT_RE to a regex that requires a non-zero leading
digit like /^[1-9][0-9]*$/ or replace the regex check with numeric parsing and a
> 0 check); ensure the same updated validation is applied before calling
dockerfile.replace for NEMOCLAW_CONTEXT_WINDOW and NEMOCLAW_MAX_TOKENS so zero
values are rejected.
🪄 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 Plus
Run ID: 3b708133-f82e-494c-9ea6-bfbead0d0142
📒 Files selected for processing (3)
Dockerfilesrc/lib/onboard.tstest/onboard.test.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
✨ Thanks for submitting this PR that proposes a fix to propagate context window, max tokens, and reasoning to the sandbox image, which could help improve the functionality of NemoClaw. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/onboard.ts (1)
1231-1248: Add negative-path tests for env validation edge cases.Current coverage demonstrates the happy path, but this block would benefit from explicit tests for invalid values (
"0", negatives, non-numeric, whitespace-padded,"TRUE"), asserting the originalARGdefaults remain unchanged.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/onboard.ts` around lines 1231 - 1248, Add negative-path unit tests that exercise the env validation around POSITIVE_INT_RE and the reasoning check: set process.env.NEMOCLAW_CONTEXT_WINDOW and NEMOCLAW_MAX_TOKENS to invalid values like "0", "-1", "abc", " 5 ", and "TRUE", then call the function that produces/returns the dockerfile (the code block using POSITIVE_INT_RE and NEMOCLAW_REASONING) and assert the original ARG lines for NEMOCLAW_CONTEXT_WINDOW and NEMOCLAW_MAX_TOKENS (and the reasoning ARG) remain unchanged; ensure tests restore env state after each case and include separate cases for each invalid input to verify the replacements do not occur.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/lib/onboard.ts`:
- Around line 1231-1248: Add negative-path unit tests that exercise the env
validation around POSITIVE_INT_RE and the reasoning check: set
process.env.NEMOCLAW_CONTEXT_WINDOW and NEMOCLAW_MAX_TOKENS to invalid values
like "0", "-1", "abc", " 5 ", and "TRUE", then call the function that
produces/returns the dockerfile (the code block using POSITIVE_INT_RE and
NEMOCLAW_REASONING) and assert the original ARG lines for
NEMOCLAW_CONTEXT_WINDOW and NEMOCLAW_MAX_TOKENS (and the reasoning ARG) remain
unchanged; ensure tests restore env state after each case and include separate
cases for each invalid input to verify the replacements do not occur.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ae6a0546-080b-493e-8ad3-c789e33a579c
📒 Files selected for processing (3)
Dockerfilesrc/lib/onboard.tstest/onboard.test.ts
✅ Files skipped from review due to trivial changes (1)
- test/onboard.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- Dockerfile
ericksoa
left a comment
There was a problem hiding this comment.
Reviewed from a security perspective — input validation is solid, no injection vectors, trust boundary is appropriate. LGTM.
…d reasoning env vars (#2108) ## Summary Documents the `NEMOCLAW_CONTEXT_WINDOW`, `NEMOCLAW_MAX_TOKENS`, and `NEMOCLAW_REASONING` build-time environment variables that landed in #1956. These variables now propagate through the Dockerfile ARG chain into `openclaw.json`, but were not mentioned anywhere in the published docs. ## Changes - Add a "Tune Model Metadata" section to `docs/inference/switch-inference-providers.md` with a variable reference table, defaults, value constraints, an example, and the `nemoclaw onboard --resume --recreate-sandbox` flow for applying changes to existing sandboxes. - Regenerate `.agents/skills/nemoclaw-user-configure-inference/SKILL.md` from the updated source. - Sync `.agents/skills/nemoclaw-user-reference/references/troubleshooting.md` with the current `docs/reference/troubleshooting.md` (brings the autogen reference back in line with the `openclaw update` entry added in #2033). ## Type of Change - [ ] Code change (feature, bug fix, or refactor) - [ ] Code change with doc updates - [x] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Verification - [x] `npx prek run --all-files` passes - [ ] `npm test` passes - [ ] Tests added or updated for new or changed behavior - [x] No secrets, API keys, or credentials committed - [x] Docs updated for user-facing behavior changes - [x] `make docs` builds without warnings (doc changes only) - [x] Doc pages follow the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md) (doc changes only) - [ ] New doc pages include SPDX header and frontmatter (new pages only) ## AI Disclosure - [x] AI-assisted — tool: Cursor --- Signed-off-by: Miyoung Choi <miyoungc@nvidia.com> Made with [Cursor](https://cursor.com) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added guide for tuning model metadata via build-time configuration variables. * Documented three new parameters for context window, max tokens, and reasoning, including accepted values, defaults, and that invalid values are ignored. * Clarified that changes apply during image build and require recreating a sandbox to take effect. * Simplified update-timeout troubleshooting with a single rebuild workflow. * Updated documentation versioning to include the new release. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Miyoung Choi <miyoungc@nvidia.com>
…son (#2441) <!-- markdownlint-disable MD041 --> ## Summary The `NEMOCLAW_INFERENCE_INPUTS` variable is not sent all the way to the `openclaw.json` file (and thus the agent configuration). The `input` field in `models[0]` is hardcoded to `['text']` in the Dockerfile, so users who select a vision-capable model via `NEMOCLAW_MODEL` cannot tell OpenClaw that the model accepts image input. This extends #1956's plumbing pattern to cover the last remaining hardcoded inference field. ## Related Issue Fixes #2421 ## Changes - adds 1 ARG to the `Dockerfile` with default `text` (matching the previously-hardcoded value), promotes it to ENV, and the Python script reads from `os.environ` . - `patchStagedDockerfile()` in `onboard.ts` reads `NEMOCLAW_INFERENCE_INPUTS` from the host and patches the ARG line before image build, validated by regex `/^(text|image)(,(text|image))*$/` matching OpenClaw's `model.input` schema (`z.array(z.union([z.literal("text"), z.literal("image")]))`) - Unit tests to verify: positive case (`text,image` → baked) plus a 6-case reject table (`undefined / audio / text, / Text,Image / text, image / shell-injection attempt`) ## Type of Change - [ √] Code change (feature, bug fix, or refactor) - [ ] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Verification <!-- Check each item you ran and confirmed. Leave unchecked items you skipped. --> - [ √] `npx prek run --all-files` passes - [ √] `npm test` passes - [ √] Tests added or updated for new or changed behavior - [√ ] No secrets, API keys, or credentials committed - [ ] Docs updated for user-facing behavior changes - [ ] `make docs` builds without warnings (doc changes only) - [ ] Doc pages follow the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md) (doc changes only) - [ ] New doc pages include SPDX header and frontmatter (new pages only) ## AI Disclosure - [ ] AI-assisted — tool: Cursor --- <!-- DCO sign-off required by CI. Run: git config user.name && git config user.email --> Signed-off-by: rluo8 <ruluo@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added build/runtime environment support to specify model input modalities (e.g., text, image) with a safe default of "text", enabling image-capable modal setups via env configuration. * Inputs are validated and parsed into a trimmed, comma-separated list before use. * **Tests** * Added regression tests for parsing and validation of the input-modality setting, covering valid multi-value inputs and malformed or injection-like values. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Rui Luo <ruluo@nvidia.com>
…son (NVIDIA#2441) <!-- markdownlint-disable MD041 --> ## Summary The `NEMOCLAW_INFERENCE_INPUTS` variable is not sent all the way to the `openclaw.json` file (and thus the agent configuration). The `input` field in `models[0]` is hardcoded to `['text']` in the Dockerfile, so users who select a vision-capable model via `NEMOCLAW_MODEL` cannot tell OpenClaw that the model accepts image input. This extends NVIDIA#1956's plumbing pattern to cover the last remaining hardcoded inference field. ## Related Issue Fixes NVIDIA#2421 ## Changes - adds 1 ARG to the `Dockerfile` with default `text` (matching the previously-hardcoded value), promotes it to ENV, and the Python script reads from `os.environ` . - `patchStagedDockerfile()` in `onboard.ts` reads `NEMOCLAW_INFERENCE_INPUTS` from the host and patches the ARG line before image build, validated by regex `/^(text|image)(,(text|image))*$/` matching OpenClaw's `model.input` schema (`z.array(z.union([z.literal("text"), z.literal("image")]))`) - Unit tests to verify: positive case (`text,image` → baked) plus a 6-case reject table (`undefined / audio / text, / Text,Image / text, image / shell-injection attempt`) ## Type of Change - [ √] Code change (feature, bug fix, or refactor) - [ ] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Verification <!-- Check each item you ran and confirmed. Leave unchecked items you skipped. --> - [ √] `npx prek run --all-files` passes - [ √] `npm test` passes - [ √] Tests added or updated for new or changed behavior - [√ ] No secrets, API keys, or credentials committed - [ ] Docs updated for user-facing behavior changes - [ ] `make docs` builds without warnings (doc changes only) - [ ] Doc pages follow the [style guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md) (doc changes only) - [ ] New doc pages include SPDX header and frontmatter (new pages only) ## AI Disclosure - [ ] AI-assisted — tool: Cursor --- <!-- DCO sign-off required by CI. Run: git config user.name && git config user.email --> Signed-off-by: rluo8 <ruluo@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added build/runtime environment support to specify model input modalities (e.g., text, image) with a safe default of "text", enabling image-capable modal setups via env configuration. * Inputs are validated and parsed into a trimmed, comma-separated list before use. * **Tests** * Added regression tests for parsing and validation of the input-modality setting, covering valid multi-value inputs and malformed or injection-like values. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Rui Luo <ruluo@nvidia.com>
Summary
The
NEMOCLAW_CONTEXT_WINDOW,NEMOCLAW_MAX_TOKENSandNEMOCLAW_REASONINGvariables were not sent all the way to theopenclaw.jsonfile (and thus the agent configuration), I've tried to fix that. As theDockerfileis altered, this will likely require a sandbox re-creation to kick in.There were a few tests I couldn't get green as they were timing out, but they don't seem to be related to the files changed in this PR.
Changes
Dockerfilewith the same defaults as before, promotes them to ENV, and the Python script reads from os.environ instead of literalspatchStagedDockerfile()inonboard.tsreads the 3 env vars from the host and patches the ARG lines before image buildType of Change
Verification
npx prek run --all-filespassesnpm testpassesmake docsbuilds without warnings (doc changes only)AI Disclosure
Signed-off-by: Jacob Avlund jacob@avlund.dk
Summary by CodeRabbit
New Features
Tests