fix: address issue #5456 - #5458
Conversation
`nemoclaw inference set` carried the previous model's `contextWindow` into the new model's config for any provider, because buildProviderConfig cloned the prior models[0] and only overrode id/name/compat. onboard computes a per-provider window but inference set never did, so a cloud->ollama switch kept the 131072 window (daemon truncates ~16k -> silent overflow) and an ollama->cloud switch left the cloud model capped at the stale Ollama window. Add a resolveContextWindow dependency to runInferenceSet that mirrors onboard per provider: probe the Ollama runtime length (floored at the agent minimum) for ollama-local, read max_model_len for vllm-local, and apply the 131072 cloud default otherwise. patchOpenClawInferenceConfig now replaces the window with the recomputed value, drops it when no runtime window is available, and preserves it for direct callers that pass nothing (e.g. connect route repair). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
ChangesContext-window recomputation on model switch
Sequence Diagram(s)sequenceDiagram
actor User
participant runInferenceSet
participant defaultResolveContextWindow
participant resolveVllmRuntimeContextWindow as resolveVllmRuntimeContextWindow (local.ts)
participant vLLM as vLLM /v1/models
participant patchOpenClawInferenceConfig
participant buildProviderConfig
User->>runInferenceSet: inference set --provider vllm-local --model mymodel
runInferenceSet->>defaultResolveContextWindow: provider=vllm-local, model=mymodel
defaultResolveContextWindow->>resolveVllmRuntimeContextWindow: modelId=mymodel
resolveVllmRuntimeContextWindow->>vLLM: GET /v1/models (curl)
vLLM-->>resolveVllmRuntimeContextWindow: JSON with max_model_len
resolveVllmRuntimeContextWindow-->>defaultResolveContextWindow: number | null
defaultResolveContextWindow-->>runInferenceSet: contextWindow
runInferenceSet->>patchOpenClawInferenceConfig: config, provider, model, contextWindow
patchOpenClawInferenceConfig->>buildProviderConfig: ..., contextWindow
buildProviderConfig-->>patchOpenClawInferenceConfig: sets or deletes contextWindow field
patchOpenClawInferenceConfig-->>runInferenceSet: updated OpenClaw config
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
|
🌿 Preview your docs: https://nvidia-preview-pr-5458.docs.buildwithfern.com/nemoclaw |
E2E Advisor RecommendationRequired E2E: Dispatch hint: Full advisor summaryE2E Recommendation AdvisorBase: Required E2E
Optional E2E
New E2E recommendations
Dispatch hint
|
Vitest E2E Scenario RecommendationRequired Vitest E2E scenarios: Dispatch required Vitest E2E scenarios:
Full Vitest E2E advisor summaryVitest E2E Scenario AdvisorBase: Required Vitest E2E scenarios
Optional Vitest E2E scenarios
Relevant changed files
|
PR Review AdvisorFindings: 0 needs attention, 3 worth checking, 1 nice ideas Review findings🛠️ Needs attention
🔎 Worth checking
🌱 Nice ideas
Consider writing more tests for
This is an automated advisory review. A human maintainer must make the final merge decision. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/lib/actions/inference-set.ts (1)
455-457: Run the targeted inference-switch E2E jobs before merge.Because this path updates live route switching and config patching, run the two recommended jobs to validate both agent flows end to end:
gh workflow run nightly-e2e.yaml --ref <branch> -f jobs=openclaw-inference-switch-e2e,hermes-inference-switch-e2eAs per coding guidelines:
src/lib/actions/inference-set.tsincludes an explicit E2E recommendation foropenclaw-inference-switch-e2eandhermes-inference-switch-e2e.🤖 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/actions/inference-set.ts` around lines 455 - 457, Before merging this pull request, run the specified E2E test workflows to validate the inference switching and context window configuration changes in the resolveContextWindow call path. Execute the workflow command provided in the comment using the gh CLI with your branch name, running both the openclaw-inference-switch-e2e and hermes-inference-switch-e2e jobs to ensure agent flows work end-to-end with the live route switching and config patching modifications.
🤖 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.
Nitpick comments:
In `@src/lib/actions/inference-set.ts`:
- Around line 455-457: Before merging this pull request, run the specified E2E
test workflows to validate the inference switching and context window
configuration changes in the resolveContextWindow call path. Execute the
workflow command provided in the comment using the gh CLI with your branch name,
running both the openclaw-inference-switch-e2e and hermes-inference-switch-e2e
jobs to ensure agent flows work end-to-end with the live route switching and
config patching modifications.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: ac9dd04c-6279-4c63-a049-b5f36c937d62
📒 Files selected for processing (6)
docs/inference/switch-inference-providers.mdxsrc/lib/actions/inference-set.test.tssrc/lib/actions/inference-set.tssrc/lib/inference/config.tssrc/lib/inference/local.tssrc/lib/inference/vllm-runtime-context.ts
|
Closing in favor of #5457, which fixes the same issue (#5456). Both PRs recompute the context window on an
#5457 also surfaces the recomputed window to the user (logs the value / warns to A few pieces from this PR are worth carrying into #5457 — noted in a review comment there (Ollama floor at 16384, vLLM probe timeouts, and the docs paragraph). This PR was auto-created by the issue auto-fix pipeline. |
Summary
nemoclaw inference set now recomputes the model context window on a model switch instead of carrying the previous model's contextWindow into the new model's config. Root cause: buildProviderConfig cloned the prior models[0] and only overrode id/name/compat, preserving the stale contextWindow for any provider switch (onboard computed a per-provider window, but inference set never did). Added a resolveContextWindow dependency to runInferenceSet whose default mirrors onboard per provider: probe the Ollama runtime context length (floored at MIN_AUTODETECTED_OLLAMA_CONTEXT_WINDOW=16384) for ollama-local, read max_model_len from /v1/models for vllm-local, and fall back to the flat 131072 cloud default otherwise. patchOpenClawInferenceConfig/buildProviderConfig now accept the recomputed window: a positive number replaces the stale value, null drops it (so a failed local probe falls back to the agent default rather than a wrong stale window), and undefined preserves the existing value for direct callers (e.g. connect route repair). Added a pure resolveVllmRuntimeContextWindow helper in vllm-runtime-context.ts and a host-probe wrapper in local.ts, plus a shared DEFAULT_CLOUD_CONTEXT_WINDOW constant in config.ts. The fix is OpenClaw-specific because the contextWindow field lives only in the OpenClaw config; Hermes config has no per-model contextWindow field.
Related Issue
Fixes #5456
Changes
auto_fix/auto_fix_recent_issues.py.Type of Change
Verification
npx prek run --from-ref main --to-ref HEADpassesnpm testpasses (broad runtime changes only)npm run docsbuilds without warnings (doc changes only)Verification details reported by Claude Code:
npx vitest run --project cli src/lib/actions/inference-set.test.tsnpm run build:clinpx vitest run --project cli src/lib/inference/ src/lib/actions/inference-set.test.tsnpm run typecheck:clinpx vitest run --project cli src/lib/actions/inference-set.test.ts src/lib/actions/sandbox/connect-route-repair.test.ts src/lib/inference/vllm-runtime-context.test.ts src/lib/inference/ollama-runtime-context.test.ts src/lib/state/openclaw-config-merge.test.tsnpx biome check --write src/lib/actions/inference-set.ts src/lib/actions/inference-set.test.ts src/lib/inference/local.ts src/lib/inference/vllm-runtime-context.ts src/lib/inference/config.tsSigned-off-by: Jason Ma jama@nvidia.com
Summary by CodeRabbit
New Features
Bug Fixes
Documentation