Skip to content

Refactor context window calcs#33

Open
gherlein wants to merge 2 commits into
dimetron:mainfrom
gherlein:refactor-context-window-calcs
Open

Refactor context window calcs#33
gherlein wants to merge 2 commits into
dimetron:mainfrom
gherlein:refactor-context-window-calcs

Conversation

@gherlein

Copy link
Copy Markdown

Summary

  • The context window display ("X / Yk Z%") was hardcoded via a model-name prefix map. For Ollama models
    this was often wrong — e.g., all qwen* models were hardcoded to 4 096 tokens regardless of actual
    configuration.
  • Adds OllamaContextWindowSize() to the provider package, which calls the Ollama /api/show endpoint
    at startup and reads the real value: num_ctx from the Parameters field (user/modelfile-configured
    window) or *.context_length from ModelInfo (native model capacity, works across llama, qwen2, gemma,
    etc.).
  • Both CLI and ACP server startup paths now query Ollama for the actual size and fall back to the
    hardcoded map if the query fails.

Test plan

  • [X ] Start pi with an Ollama model (e.g., ollama/qwen2.5-coder:32b) and confirm the context bar shows
    the correct window size instead of 4.1k.
  • go test ./internal/provider/... passes.

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 5.55556% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.85%. Comparing base (da7a08f) to head (455344f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
internal/provider/ollama.go 0.00% 26 Missing ⚠️
internal/acp/server/runtime.go 0.00% 5 Missing ⚠️
internal/cli/cli.go 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #33      +/-   ##
==========================================
- Coverage   80.96%   80.85%   -0.12%     
==========================================
  Files         174      174              
  Lines       23564    23598      +34     
==========================================
  Hits        19079    19079              
- Misses       3367     3400      +33     
- Partials     1118     1119       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant