Skip to content

fix(llm): context_window for o-series models and openai_post helper#4811

Merged
bug-ops merged 2 commits into
mainfrom
4801-openai-context-window
Jun 5, 2026
Merged

fix(llm): context_window for o-series models and openai_post helper#4811
bug-ops merged 2 commits into
mainfrom
4801-openai-context-window

Conversation

@bug-ops

@bug-ops bug-ops commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • OpenAiProvider::context_window() returned None for o-series models (o1, o1-mini, o3, o3-mini, o4-mini), causing silent context overflow when the budget manager used this value for trimming decisions. The fix adds an else if starts_with_o_digit(&self.model) branch returning Some(200_000), reusing the existing private helper already used by CompletionTokens::for_model(). Closes bug(llm): OpenAiProvider.context_window() returns None for o-series and o3-mini models #4801.
  • Extracts a private openai_post() helper that sets the Authorization bearer token and Content-Type header in one place, replacing 7 identical call sites across send_request (×2), send_stream_request, embed, embed_batch, chat_typed, and chat_with_tools. list_models_remote (GET, no JSON body) is intentionally unchanged. Closes refactor(llm): OpenAiProvider repeats Authorization/Content-Type headers 8 times #4800.
  • Adds 5 unit tests for context_window() with o-series model names.

Test plan

  • cargo +nightly fmt --check — clean
  • cargo clippy --workspace --features "desktop,ide,server,chat,pdf,scheduler" -- -D warnings — 0 warnings
  • RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler" --locked — clean
  • cargo nextest run --config-file .github/nextest.toml --workspace --lib --bins --features "desktop,ide,server,chat,pdf,scheduler" — 10730 passed
  • New tests: context_window_o1, context_window_o1_mini, context_window_o3, context_window_o3_mini, context_window_o4_mini — all pass

…helper

OpenAiProvider::context_window() returned None for o1, o1-mini, o3,
o3-mini, and o4-mini, causing silent context overflow when the budget
manager used this value for trimming decisions. Add an
`else if starts_with_o_digit(&self.model)` branch returning
Some(200_000) — reuses the existing private helper already used by
CompletionTokens::for_model(). Closes #4801.

Extract a private openai_post() helper that sets the Authorization
bearer token and Content-Type header in one place, replacing 7
identical call sites spread across send_request (×2),
send_stream_request, embed, embed_batch, chat_typed, and
chat_with_tools. list_models_remote (GET, no JSON body) is
intentionally unchanged. Closes #4800.

Adds 5 unit tests for context_window() with o-series model names.
@github-actions github-actions Bot added documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes bug Something isn't working size/M Medium PR (51-200 lines) labels Jun 5, 2026
@bug-ops bug-ops enabled auto-merge (squash) June 5, 2026 12:59
Add `///` doc comment to the private openai_post() helper per project
doc conventions. Remove CC-prefix from CHANGELOG bullet text to conform
to Keep a Changelog style.
@bug-ops bug-ops merged commit a6badd3 into main Jun 5, 2026
32 checks passed
@bug-ops bug-ops deleted the 4801-openai-context-window branch June 5, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

1 participant