refactor(onboard): separate sandbox intent from effects - #6218
Conversation
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
📝 WalkthroughWalkthroughRefactors sandbox creation into a two-stage flow that resolves a serializable create intent and then materializes it into create arguments, provider wiring, and credential validation. ChangesSandbox create-plan two-stage refactor
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant prepareSandboxCreatePlan
participant resolveSandboxCreateIntent
participant materializeSandboxCreatePlan
participant upsertMessagingProviders
prepareSandboxCreatePlan->>resolveSandboxCreateIntent: build intent inputs
resolveSandboxCreateIntent-->>prepareSandboxCreatePlan: SandboxCreateIntent
prepareSandboxCreatePlan->>materializeSandboxCreatePlan: materialize intent with token defs
materializeSandboxCreatePlan->>upsertMessagingProviders: create provider records
upsertMessagingProviders-->>materializeSandboxCreatePlan: provider names
materializeSandboxCreatePlan-->>prepareSandboxCreatePlan: SandboxCreatePlan
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Code Coverage OverviewLanguages: TypeScript TypeScript / code-coverage/pluginThe overall coverage in the Show a code coverage summary of the most covered files.
TypeScript / code-coverage/cliThe overall coverage in the Show a code coverage summary of the most covered files.
Updated |
PR Review Advisor (Nemotron Ultra) — No blocking findingsMerge posture: No blocking advisor findings Action checklist
Findings index
Review findings by urgency: 0 required fixes, 0 items to resolve/justify, 4 in-scope improvements
|
E2E Advisor RecommendationRequired E2E: Dispatch hint: Full advisor summaryE2E Recommendation AdvisorBase: Required E2E
Optional E2E
New E2E recommendations
Dispatch hint
|
E2E Target RecommendationRequired E2E targets: Dispatch required E2E targets:
Full E2E target advisor summaryE2E Target AdvisorBase: Required E2E targets
Optional E2E targets
Relevant changed files
|
PR Review Advisor — No blocking findingsMerge posture: No blocking advisor findings Action checklist
Test follow-ups to resolve or justifyIf these cover changed behavior, prefer adding them in this PR; otherwise state why existing coverage is enough or link the follow-up.
This is an automated, non-binding review; it still expects maintainers and agents to respond to each required or warning item. Treat suggestions as current-PR improvements when they touch changed code; defer only with maintainer rationale or a linked follow-up. A human maintainer must make the final merge decision. |
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/lib/onboard/sandbox-create-plan.ts (1)
229-241: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winUse the
Setfor primary credential lookup.Line 241 calls
.has()onprimaryMessagingCredentialEnvKeys, which is typed asreadonly string[]; this fails type-checking. Use theprimaryCredentialEnvKeysset created on Line 229.Proposed fix
- return channel && primaryMessagingCredentialEnvKeys.has(envKey) ? [channel] : []; + return channel && primaryCredentialEnvKeys.has(envKey) ? [channel] : [];🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/onboard/sandbox-create-plan.ts` around lines 229 - 241, The primary credential lookup in sandbox-create-plan is using the wrong type for membership checks: `primaryMessagingCredentialEnvKeys` is a readonly array, so the `.has()` call in the `messagingProviderRequests` filter will not type-check. Update the `filterEnabledChannelNames` path to use the existing `primaryCredentialEnvKeys` Set created in `sandbox-create-plan` for the `envKey` membership test, and keep the `resolveQrSelectedChannels` flow unchanged.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/lib/onboard/sandbox-create-plan.ts`:
- Around line 229-241: The primary credential lookup in sandbox-create-plan is
using the wrong type for membership checks: `primaryMessagingCredentialEnvKeys`
is a readonly array, so the `.has()` call in the `messagingProviderRequests`
filter will not type-check. Update the `filterEnabledChannelNames` path to use
the existing `primaryCredentialEnvKeys` Set created in `sandbox-create-plan` for
the `envKey` membership test, and keep the `resolveQrSelectedChannels` flow
unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 07d56891-0959-491f-bdcb-0e5e8424b731
📒 Files selected for processing (2)
src/lib/onboard/sandbox-create-plan.test.tssrc/lib/onboard/sandbox-create-plan.ts
Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Vitest E2E Target Results —
|
| Job | Result |
|---|---|
| live |
Vitest E2E Target Results —
|
| Job | Result |
|---|---|
| cloud-onboard | |
| full-e2e | ✅ success |
| messaging-providers |
Vitest E2E Target Results — ✅ All selected jobs passedRun: 28628983888
|
Vitest E2E Target Results — ✅ All requested jobs passedRun: 28629117819
|
|
Automated-review follow-up for head
Both advisors now report no required findings or warnings. |
<!-- markdownlint-disable MD041 --> ## Summary <!-- 1-3 sentences: what this PR does and why. --> Prevents a Ready LangChain Deep Agents Code sandbox from being deleted until its recorded OpenShell gateway, live inference route, managed base image, and staged build context have been validated and sealed. A DCode-only, process-local orchestration facade carries that verified gateway/context pair through recreation, fixing the post-delete port-8080 false conflict from #6195 without adding generalized persisted replay or FSM state. ## Related Issue <!-- Fixes #NNN or Closes #NNN. Remove this section if none. --> Fixes #6195 Refs #6218 Refs #6224 Refs #6226 Refs #5801 ## Changes <!-- Bullet list of key changes. --> - Bind DCode rebuilds to the sandbox's recorded gateway before credential validation, probe the live `https://inference.local` route without exposing credentials, and revalidate the gateway, registry entry, route, schema, base image, and staged context immediately before deletion. - Build a disposable DCode image and fingerprint its managed build context before mutation, then pass the retained context and recorded gateway as a one-shot handoff through the create-intent seam landed in #6218. Ordinary onboarding and non-DCode rebuild behavior remain unchanged. - Put the DCode lifecycle in `rebuild-dcode-orchestrator.ts`: it owns scoped gateway cleanup, target preflight, replacement preparation, mutation-edge revalidation, recovery behavior, and one-shot handoff cleanup while depending on injected generic rebuild callbacks. This reduced `rebuild.ts` from 1,599 to 1,460 lines and split its 1,477-line flow spec into focused generic and DCode suites plus a shared harness. - Extract the onboarding handoff into `prepared-dcode-rebuild.ts`, which owns gateway validation, ordinary-versus-prepared staging/patching, and consume-before-call semantics. The top-level `onboard.ts` entrypoint is four lines smaller than `main`. - Preserve the existing sandbox when initial preflight fails; if mutation-edge validation fails after backup, keep the harmless backup but do not delete or recreate the sandbox. Prepared-backup recovery skips unavailable live-route probes and does not take a second backup. Messaging-preflight aborts also restore the prior process gateway. - Harden managed-context sealing against symlink substitution, pathname replacement, and in-place mutation by reading regular files through `O_NOFOLLOW` file descriptors and checking identity/metadata before and after each read. - Add a live DCode lifecycle fixture that rotates the credential stored in the real gateway, waits for a 401, runs rebuild without a host credential, and proves there was no backup/delete/create while container identity, readiness, and a workspace marker remain intact. - Document the DCode rebuild preflight and backup boundary in the quickstart. A documentation review confirmed no further user-facing changes are needed. - Keep generalized FSM/session capture and cross-agent replay out of scope for #6224/#6226; true build/health/swap replacement remains #5801. ## Type of Change - [ ] Code change (feature, bug fix, or refactor) - [x] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Quality Gates <!-- Check all that apply. For any "covered by existing tests", "not applicable", or waiver entry, add a brief justification on the same line or in the Changes section. --> - [x] Tests added or updated for changed behavior - [ ] Existing tests cover changed behavior — justification: - [ ] Tests not applicable — justification: - [x] Docs updated for user-facing behavior changes - [ ] Docs not applicable — justification: - [x] Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging) - [x] Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: independent final architecture and nine-category security reviews both passed the narrowed DCode-only design with no blocker; the security review included the final orchestration extraction and managed-context TOCTOU hardening. - [ ] Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue: ## Verification <!-- Check each item you ran and confirmed. Leave unchecked items you skipped. Doc-only changes do not require npm test unless you ran it. --> - [x] PR description includes the DCO sign-off declaration and every commit appears as `Verified` in GitHub - [x] Git hooks passed during commit and push, or `npx prek run --from-ref main --to-ref HEAD` passes - [x] Targeted tests pass for changed behavior - [x] Full `npm test` passes (broad runtime changes only) - [x] Quality Gates section completed with required justifications or waivers - [x] No secrets, API keys, or credentials committed - [ ] `npm run 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) Commands and evidence: - `make check` — passed on the final narrowed implementation under the repository-expected `umask 022`. - `npm test` — 998 files passed, 2 platform suites skipped; 11,277 tests passed, 35 skipped. - Post-merge focused/current-main set — 96/96 passed across generic rebuild flow, DCode flow, managed-image preflight, prepared handoff, inference-provider compatibility, and messaging setup; the final descriptor-pinning, target-guard, and fail-closed review deltas passed 27/27 focused cases. - Additional affected environment-failure audit — 121/121 passed; E2E support — 26/26 passed. - `npm run build:cli` and `npm run typecheck:cli` — passed. - Current-tree Vitest project-membership check — 1,075 files across eight disjoint projects; source-shape, test-file-size, and changed-test conditional budgets passed. - `npm run docs` — passed with 0 errors and 2 pre-existing warnings. - Pre-push plugin and CLI TypeScript gates — passed. - GitHub commit verification — 18/18 commits report `verified=true`, reason `valid`. --- <!-- DCO sign-off is required in this PR description, and every commit must appear as Verified in GitHub. Run: git config user.name && git config user.email --> Signed-off-by: Carlos Villela <cvillela@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for a new DCode rebuild flow during onboarding and sandbox recreation. * Introduced a preflight check for inference routing before rebuilds proceed. * **Bug Fixes** * Rebuilds now fail safely when credentials or routing are invalid, helping prevent unsafe sandbox changes. * Improved rebuild handling so existing sandboxes and backups are preserved if a later check fails. * **Documentation** * Updated the quickstart guide with clearer rebuild and backup behavior for managed DCode sandboxes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Carlos Villela <cvillela@nvidia.com>
## Summary Hardens the managed-MCP work merged in #5876 so DCode rebuilds validate every reconstructable input before crossing the destructive delete boundary, preserve exact policy intent, and migrate legacy managed MCP state fail-closed. Prepared rebuild artifacts and the derived MCP runtime snapshot remain ephemeral and process-local; neither is persisted in FSM or checkpoint state, so this does not implement #6224. ## Related Issue Refs #5876 Refs #6195 Refs #6218 ## Changes - Revalidate DCode route, image, Dockerfile, reasoning, web-search, and MCP inputs after preparation and before NIM stop or sandbox deletion; restore MCP state and relock shields on failure. - Preserve exact custom network policy replay while keeping generated MCP rules under the MCP adapter's exclusive ownership. - Add protocol-specific policy schema validation for REST, WebSocket, JSON-RPC, and MCP matchers, including cross-rule `tools/call` conflict rejection. - Pin Deep Agents Code 0.1.30 and load only a strict, canonicalized managed MCP projection from a process-local integrity-bound snapshot. Sealed memfd is preferred; when OpenShell seccomp blocks it, an anonymous `O_TMPFILE` inode is reopened read-only and bound by descriptor, device, inode, size, kind, and SHA-256, with ambient discovery disabled. - Bind the canonical TypeScript secret-pattern source and flags to one shared behavior corpus executed through the Bash and Python DCode enforcement boundaries, including the full ECMAScript whitespace set. - Add capability-v2 gating and legacy-v1 teardown/rollback that preserves unrelated user configuration and fails closed on malformed, unsafe, or drifted state. - Add rebuild, migration, runtime-patch, schema, snapshot, and lifecycle coverage; update the MCP, policy, security, command, and DCode documentation. Verification notes: - Final DCode-adjacent run: 9 files, 187 tests passed; the focused descriptor/projection run passed 4 files and 138 tests. - Final review-follow-up run: 82 focused Bash/Python/TypeScript parity and descriptor-fallback tests passed, including all 25 ECMAScript whitespace code points under both `C` and `C.UTF-8` Bash locales. - Full pre-squash-equivalent run: 1,068 files passed, 2 skipped; 12,149 tests passed, 35 skipped. - CLI coverage ratchet passed with the repository include/exclude set expressed as one Vitest glob: lines 65.24%, statements 64.45%, functions 67.06%, branches 57.21%. - Python compile, Biome, ShellCheck, shfmt, source-shape, test-size, repository, secret-scan, and diff checks passed. The normal push hook passed CLI typechecking. - Main-sync validation after merging #6265 passed: 9 CLI files/82 tests, 6 integration files/174 tests, an additional 3 preparation tests, CLI typecheck, Biome, and diff checks. Generated-context provenance was ported into the split preflight fixtures without restoring the obsolete monolith. - Exact-head CI for `9a31537785ef2d456901de622721ed215627fdec` passed: 40 checks green, all five required contexts passed, and there were 0 failures, cancellations, or pending checks. The only skips were the expected docs-only job and two duplicate NVSkills request jobs. This includes all five CLI shards plus the aggregate, both CodeQL languages, both sandbox image builds, macOS, WSL, four self-hosted runtime checks, CodeRabbit, and both review advisors. - Exact-head live E2E for `9a31537785ef2d456901de622721ed215627fdec` passed: [`mcp-bridge`](https://github.com/NVIDIA/NemoClaw/actions/runs/28696844701), [`mcp-bridge-dev`](https://github.com/NVIDIA/NemoClaw/actions/runs/28696844719), and [`ubuntu-repo-cloud-langchain-deepagents-code`](https://github.com/NVIDIA/NemoClaw/actions/runs/28696844639). Stable and dev each passed OpenClaw, Hermes, and DCode 3/3; authenticated MCP calls passed initially and after restart, credential rotation, and rebuild, then removal denied access with no provider, policy, tunnel, or credential residue. The dedicated DCode lane passed Landlock 5/5, Python egress 14/14, headless inference 10/10, secret boundary 8/8, Tavily 6/6, and TUI 4/4; BuildKit accepted the merged generated-context handoff, and invalid-credential rebuild failure remained pre-destructive with the original sandbox, marker, and route recovered. Artifact inspection found one unchanged pre-existing harness defect: two OpenShell audit-log filtering subassertions can false-pass because awk treats `close` as reserved; runtime-output, sandbox-log, env-file immutability, and raw-secret checks passed, and this PR does not modify that E2E file. - The base `test-cli` pre-commit invocation remains affected by Vitest 4.1.9 collapsing repeated `--coverage.exclude` arguments to a zero-file/invalid summary. All other commit and push hooks passed; targeted tests and the authoritative sharded CI coverage checks provide the exact-head gate. - `npm run docs` completed with 0 errors and 2 pre-existing Fern warnings. Two documentation-writer audits confirmed the final behavior is accurately documented. ## Type of Change - [ ] Code change (feature, bug fix, or refactor) - [x] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Quality Gates - [x] Tests added or updated for changed behavior - [ ] Existing tests cover changed behavior — justification: - [ ] Tests not applicable — justification: - [x] Docs updated for user-facing behavior changes - [ ] Docs not applicable — justification: - [x] Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging) - [x] Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: independent security and correctness reviews passed after fixes; destructive-boundary rollback, capability migration, the process-local integrity-bound snapshot handoff (sealed memfd preferred, anonymous `O_TMPFILE` fallback), cross-language secret-pattern parity, policy fidelity, and the #6224 boundary were checked. - [ ] Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue: ## Verification - [x] PR description includes the DCO sign-off declaration and every commit appears as `Verified` in GitHub - [ ] Git hooks passed during commit and push, or `npx prek run --from-ref main --to-ref HEAD` passes - [x] Targeted tests pass for changed behavior - [x] Full `npm test` passes (broad runtime changes only) - [x] Quality Gates section completed with required justifications or waivers - [x] No secrets, API keys, or credentials committed - [ ] `npm run 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) --- Signed-off-by: Carlos Villela <cvillela@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Enhanced managed MCP bridge support with managed-only configuration snapshots for safer add/restart/rebuild/teardown. * Network policy protocol rules now support protocol-specific matching plus stricter `endpoint.path` validation. * **Bug Fixes** * Stronger fail-fast validation for MCP server names/hostnames and endpoint details (rejected before changes are applied). * Rebuild flows improved to preserve/replay custom policies and validate after MCP preparation, with rollback on failure. * **Documentation** * Updated setup/quickstart/reference and MCP bridge/rebuild guidance for managed MCP capability v2 behavior and stricter validation rules. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Carlos Villela <cvillela@nvidia.com>
<!-- markdownlint-disable MD041 --> ## Summary <!-- 1-3 sentences: what this PR does and why. --> Separates create-time onboarding intent resolution from effectful materialization while preserving the existing `prepareSandboxCreatePlan` entry point and runtime behavior. This establishes a typed internal seam for later FSM work without persisting temporary paths, cleanup callbacks, or messaging credential values. ## Changes <!-- Bullet list of key changes. --> - Add a deterministic `SandboxCreateIntent` resolver with explicit credential metadata, policy inputs, GPU arguments, and provider contributions. - Materialize temporary policy files, resource flags, provider cleanup/upserts, and concrete create arguments in a separate effectful phase. - Keep the serializable intent contract in a dedicated type-only module so the execution path remains focused. - Reject changed credential availability or provider type before any materialization effects run. - Preserve provider ordering, channel filtering, policy-tier behavior, and the existing compatibility wrapper. - Add characterization coverage for serialization, credential-value exclusion, effect ordering, stale bindings, disabled channels, GPU behavior, and provider deduplication. - Keep FSM/session capture out of scope: recreate still reaches this seam after the existing destructive boundary, which requires a separate migration. - Local verification used Node.js 22: 39 focused tests pass, CLI typecheck/build and repository checks pass, and GitHub verifies all three signed commits. The repository-wide `test-cli` hook was attempted, then skipped for the commits because macOS lacks GNU `script -qec` and Docker; a separate CLI run reached 5,335 passing tests with 18 unrelated timeout failures in untouched files. ## Type of Change - [x] 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) ## Quality Gates <!-- Check all that apply. For any "covered by existing tests", "not applicable", or waiver entry, add a brief justification on the same line or in the Changes section. --> - [x] Tests added or updated for changed behavior - [ ] Existing tests cover changed behavior — justification: - [ ] Tests not applicable — justification: - [ ] Docs updated for user-facing behavior changes - [x] Docs not applicable — justification: internal behavior-preserving refactor with no CLI, prompt, output, persistence, event, or public API change. - [x] Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging) - [x] Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: reviewed credential-value exclusion, binding validation, and side-effect ordering; focused tests assert no effects run for stale bindings. - [ ] Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue: ## Verification <!-- Check each item you ran and confirmed. Leave unchecked items you skipped. Doc-only changes do not require npm test unless you ran it. --> - [x] PR description includes the DCO sign-off declaration and every commit appears as `Verified` in GitHub - [ ] Git hooks passed during commit and push, or `npx prek run --from-ref main --to-ref HEAD` passes - [x] Targeted tests pass for changed behavior - [ ] Full `npm test` passes (broad runtime changes only) - [x] Quality Gates section completed with required justifications or waivers - [x] No secrets, API keys, or credentials committed - [ ] `npm run 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) --- <!-- DCO sign-off is required in this PR description, and every commit must appear as Verified in GitHub. Run: git config user.name && git config user.email --> Signed-off-by: Carlos Villela <cvillela@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Strengthened validation during sandbox creation so mismatched or missing messaging credential bindings are detected early, preventing partial side effects. * Improved determinism and correctness of messaging provider request generation and the resulting provider wiring order. * **Refactor** * Reworked sandbox creation into a two-stage flow: deriving a serializable “intent” and then materializing it into final creation arguments and providers. * Updated messaging provider and active channel resolution to be request-driven, with consistent ordering and Hermes gateway integration. * **Tests** * Expanded and added coverage for intent resolution, credential-binding failure behavior, deterministic output, and effect ordering. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Carlos Villela <cvillela@nvidia.com>
<!-- markdownlint-disable MD041 --> ## Summary <!-- 1-3 sentences: what this PR does and why. --> Prevents a Ready LangChain Deep Agents Code sandbox from being deleted until its recorded OpenShell gateway, live inference route, managed base image, and staged build context have been validated and sealed. A DCode-only, process-local orchestration facade carries that verified gateway/context pair through recreation, fixing the post-delete port-8080 false conflict from NVIDIA#6195 without adding generalized persisted replay or FSM state. ## Related Issue <!-- Fixes #NNN or Closes #NNN. Remove this section if none. --> Fixes NVIDIA#6195 Refs NVIDIA#6218 Refs NVIDIA#6224 Refs NVIDIA#6226 Refs NVIDIA#5801 ## Changes <!-- Bullet list of key changes. --> - Bind DCode rebuilds to the sandbox's recorded gateway before credential validation, probe the live `https://inference.local` route without exposing credentials, and revalidate the gateway, registry entry, route, schema, base image, and staged context immediately before deletion. - Build a disposable DCode image and fingerprint its managed build context before mutation, then pass the retained context and recorded gateway as a one-shot handoff through the create-intent seam landed in NVIDIA#6218. Ordinary onboarding and non-DCode rebuild behavior remain unchanged. - Put the DCode lifecycle in `rebuild-dcode-orchestrator.ts`: it owns scoped gateway cleanup, target preflight, replacement preparation, mutation-edge revalidation, recovery behavior, and one-shot handoff cleanup while depending on injected generic rebuild callbacks. This reduced `rebuild.ts` from 1,599 to 1,460 lines and split its 1,477-line flow spec into focused generic and DCode suites plus a shared harness. - Extract the onboarding handoff into `prepared-dcode-rebuild.ts`, which owns gateway validation, ordinary-versus-prepared staging/patching, and consume-before-call semantics. The top-level `onboard.ts` entrypoint is four lines smaller than `main`. - Preserve the existing sandbox when initial preflight fails; if mutation-edge validation fails after backup, keep the harmless backup but do not delete or recreate the sandbox. Prepared-backup recovery skips unavailable live-route probes and does not take a second backup. Messaging-preflight aborts also restore the prior process gateway. - Harden managed-context sealing against symlink substitution, pathname replacement, and in-place mutation by reading regular files through `O_NOFOLLOW` file descriptors and checking identity/metadata before and after each read. - Add a live DCode lifecycle fixture that rotates the credential stored in the real gateway, waits for a 401, runs rebuild without a host credential, and proves there was no backup/delete/create while container identity, readiness, and a workspace marker remain intact. - Document the DCode rebuild preflight and backup boundary in the quickstart. A documentation review confirmed no further user-facing changes are needed. - Keep generalized FSM/session capture and cross-agent replay out of scope for NVIDIA#6224/NVIDIA#6226; true build/health/swap replacement remains NVIDIA#5801. ## Type of Change - [ ] Code change (feature, bug fix, or refactor) - [x] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Quality Gates <!-- Check all that apply. For any "covered by existing tests", "not applicable", or waiver entry, add a brief justification on the same line or in the Changes section. --> - [x] Tests added or updated for changed behavior - [ ] Existing tests cover changed behavior — justification: - [ ] Tests not applicable — justification: - [x] Docs updated for user-facing behavior changes - [ ] Docs not applicable — justification: - [x] Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging) - [x] Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: independent final architecture and nine-category security reviews both passed the narrowed DCode-only design with no blocker; the security review included the final orchestration extraction and managed-context TOCTOU hardening. - [ ] Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue: ## Verification <!-- Check each item you ran and confirmed. Leave unchecked items you skipped. Doc-only changes do not require npm test unless you ran it. --> - [x] PR description includes the DCO sign-off declaration and every commit appears as `Verified` in GitHub - [x] Git hooks passed during commit and push, or `npx prek run --from-ref main --to-ref HEAD` passes - [x] Targeted tests pass for changed behavior - [x] Full `npm test` passes (broad runtime changes only) - [x] Quality Gates section completed with required justifications or waivers - [x] No secrets, API keys, or credentials committed - [ ] `npm run 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) Commands and evidence: - `make check` — passed on the final narrowed implementation under the repository-expected `umask 022`. - `npm test` — 998 files passed, 2 platform suites skipped; 11,277 tests passed, 35 skipped. - Post-merge focused/current-main set — 96/96 passed across generic rebuild flow, DCode flow, managed-image preflight, prepared handoff, inference-provider compatibility, and messaging setup; the final descriptor-pinning, target-guard, and fail-closed review deltas passed 27/27 focused cases. - Additional affected environment-failure audit — 121/121 passed; E2E support — 26/26 passed. - `npm run build:cli` and `npm run typecheck:cli` — passed. - Current-tree Vitest project-membership check — 1,075 files across eight disjoint projects; source-shape, test-file-size, and changed-test conditional budgets passed. - `npm run docs` — passed with 0 errors and 2 pre-existing warnings. - Pre-push plugin and CLI TypeScript gates — passed. - GitHub commit verification — 18/18 commits report `verified=true`, reason `valid`. --- <!-- DCO sign-off is required in this PR description, and every commit must appear as Verified in GitHub. Run: git config user.name && git config user.email --> Signed-off-by: Carlos Villela <cvillela@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for a new DCode rebuild flow during onboarding and sandbox recreation. * Introduced a preflight check for inference routing before rebuilds proceed. * **Bug Fixes** * Rebuilds now fail safely when credentials or routing are invalid, helping prevent unsafe sandbox changes. * Improved rebuild handling so existing sandboxes and backups are preserved if a later check fails. * **Documentation** * Updated the quickstart guide with clearer rebuild and backup behavior for managed DCode sandboxes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Carlos Villela <cvillela@nvidia.com>
## Summary Hardens the managed-MCP work merged in NVIDIA#5876 so DCode rebuilds validate every reconstructable input before crossing the destructive delete boundary, preserve exact policy intent, and migrate legacy managed MCP state fail-closed. Prepared rebuild artifacts and the derived MCP runtime snapshot remain ephemeral and process-local; neither is persisted in FSM or checkpoint state, so this does not implement NVIDIA#6224. ## Related Issue Refs NVIDIA#5876 Refs NVIDIA#6195 Refs NVIDIA#6218 ## Changes - Revalidate DCode route, image, Dockerfile, reasoning, web-search, and MCP inputs after preparation and before NIM stop or sandbox deletion; restore MCP state and relock shields on failure. - Preserve exact custom network policy replay while keeping generated MCP rules under the MCP adapter's exclusive ownership. - Add protocol-specific policy schema validation for REST, WebSocket, JSON-RPC, and MCP matchers, including cross-rule `tools/call` conflict rejection. - Pin Deep Agents Code 0.1.30 and load only a strict, canonicalized managed MCP projection from a process-local integrity-bound snapshot. Sealed memfd is preferred; when OpenShell seccomp blocks it, an anonymous `O_TMPFILE` inode is reopened read-only and bound by descriptor, device, inode, size, kind, and SHA-256, with ambient discovery disabled. - Bind the canonical TypeScript secret-pattern source and flags to one shared behavior corpus executed through the Bash and Python DCode enforcement boundaries, including the full ECMAScript whitespace set. - Add capability-v2 gating and legacy-v1 teardown/rollback that preserves unrelated user configuration and fails closed on malformed, unsafe, or drifted state. - Add rebuild, migration, runtime-patch, schema, snapshot, and lifecycle coverage; update the MCP, policy, security, command, and DCode documentation. Verification notes: - Final DCode-adjacent run: 9 files, 187 tests passed; the focused descriptor/projection run passed 4 files and 138 tests. - Final review-follow-up run: 82 focused Bash/Python/TypeScript parity and descriptor-fallback tests passed, including all 25 ECMAScript whitespace code points under both `C` and `C.UTF-8` Bash locales. - Full pre-squash-equivalent run: 1,068 files passed, 2 skipped; 12,149 tests passed, 35 skipped. - CLI coverage ratchet passed with the repository include/exclude set expressed as one Vitest glob: lines 65.24%, statements 64.45%, functions 67.06%, branches 57.21%. - Python compile, Biome, ShellCheck, shfmt, source-shape, test-size, repository, secret-scan, and diff checks passed. The normal push hook passed CLI typechecking. - Main-sync validation after merging NVIDIA#6265 passed: 9 CLI files/82 tests, 6 integration files/174 tests, an additional 3 preparation tests, CLI typecheck, Biome, and diff checks. Generated-context provenance was ported into the split preflight fixtures without restoring the obsolete monolith. - Exact-head CI for `9a31537785ef2d456901de622721ed215627fdec` passed: 40 checks green, all five required contexts passed, and there were 0 failures, cancellations, or pending checks. The only skips were the expected docs-only job and two duplicate NVSkills request jobs. This includes all five CLI shards plus the aggregate, both CodeQL languages, both sandbox image builds, macOS, WSL, four self-hosted runtime checks, CodeRabbit, and both review advisors. - Exact-head live E2E for `9a31537785ef2d456901de622721ed215627fdec` passed: [`mcp-bridge`](https://github.com/NVIDIA/NemoClaw/actions/runs/28696844701), [`mcp-bridge-dev`](https://github.com/NVIDIA/NemoClaw/actions/runs/28696844719), and [`ubuntu-repo-cloud-langchain-deepagents-code`](https://github.com/NVIDIA/NemoClaw/actions/runs/28696844639). Stable and dev each passed OpenClaw, Hermes, and DCode 3/3; authenticated MCP calls passed initially and after restart, credential rotation, and rebuild, then removal denied access with no provider, policy, tunnel, or credential residue. The dedicated DCode lane passed Landlock 5/5, Python egress 14/14, headless inference 10/10, secret boundary 8/8, Tavily 6/6, and TUI 4/4; BuildKit accepted the merged generated-context handoff, and invalid-credential rebuild failure remained pre-destructive with the original sandbox, marker, and route recovered. Artifact inspection found one unchanged pre-existing harness defect: two OpenShell audit-log filtering subassertions can false-pass because awk treats `close` as reserved; runtime-output, sandbox-log, env-file immutability, and raw-secret checks passed, and this PR does not modify that E2E file. - The base `test-cli` pre-commit invocation remains affected by Vitest 4.1.9 collapsing repeated `--coverage.exclude` arguments to a zero-file/invalid summary. All other commit and push hooks passed; targeted tests and the authoritative sharded CI coverage checks provide the exact-head gate. - `npm run docs` completed with 0 errors and 2 pre-existing Fern warnings. Two documentation-writer audits confirmed the final behavior is accurately documented. ## Type of Change - [ ] Code change (feature, bug fix, or refactor) - [x] Code change with doc updates - [ ] Doc only (prose changes, no code sample modifications) - [ ] Doc only (includes code sample changes) ## Quality Gates - [x] Tests added or updated for changed behavior - [ ] Existing tests cover changed behavior — justification: - [ ] Tests not applicable — justification: - [x] Docs updated for user-facing behavior changes - [ ] Docs not applicable — justification: - [x] Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging) - [x] Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: independent security and correctness reviews passed after fixes; destructive-boundary rollback, capability migration, the process-local integrity-bound snapshot handoff (sealed memfd preferred, anonymous `O_TMPFILE` fallback), cross-language secret-pattern parity, policy fidelity, and the NVIDIA#6224 boundary were checked. - [ ] Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue: ## Verification - [x] PR description includes the DCO sign-off declaration and every commit appears as `Verified` in GitHub - [ ] Git hooks passed during commit and push, or `npx prek run --from-ref main --to-ref HEAD` passes - [x] Targeted tests pass for changed behavior - [x] Full `npm test` passes (broad runtime changes only) - [x] Quality Gates section completed with required justifications or waivers - [x] No secrets, API keys, or credentials committed - [ ] `npm run 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) --- Signed-off-by: Carlos Villela <cvillela@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Enhanced managed MCP bridge support with managed-only configuration snapshots for safer add/restart/rebuild/teardown. * Network policy protocol rules now support protocol-specific matching plus stricter `endpoint.path` validation. * **Bug Fixes** * Stronger fail-fast validation for MCP server names/hostnames and endpoint details (rejected before changes are applied). * Rebuild flows improved to preserve/replay custom policies and validate after MCP preparation, with rollback on failure. * **Documentation** * Updated setup/quickstart/reference and MCP bridge/rebuild guidance for managed MCP capability v2 behavior and stricter validation rules. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Carlos Villela <cvillela@nvidia.com>
Summary
Separates create-time onboarding intent resolution from effectful materialization while preserving the existing
prepareSandboxCreatePlanentry point and runtime behavior. This establishes a typed internal seam for later FSM work without persisting temporary paths, cleanup callbacks, or messaging credential values.Changes
SandboxCreateIntentresolver with explicit credential metadata, policy inputs, GPU arguments, and provider contributions.test-clihook was attempted, then skipped for the commits because macOS lacks GNUscript -qecand Docker; a separate CLI run reached 5,335 passing tests with 18 unrelated timeout failures in untouched files.Type of Change
Quality Gates
Verification
Verifiedin GitHubnpx prek run --from-ref main --to-ref HEADpassesnpm testpasses (broad runtime changes only)npm run docsbuilds without warnings (doc changes only)Signed-off-by: Carlos Villela cvillela@nvidia.com
Summary by CodeRabbit
Bug Fixes
Refactor
Tests