fix: forward resolved context limit to Ollama#579
Conversation
There was a problem hiding this comment.
Thanks for the contribution - I think the overall direction is correct, and forwarding the resolved context limit to Ollama is absolutely the right approach.
However, after validating the issue and tracing the context resolution flow, I don't think we can confidently close this issue yet.
The main blocker is the subagent precedence issue. The original feature request explicitly calls out subagents using different context limits, but the current resolution order means a subagent override is ignored whenever a per-model contextWindows entry exists. I was able to reproduce and verify this behavior locally.
Additionally, I wasn't able to verify whether Ollama's OpenAI-compatible endpoint actually honors the injected options.num_ctx field at runtime. Since the effectiveness of this fix depends on that behavior, I'd like to see either manual validation or automated coverage demonstrating that the runtime context limit changes when using the /v1/chat/completions endpoint.
Once the subagent override issue is addressed and the Ollama runtime behavior is verified, I'd be happy to take another look.
Description
This PR fixes the missing runtime half of #485 for Ollama-backed models.
Nanocoder already let users configure context limits via:
/context-max/--context-maxcontextWindowcontextWindowscontextWindowBut those limits were only used inside Nanocoder for context accounting and auto-compact decisions. They were not being forwarded to Ollama itself, so the actual model runtime could still use a different context size.
This change now forwards the resolved Nanocoder context limit to Ollama as
options.num_ctxon each request, so the configured limit affects the real runtime behavior too.It also updates the docs to make that behavior explicit.
Type of Change
Testing
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Ran:
npm exec --yes pnpm -- test:ava source/ai-sdk-client/chat/provider-options.spec.tsnpm exec --yes pnpm -- test:typesnpm exec --yes pnpm -- exec biome check source/ai-sdk-client/chat/provider-options.ts source/ai-sdk-client/chat/provider-options.spec.ts source/ai-sdk-client/chat/chat-handler.ts docs/configuration/providers/ollama.md docs/features/subagents.mdManual Testing
Manual testing was not run in this environment.
Checklist
Closes #485