fix(llm): context_window for o-series models and openai_post helper#4811
Merged
Conversation
…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.
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.
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.
Summary
OpenAiProvider::context_window()returnedNonefor 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 anelse if starts_with_o_digit(&self.model)branch returningSome(200_000), reusing the existing private helper already used byCompletionTokens::for_model(). Closes bug(llm): OpenAiProvider.context_window() returns None for o-series and o3-mini models #4801.openai_post()helper that sets theAuthorizationbearer token andContent-Typeheader in one place, replacing 7 identical call sites acrosssend_request(×2),send_stream_request,embed,embed_batch,chat_typed, andchat_with_tools.list_models_remote(GET, no JSON body) is intentionally unchanged. Closes refactor(llm): OpenAiProvider repeats Authorization/Content-Type headers 8 times #4800.context_window()with o-series model names.Test plan
cargo +nightly fmt --check— cleancargo clippy --workspace --features "desktop,ide,server,chat,pdf,scheduler" -- -D warnings— 0 warningsRUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler" --locked— cleancargo nextest run --config-file .github/nextest.toml --workspace --lib --bins --features "desktop,ide,server,chat,pdf,scheduler"— 10730 passedcontext_window_o1,context_window_o1_mini,context_window_o3,context_window_o3_mini,context_window_o4_mini— all pass