Repository navigation
fix: read Ollama context length from flat model_info keys - #1622
Conversation
Add proposal, design, spec delta, and tasks for the ollama-context-probe-fix change. The Ollama /api/show probe never matches the real flat model_info shape, so it returns undefined for stock models and the summarization trigger falls back to the 128000 default.
The Ollama /api/show endpoint returns model_info as a flat object of dotted keys (e.g. "gemma4.context_length": 131072), not nested family objects. The previous branch iterated Object.values checking family.context_length, which never matched, so the probe always fell through to the 128000-token default and summarization triggered at 102400 tokens — wrong for small local models. Scan Object.entries for keys ending in .effective_context_length (runtime cap, min(native, OLLAMA_CONTEXT_LENGTH)) with highest precedence, then .context_length (native), preserving the num_ctx fallback. Correct the unit test to the flat shape and add precedence and neither-field cases.
Sync the two ADDED requirements (flat model_info parsing, effective_context_length precedence) into the main model-context-length spec, then archive the completed change.
Implementation completeThe Ollama context-window probe fix is implemented, tested, and archived. Root cause: Fix: Scan Tests: Corrected the masking unit test to the flat shape; added a precedence case (effective wins over native) and a neither-field case. All 26 Note: PDF/Chrome and MCP-server integration tests fail in this environment for unrelated reasons (no Chrome binary, no live MCP server) — not regressions from this change. Closes #1621 |
Description
The Ollama
/api/showprobe insrc/provider/modelInfo.jsiteratedObject.values(model_info)looking for nestedfamily.context_length, but Ollama returnsmodel_infoas a flat object of dotted keys (e.g."gemma4.context_length": 131072). The branch was dead, so the probe returnedundefinedfor stock Ollama models and the summarization trigger fell back to the 128000-token default — wrong for small local models.This change rewrites the Ollama branch to scan
Object.entries(model_info)for keys ending in.effective_context_length(the runtime cap,min(native, OLLAMA_CONTEXT_LENGTH), highest precedence), then.context_length(native), preserving thenum_ctxfallback. It corrects the masking unit test to the flat shape and adds precedence and neither-field cases. The change is delivered as an OpenSpec change (ollama-context-probe-fix), now archived with its main-spec sync.Type of Change
Testing
Corrected the Ollama
/api/showunit test to the flatmodel_infoshape and added: a precedence case (botheffective_context_lengthandcontext_lengthpresent → effective wins), and a neither-field case assertingundefined. All 26modelInfounit tests pass.modelInfo.jscoverage: 100% line / 97% branch / 100% func. (PDF/Chrome and MCP-server integration tests fail in this environment for unrelated reasons — no Chrome binary, no live MCP server.)Coverage
Checklist
npm run lintpassesCloses #1621