Skip to content

fix: read Ollama context length from flat model_info keys - #1622

Merged
avoidwork merged 3 commits into
mainfrom
fix/ollama-context-probe-fix
Nov 1, 2026
Merged

avoidwork merged 3 commits into
mainfrom
fix/ollama-context-probe-fix

Conversation

@avoidwork

@avoidwork avoidwork commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Description

The Ollama /api/show probe in src/provider/modelInfo.js iterated Object.values(model_info) looking for nested family.context_length, but Ollama returns model_info as a flat object of dotted keys (e.g. "gemma4.context_length": 131072). The branch was dead, so the probe returned undefined for 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 the num_ctx fallback. 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

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)
  • Performance improvement
  • CI / build / tooling

Testing

Corrected the Ollama /api/show unit test to the flat model_info shape and added: a precedence case (both effective_context_length and context_length present → effective wins), and a neither-field case asserting undefined. All 26 modelInfo unit tests pass. modelInfo.js coverage: 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

  • Line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with maintained line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

Closes #1621

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.
@avoidwork avoidwork added the bug Something isn't working label Nov 1, 2026
@avoidwork avoidwork self-assigned this Nov 1, 2026
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.
@avoidwork avoidwork changed the title chore: add OpenSpec change for Ollama context-window probe fix fix: read Ollama context length from flat model_info keys Nov 1, 2026
@avoidwork

Copy link
Copy Markdown
Owner Author

Implementation complete

The Ollama context-window probe fix is implemented, tested, and archived.

Root cause: src/provider/modelInfo.js iterated Object.values(model_info) looking for nested family.context_length, but Ollama's /api/show returns model_info as a flat object of dotted keys (e.g. "gemma4.context_length": 131072). The branch was dead, so the probe returned undefined for stock Ollama models and the summarization trigger fell back to the 128000-token default — wrong for small local models.

Fix: Scan Object.entries(model_info) for keys ending in .effective_context_length (runtime cap, min(native, OLLAMA_CONTEXT_LENGTH), highest precedence), then .context_length (native), preserving the num_ctx fallback.

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 modelInfo unit tests pass. modelInfo.js coverage: 100% line / 97% branch / 100% func.

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

@avoidwork
avoidwork merged commit c1312a6 into main Nov 1, 2026
2 checks passed
@avoidwork
avoidwork deleted the fix/ollama-context-probe-fix branch November 1, 2026 01:17
@avoidwork avoidwork mentioned this pull request Nov 1, 2026
6 of 12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Ollama context-window probe never matches the real /api/show shape

1 participant