Repository navigation
Retry with max_completion_tokens when the endpoint rejects max_tokens - #1232
Open
Schro-code wants to merge 1 commit into
Open
Schro-code wants to merge 1 commit into
Schro-code wants to merge 1 commit into
Conversation
WaylandYang
requested changes
Oct 14, 2026
WaylandYang
left a comment
Contributor
There was a problem hiding this comment.
Thank you, the problem is real and reading error.param / error.code is the right way to detect it.
Two things to change:
- In
chat_at_streamingeach attempt rewritesbody["max_tokens"], so after the rename the next request carries it again and the retry can loop without end. - Every call pays the 400 again (once per chunk). Learn the parameter name and a rejected temperature once on the client, as
completion_ceilingalready does.
Please add a wiremock test like the existing "max_tokens is too large" one, and run cargo fmt (the lint failure). Thanks again.
Signed-off-by: Zhoulu <ldazzh@lineadirecta.es>
Schro-code
force-pushed
the
fix/compat-retries-unsupported-max-tokens
branch
from
October 15, 2026 08:24
522599f to
19c26e1
Compare
Author
|
Thanks for the review. Addressed all three points:
Left out temperature deliberately: silently dropping temperature=0 switches extraction from deterministic to sampling, which felt like a semantic decision for the operator rather than a silent fallback. Happy to add it if you disagree. |
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.
Why
Newer OpenAI reasoning models (o1, o3, GPT-5 family) renamed
max_tokenstomax_completion_tokens. Sending the old name returns a 400 witherror.code: "unsupported_parameter", and every extraction chunk fails.What changes
An
AtomicBoolonLlmClient(use_max_completion_tokens) learns the rename from a single 400 and remembers it for the client and its clones, the same waycompletion_ceilingalready works.In
chat_at_streaming's retry loop:body["max_tokens"] = json!(ceiling).error.param: "max_tokens"/error.code: "unsupported_parameter"sets the flag and retries. The first chunk pays the 400; the remaining 69 use the correct name from the start.chat_at(non-streaming) is not touched — it never sendsmax_tokens.Temperature rejection (
unsupported_value) is left out deliberately: silently droppingtemperature=0changes extraction from deterministic to sampling, which is a semantic decision the operator should make, not a silent fallback. Happy to add it if the project disagrees.A wiremock test verifies the rename, learning across calls, and learning across clones.
How it was checked
Tested against an Azure OpenAI endpoint running gpt-5.6-sol, which rejects
max_tokens. Before: 70/70 chunks fail with 400. After: first chunk retries once, remaining 69 pass directly.cargo fmt,cargo clippy -D warnings, andcargo test -p utopia-llm(54 tests) all pass.Before review
git commit -s)cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepassweb/:pnpm buildandpnpm testpass — N/A, no web changescrates/utopia-store/was tested withUTOPIA_DATABASE_URLset — N/A, no SQL changesdev— N/A, no migrationsweb/src/i18n/en.tsandzh.ts— N/A, no UI stringsdocs/decisions/— N/A