Repository navigation
fix(server): read Ollama's reported context window - #1217
Merged
danyaberezun merged 3 commits intoNov 11, 2026
Merged
Conversation
Custom endpoint discovery only parsed a Modelfile num_ctx line from /api/show. Models that omit it, including every Ollama cloud model, report the window as model_info["<architecture>.context_length"] and were saved with pi's 128K default. num_ctx still wins when a Modelfile sets it, because ThinkRail does not send a context size and that parameter is the window the server runs. /api/version still has to succeed before /api/show is trusted; Ollama cloud returns a version, so that check was not dropping the window.
markxu (markjoin123)
requested review from
Olga Lavrichenko (OLavrik),
Rustam Sadykov (SBOne-Kenobi),
danyaberezun and
Rinat S (rsolmano)
as code owners
November 5, 2026 14:09
A missing Modelfile num_ctx is not the runtime window. Local Ollama loads OLLAMA_CONTEXT_LENGTH and silently truncates past it, so saving model_info context_length turns off compaction and skips overflow recovery. Use that metadata length only for Ollama cloud (host ollama.com), which serves the full reported window. Version 0.0.0 is not the signal: source-built local servers report it too.
danyaberezun
requested review from
Andrey Markin (Mark-Life) and
artyomxx
as code owners
November 11, 2026 14:43
danyaberezun
approved these changes
Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A custom Ollama endpoint saved every model with a 128K context window.
/v1/modelshas no context fields, and discovery only read a Modelfilenum_ctxline from/api/show. Models that don't set one report the window onmodel_info["<architecture>.context_length"], so nothing was stored and pi's 128K default applied. Compaction and overflow detection then treated a much larger model as 128K.Approach
When
/api/showhas nonum_ctx, Ollama cloud (ollama.com) reports the window it serves onmodel_info["<architecture>.context_length"], so discovery now uses that value there. The architecture may be empty (nemotron-3-ultrareports.context_length). A nested key such as*.vision.context_lengthis not the text window.Local and self-hosted endpoints are different: the runtime window comes from
OLLAMA_CONTEXT_LENGTH, which can be smaller than the model's metadata. On any host other thanollama.comthe context stays unknown unless a Modelfilenum_ctxor the/v1/modelslisting set one, so pi keeps its default and compaction behaves as before.A Modelfile
num_ctxstill wins, and a context already reported by/v1/modelsstill wins over both./api/versionstill has to succeed before/api/showis trusted; the version string isn't used to tell cloud from local, because a source build also reports0.0.0.Changes
num_ctxis absent, only forollama.com.num_ctxoverriding it, an empty architecture, a listing length winning, and a failed/api/version.Screenshots
Not applicable, no frontend changes.
Related issues
Fixes #1211
Checklist
bun run lint,bun run typecheck,bun run test(packages/server: 2293 pass, 6 skip, 0 fail)bun run e2e, orbun run e2e:fullwhen touching agent behavior)SPEC.md/ top-level specs updated to reflect any boundary, contract, or behavior change