Skip to content

fix(inference): pre-flight sandbox read before mutating the inference route - #7004

Closed
rluo8 wants to merge 3 commits into
NVIDIA:mainfrom
rluo8:fix/6997-inference-set-preflight-sandbox
Closed

fix(inference): pre-flight sandbox read before mutating the inference route#7004
rluo8 wants to merge 3 commits into
NVIDIA:mainfrom
rluo8:fix/6997-inference-set-preflight-sandbox

Conversation

@rluo8

@rluo8 rluo8 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

nemoclaw inference set --no-verify --sandbox <name> against a sandbox whose container is stopped crashed with an uncaught SandboxConfigError (raw Node stack, exit 1) and left a half-applied switch: the gateway route and registry were already mutated to the new model while the in-sandbox openclaw.json still pointed at the old one. The in-sandbox config is now read as a pre-flight gate before any mutation, so an unreadable config aborts cleanly and atomically (nothing mutated) with a clear message instead of a stack trace.

Related Issue

Closes #6997

Changes

  • src/lib/actions/inference-set.ts: add readInSandboxConfigOrFail(), which reads the in-sandbox config and converts a SandboxConfigError (the config could not be read or parsed — most commonly a stopped sandbox) into a clean InferenceSetError, preserving the original diagnostic lines and exit code. It appends a Start the sandbox and retry. hint only for the stopped-sandbox case (the one that reports Is the sandbox running?) — not for a corrupt/unparseable config, which starting the sandbox would not fix. Call it before the gateway-route mutation (captureOpenshell inference set) and the registry writes, replacing the former crash-prone read that ran after those mutations. Protected by the tests below.
  • src/lib/actions/inference-set-degraded-state.test.ts: rewrite the read-failure case to exercise the real SandboxConfigError path and assert zero mutation (route-set, updateSandbox, writeSandboxConfig, restartSandboxGateway all uncalled) — locking the ordering so moving the read back after the mutations fails the test. The prior assertion asserted the buggy half-applied state.
  • test/inference-set-preflight.test.ts: unit tests for the helper — readable path, stopped-sandbox conversion (error type, message, exit code), parse-failure conversion (no start hint), and pass-through of unrelated errors.

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)

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: behavior/error-message change on an existing command; no documented behavior contract changes.
  • Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging)
  • Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification:
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • Normal pre-commit, commit-msg, and pre-push hooks passed, or npm run check:diff passed when hooks were skipped or unavailable
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — command/result or justification:
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result:
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Rui Luo ruluo@nvidia.com

Summary by CodeRabbit

  • Bug Fixes

    • Added a pre-flight validation step for sandbox configuration before any gateway or sandbox updates.
    • Improved error handling when sandbox config reads fail, including a “Start the sandbox and retry” hint for stopped sandboxes.
    • Prevented partial/incomplete updates by aborting early when pre-flight config checks fail.
  • Tests

    • Updated degraded-state coverage to ensure no gateway route updates or sandbox updates occur when config pre-flight fails.
    • Added new tests for the pre-flight config helper, covering success, stopped-sandbox errors, parse failures, and unexpected errors.

… route

Signed-off-by: Rui Luo <ruluo@nvidia.com>
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e2d9c35b-3dcf-45a5-8559-7aaccb0f7c54

📥 Commits

Reviewing files that changed from the base of the PR and between a197a24 and ca75e50.

📒 Files selected for processing (1)
  • test/inference-set-preflight.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/inference-set-preflight.test.ts

📝 Walkthrough

Walkthrough

runInferenceSet now reads sandbox configuration before mutating gateway routes or sandbox state. Read failures become actionable InferenceSetError instances, with coverage for stopped, parse, successful, and unrelated errors.

Changes

Inference set preflight

Layer / File(s) Summary
Configuration read error handling
src/lib/actions/inference-set.ts, test/inference-set-preflight.test.ts
Adds readInSandboxConfigOrFail to preserve diagnostics, translate SandboxConfigError, append stopped-sandbox retry guidance, and validate helper behavior.
Inference-set preflight gate
src/lib/actions/inference-set.ts, src/lib/actions/inference-set-degraded-state.test.ts
Reads configuration before gateway or sandbox mutations, reuses the result, and verifies failed reads perform no mutable updates.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: bug-fix, area: sandbox

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant runInferenceSetWithoutHostLock
  participant readSandboxConfig
  participant Gateway
  participant updateSandbox
  CLI->>runInferenceSetWithoutHostLock: set inference configuration
  runInferenceSetWithoutHostLock->>readSandboxConfig: read sandbox config
  readSandboxConfig-->>runInferenceSetWithoutHostLock: config or translated error
  runInferenceSetWithoutHostLock->>Gateway: mutate route after successful preflight
  runInferenceSetWithoutHostLock->>updateSandbox: update sandbox state
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: reading sandbox config before mutating the inference route.
Linked Issues check ✅ Passed The changes match #6997 by preflighting the sandbox read, converting SandboxConfigError to InferenceSetError, and avoiding mutations on failure.
Out of Scope Changes check ✅ Passed The modified code and tests are tightly scoped to the inference-set preflight failure flow and related error handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — Informational

Advisor assessment: Informational / high confidence
Next action: No advisor follow-up needed.
Findings: 0 blockers · 0 warnings · 0 suggestions
Status: No actionable findings remain in the canonical review ledger.

Model lanes

  • GPT-5.6 Terra (primary): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 1 warning · 0 suggestions
  • Model comparison: normalized findings differ; normalized E2E selections differ; Nemotron reported the same number of blockers, 1 more warning, the same number of suggestions.

Nemotron output stays in workflow artifacts and does not change the assessment above.

E2E guidance

Advisory only. E2E / PR Gate selects and runs jobs independently.

Recommended E2E: inference-routing, network-policy

2 optional E2E recommendations
  • openclaw-inference-switch
  • hermes-inference-switch

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@test/inference-set-preflight.test.ts`:
- Line 16: Update the describe block title for readInSandboxConfigOrFail so the
issue reference appears as the required final “(`#6997`)” suffix, after the test
description.
🪄 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: Enterprise

Run ID: e991ba3e-ab43-45a4-86bc-85b094c96997

📥 Commits

Reviewing files that changed from the base of the PR and between c1bda80 and a197a24.

📒 Files selected for processing (3)
  • src/lib/actions/inference-set-degraded-state.test.ts
  • src/lib/actions/inference-set.ts
  • test/inference-set-preflight.test.ts

Comment thread test/inference-set-preflight.test.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants