Skip to content

fix(inference): recompute context window on model switch - #5457

Merged
cv merged 1 commit into
mainfrom
fix/inference-recompute-context-window-on-switch
Jun 15, 2026
Merged

fix(inference): recompute context window on model switch#5457
cv merged 1 commit into
mainfrom
fix/inference-recompute-context-window-on-switch

Conversation

@hunglp6d

@hunglp6d hunglp6d commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

nemoclaw inference set kept the previous model's context window when switching, for any provider (patchOpenClawInferenceConfig cloned the prior model entry, including contextWindow). This recomputes the window for the target model — Ollama warm+probe, vLLM /v1/models max_model_len, cloud the onboard default — so the in-sandbox config matches the model instead of carrying a stale window (e.g. a 131072 cloud default kept for an Ollama model whose runtime is ~16k → silent overflow).

Related Issue

Fixes #5456

Changes

  • New src/lib/inference/context-window.tsresolveContextWindowForModel(provider, model):
    • ollama-local: warm the model, then probe its runtime context length (resolveOllamaRuntimeContextWindow).
    • vllm-local: read the running server's max_model_len from /v1/models, via a shared resolveVllmContextWindowFromModels extracted from applyVllmRuntimeContextWindow so onboard and inference set use the same source.
    • cloud providers: the onboard default (DEFAULT_CONTEXT_WINDOW = 131072, new constant in config.ts).
    • returns null when the local runtime is unreachable.
  • src/lib/inference/vllm-runtime-context.ts: extract resolveVllmContextWindowFromModels (pure parse); applyVllmRuntimeContextWindow now wraps it (behavior unchanged).
  • src/lib/actions/inference-set.ts: runInferenceSet (OpenClaw path) computes the window and passes it to patchOpenClawInferenceConfig (new optional contextWindow param → buildProviderConfig sets model.contextWindow instead of inheriting). On null it keeps the existing value and warns to run nemoclaw <name> rebuild (which re-runs onboard and re-probes).
  • Always recompute on switch — no flag/guard, since the in-memory "user pinned it" signal onboard uses is not available to a separate inference set process.
  • Tests: context-window.test.ts (helper dispatch incl. vLLM + null), existing vllm-runtime-context.test.ts (shared parse core), inference-set.test.ts (caller writes the recomputed window / preserves + warns on null).

Out of scope — Hermes: its config has no context-window field of any name (patchHermesInferenceConfig and agents/hermes/config write only model.default, base_url, provider, api_key, api_mode), so this fix has no Hermes counterpart. A per-model Hermes window would be a separate config-schema change.

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

  • Git hooks passed during commit and push, or npx prek run --from-ref main --to-ref HEAD passes
  • Targeted tests pass for changed behavior
  • Full npm test passes (broad runtime changes only)
  • Tests added or updated for new or changed behavior
  • No secrets, API keys, or credentials committed
  • Docs updated for user-facing behavior changes
  • 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: Hung Le hple@nvidia.com

Summary by CodeRabbit

  • New Features

    • Automatic context window resolution for inference models across different providers with intelligent fallback handling.
    • Context windows are now recomputed when switching between inference models for improved accuracy.
  • Tests

    • Added comprehensive test coverage for context window resolution and model switching behavior.

@copy-pr-bot

copy-pr-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jun 15, 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: 46043626-61a3-4267-b1a2-a3c71dbe4c6b

📥 Commits

Reviewing files that changed from the base of the PR and between f4f3c58 and 5c38db4.

📒 Files selected for processing (6)
  • src/lib/actions/inference-set.test.ts
  • src/lib/actions/inference-set.ts
  • src/lib/inference/config.ts
  • src/lib/inference/context-window.test.ts
  • src/lib/inference/context-window.ts
  • src/lib/inference/vllm-runtime-context.ts

📝 Walkthrough

Walkthrough

Fixes stale context window propagation on inference set model switches. Extracts vLLM /v1/models parsing into a new pure resolveVllmContextWindowFromModels function, adds a DEFAULT_CONTEXT_WINDOW constant, introduces resolveContextWindowForModel for provider-aware probing, and integrates it into runInferenceSet so the sandbox window is recomputed on every OpenClaw model switch.

Changes

Context Window Recomputation on Model Switch

Layer / File(s) Summary
vLLM parser extraction and DEFAULT_CONTEXT_WINDOW constant
src/lib/inference/config.ts, src/lib/inference/vllm-runtime-context.ts
Adds DEFAULT_CONTEXT_WINDOW = 131072 as the cloud fallback constant. Extracts all max_model_len validation from applyVllmRuntimeContextWindow into the new exported pure function resolveVllmContextWindowFromModels, which returns null for empty, malformed, non-positive, or above-ceiling values; applyVllmRuntimeContextWindow now delegates to it and early-returns on null.
New resolveContextWindowForModel module and tests
src/lib/inference/context-window.ts, src/lib/inference/context-window.test.ts
Adds ContextWindowDeps interface and resolveContextWindowForModel function that warms then probes for ollama-local, probes only for vllm-local, and returns DEFAULT_CONTEXT_WINDOW for cloud providers. Tests cover all provider paths including null-probe and unreachable-server cases.
inference-set.ts wiring and integration tests
src/lib/actions/inference-set.ts, src/lib/actions/inference-set.test.ts
Adds resolveContextWindowForModel to InferenceSetDeps and defaultDeps. Extends patchOpenClawInferenceConfig with an optional contextWindow parameter propagated into buildProviderConfig. Updates runInferenceSet to call the resolver on OpenClaw switches—logging on success or warning and preserving the existing window on null. Test helper and two new test cases validate both resolution paths.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as nemoclaw inference set
  participant runInferenceSet
  participant resolveContextWindowForModel
  participant OllamaRuntime as Ollama daemon
  participant VllmEndpoint as vLLM /v1/models

  CLI->>runInferenceSet: provider, model, sandbox
  runInferenceSet->>resolveContextWindowForModel: provider, model
  alt ollama-local
    resolveContextWindowForModel->>OllamaRuntime: warm model
    resolveContextWindowForModel->>OllamaRuntime: probe context length
    OllamaRuntime-->>resolveContextWindowForModel: number or null
  else vllm-local
    resolveContextWindowForModel->>VllmEndpoint: GET /v1/models
    VllmEndpoint-->>resolveContextWindowForModel: max_model_len number or null
  else cloud
    resolveContextWindowForModel-->>runInferenceSet: DEFAULT 131072
  end
  resolveContextWindowForModel-->>runInferenceSet: contextSize or null
  alt resolved number
    runInferenceSet->>runInferenceSet: log token count
    runInferenceSet->>runInferenceSet: patchOpenClawInferenceConfig with contextSize
  else null
    runInferenceSet->>runInferenceSet: warn indeterminate, keep existing
    runInferenceSet->>runInferenceSet: patchOpenClawInferenceConfig unchanged
  end
  runInferenceSet-->>CLI: updated sandbox config
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

v0.0.64

Suggested reviewers

  • cv
  • prekshivyas

Poem

🐇 Hop hop, the window's right at last,
No stale tokens carried from the past!
Ollama probed, vLLM queried too,
The cloud defaults to 131k—it's true.
inference set now knows exactly how,
To fit the context — recomputed, meow! 🪟✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: recomputing context window on model switch, which is the core problem being fixed.
Linked Issues check ✅ Passed The PR fully addresses the objectives from issue #5456 by implementing context window recomputation logic across providers (Ollama, vLLM, cloud) in inference-set.
Out of Scope Changes check ✅ Passed All changes directly support the context window recomputation objective. File modifications (test additions, new context-window module, vLLM refactoring, inference-set updates) are in scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/inference-recompute-context-window-on-switch

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

@github-code-quality

github-code-quality Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: TypeScript

TypeScript / code-coverage/plugin

The overall coverage in the fix/inference-recomp... branch is 96%. Coverage data for the main branch is not yet available.

Show a code coverage summary of the most covered files.
File main fix/inference-recomp... 5c38db4 +/-
nemoclaw/src/se...cret-scanner.ts 100%
nemoclaw/src/commands/slash.ts 100%
nemoclaw/src/li...bprocess-env.ts 100%
nemoclaw/src/bl...eprint/state.ts 98%
nemoclaw/src/onboard/config.ts 98%
nemoclaw/src/bl...int/snapshot.ts 97%
nemoclaw/src/bl...print/runner.ts 95%
nemoclaw/src/co...ration-state.ts 94%
nemoclaw/src/bl...ate-networks.ts 94%
nemoclaw/src/index.ts 94%

TypeScript / code-coverage/cli

The overall coverage in the fix/inference-recomp... branch is 44%. Coverage data for the main branch is not yet available.

Show a code coverage summary of the most covered files.
File main fix/inference-recomp... 5c38db4 +/-
src/lib/state/o...oard-session.ts 90%
src/lib/inference/local.ts 77%
src/lib/sandbox/config.ts 72%
src/lib/inference/nim.ts 72%
src/lib/onboard/preflight.ts 64%
src/lib/state/sandbox.ts 55%
src/lib/onboard...er-gpu-patch.ts 50%
src/lib/actions...licy-channel.ts 49%
src/lib/policy/index.ts 48%
src/lib/onboard.ts 17%

Updated June 15, 2026 09:11 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

E2E Advisor Recommendation

Required E2E: openclaw-inference-switch-vitest
Optional E2E: inference-routing-vitest, gpu-e2e, runtime-overrides-vitest

Dispatch hint: openclaw-inference-switch-vitest

Workflow run

Full advisor summary

E2E Recommendation Advisor

Base: origin/main
Head: HEAD
Confidence: high

Required E2E

  • openclaw-inference-switch-vitest (high): Directly exercises the changed nemoclaw inference set user flow for an OpenClaw sandbox: install/onboard, switch route, verify OpenShell route, registry/session state, in-sandbox openclaw.json, config hash, inference.local, and a real OpenClaw agent turn.

Optional E2E

  • inference-routing-vitest (medium): Useful adjacent coverage for gateway inference routing and provider error classification after changes in inference config/routing-adjacent code, but it does not specifically validate context-window recomputation during inference set.
  • gpu-e2e (high): Provides local Ollama end-to-end confidence on a real GPU sandbox, which is adjacent to the new Ollama context-window probing path. Optional because existing coverage does not appear to exercise nemoclaw inference set --provider ollama-local specifically.
  • runtime-overrides-vitest (medium): Adjacent coverage for generated OpenClaw config contextWindow handling and runtime override boundaries. Optional because the PR changes post-onboard inference switching rather than build-time override generation.

New E2E recommendations

  • local inference context-window switching (high): Existing E2E coverage verifies OpenClaw inference switching for hosted providers, but this PR's main new behavior is recomputing contextWindow when switching to local providers. Add an E2E that switches a running OpenClaw sandbox to ollama-local with a small model and asserts the in-sandbox openclaw.json contextWindow changes from the prior value rather than being inherited.
    • Suggested test: Add an OpenClaw local-provider inference-switch E2E covering nemoclaw inference set --provider ollama-local --model <small-model> and asserting models.providers.inference.models[0].contextWindow is the probed Ollama window.
  • vLLM context-window parsing during inference set (medium): The vLLM parser is now shared between onboard and inference set, but no existing E2E appears to validate vllm-local route switching against /v1/models max_model_len.
    • Suggested test: Add a hermetic vLLM-local inference-switch E2E using a fake /v1/models response with max_model_len, then assert openclaw.json receives that value after nemoclaw inference set --provider vllm-local.

Dispatch hint

  • Workflow: .github/workflows/e2e-vitest-scenarios.yaml
  • jobs input: openclaw-inference-switch-vitest

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Vitest E2E Scenario Recommendation

Required Vitest E2E scenarios: openclaw-inference-switch-vitest
Optional Vitest E2E scenarios: None

Dispatch required Vitest E2E scenarios:

  • gh workflow run e2e-vitest-scenarios.yaml --ref <pr-head-ref> --field jobs=openclaw-inference-switch-vitest

Workflow run

Full Vitest E2E advisor summary

Vitest E2E Scenario Advisor

Base: origin/main
Head: HEAD
Confidence: high

Required Vitest E2E scenarios

  • openclaw-inference-switch-vitest: The PR changes nemoclaw inference set and inference context-window resolution used when switching OpenClaw routes. The wired free-standing OpenClaw inference-switch Vitest job exercises the live route switch, in-sandbox config, registry, inference.local, and agent assertions for this surface.
    • Dispatch: gh workflow run e2e-vitest-scenarios.yaml --ref <pr-head-ref> --field jobs=openclaw-inference-switch-vitest

Optional Vitest E2E scenarios

  • None.

Relevant changed files

  • src/lib/actions/inference-set.ts
  • src/lib/inference/config.ts
  • src/lib/inference/context-window.ts
  • src/lib/inference/vllm-runtime-context.ts

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor

Findings: 1 needs attention, 2 worth checking, 0 nice ideas
Since last review: 0 prior items resolved, 2 still apply, 0 new items found

Review findings

🛠️ Needs attention

  • Ollama recomputation still bypasses onboarding's context-window floor (src/lib/inference/context-window.ts:43): The linked issue asks `inference set` to compute the same per-provider window as onboarding. This path warms Ollama, but then calls `resolveOllamaRuntimeContextWindow(model, null)`, which returns the daemon's raw `context_length`. Onboarding's `applyOllamaRuntimeContextWindow` instead adopts `Math.max(detected, MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW)`, raising stock below-floor daemon reports such as 4096 to the 16384-token agent floor. A switch to an Ollama model whose daemon reports 4096 would write 4096 into `openclaw.json`, so the PR still does not match onboarding for that acceptance clause.
    • Recommendation: Share the onboarding adoption logic or apply `MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW` in the `ollama-local` inference-set path, and add a regression test that a daemon-reported `context_length` of 4096 writes 16384.
    • Evidence: `context-window.ts` uses `resolveOllamaRuntimeContextWindow(model, null)`. Existing `ollama-runtime-context.ts` applies `const adopted = Math.max(detected, MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW)` in `applyOllamaRuntimeContextWindow`. The new tests cover an injected 16384 but not a below-floor 4096 daemon report.

🔎 Worth checking

  • Source-of-truth review needed: Ollama inference-set context-window adoption: The advisor marked localized patch analysis as needs_followup.
    • Recommendation: Identify the invalid state, source boundary, source-fix constraint, regression test, and removal condition before merging the localized behavior.
    • Evidence: `context-window.ts` calls `resolveOllamaRuntimeContextWindow(model, null)` while `ollama-runtime-context.ts` applies `Math.max(detected, MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW)` in `applyOllamaRuntimeContextWindow`.
  • Bound and validate the new vLLM local probe (src/lib/inference/context-window.ts:49): The new vLLM context-window probe shells out to `curl -sf http://127.0.0.1:${VLLM\_PORT}/v1/models\` without `--connect-timeout`, `--max-time`, or the repository's `buildValidatedCurlCommandArgs` helper. The URL is fixed to loopback and `VLLM_PORT` is numeric, so this does not look like a command-injection or broad SSRF issue, but a local service that accepts and stalls can hang `nemoclaw inference set` on a security-sensitive inference/network path.
    • Recommendation: Use the same bounded probe pattern as nearby local-provider curl calls, for example `buildValidatedCurlCommandArgs(["-sf", "--connect-timeout", "3", "--max-time", "5", url])`, and add a test that the vLLM probe command includes the timeout bounds.
    • Evidence: `context-window.ts` constructs `runCapture(["curl", "-sf", `http://127.0.0.1:${VLLM\_PORT}/v1/models\`\], { ignoreError: true })`; nearby Ollama runtime probing uses validated curl args with explicit connect and total timeouts.

🌱 Nice ideas

  • None.
Consider writing more tests for
  • **Runtime validation** — ollama-local inference set writes 16384 when Ollama `/api/ps` reports `context_length` 4096.. The PR changes runtime/sandbox inference switching and host-local network probing. The added unit tests cover injected helper behavior, but the highest-risk behavior is the real onboarding-parity and curl-command boundary.
  • **Runtime validation** — vllm-local context-window probe command includes `--connect-timeout` and `--max-time` and is built through validated curl args.. The PR changes runtime/sandbox inference switching and host-local network probing. The added unit tests cover injected helper behavior, but the highest-risk behavior is the real onboarding-parity and curl-command boundary.
  • **Runtime validation** — ollama-local to cloud `runInferenceSet` replaces an existing 16384 `contextWindow` with the 131072 cloud default.. The PR changes runtime/sandbox inference switching and host-local network probing. The added unit tests cover injected helper behavior, but the highest-risk behavior is the real onboarding-parity and curl-command boundary.
  • **Runtime validation** — vllm-local `runInferenceSet` keeps the existing `contextWindow` and logs the rebuild warning when `/v1/models` returns malformed JSON.. The PR changes runtime/sandbox inference switching and host-local network probing. The added unit tests cover injected helper behavior, but the highest-risk behavior is the real onboarding-parity and curl-command boundary.
  • **Runtime validation** — `patchOpenClawInferenceConfig` overwrites `contextWindow` when an explicit context-window parameter is supplied.. The PR changes runtime/sandbox inference switching and host-local network probing. The added unit tests cover injected helper behavior, but the highest-risk behavior is the real onboarding-parity and curl-command boundary.
  • **Acceptance clause:** patchOpenClawInferenceConfig PRESERVES the existing model.contextWindow when switching: buildProviderConfig clones the prior models[0] and only overrides id/name/compat. This is PROVIDER-AGNOSTIC — the prior window is kept for any switch. — add test evidence or identify existing coverage. `buildProviderConfig` now accepts `contextWindow` and overwrites `firstExistingModel.contextWindow` when a numeric value is supplied. If resolution returns null, `runInferenceSet` passes `undefined` and intentionally preserves the existing value with a warning.
  • **Acceptance clause:** onboard DOES set a per-(provider,model) window: — add test evidence or identify existing coverage. The PR adds provider-specific dispatch for Ollama, vLLM, and cloud, but the Ollama branch uses a lower-level raw resolver and does not fully match onboarding's adoption semantics.
  • **Acceptance clause:** ollama → applyOllamaRuntimeContextWindow (probes the daemon's context length) — add test evidence or identify existing coverage. `resolveContextWindowForModel` warms Ollama and probes the daemon, but it calls `resolveOllamaRuntimeContextWindow` rather than sharing `applyOllamaRuntimeContextWindow`'s 16384-token minimum-floor adoption.
Since last review details

Current findings:

  • Source-of-truth review needed: Ollama inference-set context-window adoption: The advisor marked localized patch analysis as needs_followup.
    • Recommendation: Identify the invalid state, source boundary, source-fix constraint, regression test, and removal condition before merging the localized behavior.
    • Evidence: `context-window.ts` calls `resolveOllamaRuntimeContextWindow(model, null)` while `ollama-runtime-context.ts` applies `Math.max(detected, MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW)` in `applyOllamaRuntimeContextWindow`.
  • Ollama recomputation still bypasses onboarding's context-window floor (src/lib/inference/context-window.ts:43): The linked issue asks `inference set` to compute the same per-provider window as onboarding. This path warms Ollama, but then calls `resolveOllamaRuntimeContextWindow(model, null)`, which returns the daemon's raw `context_length`. Onboarding's `applyOllamaRuntimeContextWindow` instead adopts `Math.max(detected, MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW)`, raising stock below-floor daemon reports such as 4096 to the 16384-token agent floor. A switch to an Ollama model whose daemon reports 4096 would write 4096 into `openclaw.json`, so the PR still does not match onboarding for that acceptance clause.
    • Recommendation: Share the onboarding adoption logic or apply `MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW` in the `ollama-local` inference-set path, and add a regression test that a daemon-reported `context_length` of 4096 writes 16384.
    • Evidence: `context-window.ts` uses `resolveOllamaRuntimeContextWindow(model, null)`. Existing `ollama-runtime-context.ts` applies `const adopted = Math.max(detected, MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW)` in `applyOllamaRuntimeContextWindow`. The new tests cover an injected 16384 but not a below-floor 4096 daemon report.
  • Bound and validate the new vLLM local probe (src/lib/inference/context-window.ts:49): The new vLLM context-window probe shells out to `curl -sf http://127.0.0.1:${VLLM\_PORT}/v1/models\` without `--connect-timeout`, `--max-time`, or the repository's `buildValidatedCurlCommandArgs` helper. The URL is fixed to loopback and `VLLM_PORT` is numeric, so this does not look like a command-injection or broad SSRF issue, but a local service that accepts and stalls can hang `nemoclaw inference set` on a security-sensitive inference/network path.
    • Recommendation: Use the same bounded probe pattern as nearby local-provider curl calls, for example `buildValidatedCurlCommandArgs(["-sf", "--connect-timeout", "3", "--max-time", "5", url])`, and add a test that the vLLM probe command includes the timeout bounds.
    • Evidence: `context-window.ts` constructs `runCapture(["curl", "-sf", `http://127.0.0.1:${VLLM\_PORT}/v1/models\`\], { ignoreError: true })`; nearby Ollama runtime probing uses validated curl args with explicit connect and total timeouts.

Workflow run details

This is an automated advisory review. A human maintainer must make the final merge decision.

@hunglp6d hunglp6d self-assigned this Jun 15, 2026
@hunglp6d hunglp6d added VRDC Issues and PRs submitted by NVIDIA VRDC test team. area: cli Command line interface, flags, terminal UX, or output area: inference Inference routing, serving, model selection, or outputs area: local-models Local model providers, downloads, launch, or connectivity labels Jun 15, 2026
@hunglp6d
hunglp6d marked this pull request as ready for review June 15, 2026 09:12
@github-actions github-actions Bot mentioned this pull request Jun 15, 2026
13 tasks

@jason-ma-nv jason-ma-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed this against #5458 (the auto-generated PR for the same issue, now closed) — this is the stronger fix and the one to merge.

Why this one: resolveOllamaRuntimeContextWindow only reports a window when the model is already loaded. This PR warms the model first (warmOllamaModel) and then probes, so the canonical repro from #5456 (cloud → ollama-local on a freshly-pulled model) actually detects and writes the runtime window instead of leaving it to chance. The shared resolveVllmContextWindowFromModels parser (used by both onboard and inference set) and the per-switch log/warning are also nice — the warning pointing users to rebuild directly addresses the missing-feedback note in the issue.

Three things worth grafting from #5458 before merge:

  1. Floor the Ollama value at the agent minimum. onboard does Math.max(detected, MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW) (16384). resolveContextWindowForModel currently writes the raw probed value, so a sub-16k model would land below onboard's floor and diverge from the onboard path the issue asks us to mirror.

  2. Add timeouts to the vLLM probe. probeVllmContextWindow runs curl -sf http://127.0.0.1:<port>/v1/models with no --connect-timeout/--max-time. If the port is open but the server is slow/wedged, inference set can hang. #5458 used --connect-timeout 3 --max-time 5 with validated curl args.

  3. Document the new behavior. #5458 added a paragraph to docs/inference/switch-inference-providers.mdx stating that inference set recomputes the window per provider on a switch. Worth pulling in (drop the stray $$ prefix it had in the code span).

Minor: the fix commit has an empty body and the PR description has CRLF line endings — not blocking.

Note: I verified the warm/probe and floor semantics from the source rather than a live Ollama run, so the Ollama detection path is worth a quick manual sanity check on a host with Ollama before merge.

@cv
cv merged commit 2bdee17 into main Jun 15, 2026
51 checks passed
@cv
cv deleted the fix/inference-recompute-context-window-on-switch branch June 15, 2026 15:45
@cv cv added the v0.0.65 label Jun 15, 2026
@miyoungc miyoungc mentioned this pull request Jun 16, 2026
13 tasks
cv pushed a commit that referenced this pull request Jun 17, 2026
## Summary
Refreshes release-prep documentation for NemoClaw v0.0.65.
Adds the v0.0.65 release-notes section and refreshes generated
`nemoclaw-user-*` skills from the Fern MDX source docs.

## Changes
- Added the v0.0.65 release notes to `docs/about/release-notes.mdx` with
links to the deeper docs pages for lifecycle, troubleshooting,
inference, CLI commands, messaging, credentials, network policy, Hermes,
and sub-agents.
- Regenerated the `nemoclaw-user-*` skills with
`scripts/docs-to-skills.py` so release-prep skill output matches the
merged source docs.
- Used the v0.0.65 announcement discussion as release context:
#5472.

## Source Summary
- #2492 -> `docs/about/release-notes.mdx`: Documents deadline-based
gateway wait reliability in the v0.0.65 recovery summary.
- #4958 -> `docs/about/release-notes.mdx`: Documents re-execed OpenClaw
gateway health check recovery in the sandbox recovery summary.
- #5163 -> `docs/about/release-notes.mdx`: Documents safer uninstall TTY
confirmation behavior in the day-two CLI summary.
- #5178 -> `docs/about/release-notes.mdx`: Documents fail-closed config
restore merge behavior in the rebuild and restore summary.
- #5179 -> `docs/about/release-notes.mdx`: Documents WeChat QR token
redaction in the messaging summary.
- #5182 -> `docs/about/release-notes.mdx`: Documents sustained gateway
serving checks in the recovery summary.
- #5194 -> `docs/about/release-notes.mdx`: Documents model-router
teardown during uninstall in the day-two CLI summary.
- #5195 -> `docs/about/release-notes.mdx`: Documents Shields
auto-restore lock reconfirmation in the rebuild and restore summary.
- #5198 -> `docs/about/release-notes.mdx`: Documents Docker Desktop WSL
CDI injection failure handling in the onboarding diagnostics summary.
- #5201 -> `docs/about/release-notes.mdx`: Documents sandbox
download/upload wrappers and sessions export in the day-two CLI summary.
- #5205 -> `docs/about/release-notes.mdx`: Documents reporter-owned
model metadata preservation in the rebuild and restore summary.
- #5214 -> `docs/about/release-notes.mdx`: Documents managed vLLM model
preflight before side effects in the inference setup summary.
- #5215 -> `docs/about/release-notes.mdx`: Documents managed vLLM extra
serve arguments in the inference setup summary.
- #5216 -> `docs/about/release-notes.mdx`: Documents silent OpenClaw
runtime fallback surfacing in the onboarding diagnostics summary.
- #5225 -> `docs/about/release-notes.mdx`: Documents persisted sandbox
gateway lookup in the gateway recovery summary.
- #5238 -> `docs/about/release-notes.mdx`: Documents sub-agent gateway
dial-back through the sandbox interface in the Hermes and sub-agent
summary.
- #5248 -> `docs/about/release-notes.mdx`: Documents Discord per-account
proxy resolution in the messaging summary.
- #5264 -> `docs/about/release-notes.mdx`: Documents reserved Hermes
port `8642` handling in the Hermes compatibility summary.
- #5267 -> `docs/about/release-notes.mdx`: Documents the narrower Hermes
baseline policy in the Hermes compatibility summary.
- #5321 -> `docs/about/release-notes.mdx`: Documents restored gateway
guard chains in the gateway recovery summary.
- #5328 -> `docs/about/release-notes.mdx`: Documents compact persisted
messaging plans in the messaging summary.
- #5338 -> `docs/about/release-notes.mdx`: Documents manifest channel
migration in the messaging summary.
- #5352 -> `docs/about/release-notes.mdx`: Documents persisted agent
preservation through registry recovery in the rebuild and restore
summary.
- #5371 ->
`.agents/skills/nemoclaw-user-reference/references/commands.md`:
Refreshes generated skill output for custom build cache and
layer-ordering source docs.
- #5379 -> `docs/about/release-notes.mdx`: Documents dashboard port
allocation across multiple NemoClaw gateways in the recovery summary.
- #5382 -> `docs/about/release-notes.mdx`: Documents recovery when an
active gateway has no sandbox spec in the recovery summary.
- #5389 ->
`.agents/skills/nemoclaw-user-reference/references/troubleshooting.md`:
Refreshes generated skill output for declared agent `forward_ports`
recovery source docs.
- #5400 -> `docs/about/release-notes.mdx`: Documents bounded compatible
endpoint probes in the inference setup summary.
- #5410 -> `docs/about/release-notes.mdx`: Documents provider credential
hash removal from sandbox registry entries in the messaging summary.
- #5418 -> `docs/about/release-notes.mdx`: Documents summarized
inference validation failures in the onboarding diagnostics summary.
- #5457 -> `docs/about/release-notes.mdx`: Documents context-window
recomputation after runtime model switches in the inference setup
summary.
- #5463 -> `docs/about/release-notes.mdx`: Documents cleanup of
hard-coded messaging channel stragglers in the messaging summary.

## Skipped
- #5366 matched `docs/.docs-skip` entries through skipped experimental
paths, so this PR does not add new release-note text for that commit.

## Type of Change
- [ ] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [x] Doc only (includes code sample changes)

## Verification
- [x] Git hooks passed during commit and push, or `npx prek run
--from-ref main --to-ref HEAD` passes
- [ ] Targeted tests pass for changed behavior
- [ ] Full `npm test` passes (broad runtime changes only)
- [ ] 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
- [ ] `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)

Verification notes:
- `npm run docs` passed after rerunning outside the sandbox. Fern
reported 0 errors and 1 hidden warning.
- The first sandboxed `npm run docs` attempt failed before validation
because `tsx` could not create its local IPC pipe under sandbox
restrictions.
- `npm run build:cli` passed before push to refresh the local `dist/`
artifacts used by the CLI typecheck hook.
- `npm test` was not run because this is a docs-only release refresh.

---
Signed-off-by: Miyoung Choi <miyoungc@nvidia.com>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Released NemoClaw v0.0.65 with improved gateway/sandbox recovery,
safer day-two workflows, and enhanced Hermes compatibility.
* Added managed vLLM extra-arguments configuration via
`NEMOCLAW_VLLM_EXTRA_ARGS_JSON`.
* Added Hermes troubleshooting guidance for port forwarding and health
checks.

* **Documentation**
* Updated NVIDIA Endpoints/NIM setup and examples to use
`NVIDIA_INFERENCE_API_KEY`.
* Refined NVIDIA network policy and Model Router API base configuration.
* Expanded CLI/environment variable documentation (including sub-agent
gateway connectivity) and plugin build performance tips.

* **Tests**
  * Expanded Vitest-backed E2E release validation coverage.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli Command line interface, flags, terminal UX, or output area: inference Inference routing, serving, model selection, or outputs area: local-models Local model providers, downloads, launch, or connectivity VRDC Issues and PRs submitted by NVIDIA VRDC test team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Inference][CLI] inference set does not recompute the context window on model switch — stale window carries over (any provider)

4 participants