Skip to content

Retry at the ceiling the endpoint states when it refuses ours, and remember it - #914

Merged
WaylandYang merged 1 commit into
devfrom
fix/max-tokens-respects-endpoint-ceiling
Sep 25, 2026
Merged

WaylandYang merged 1 commit into
devfrom
fix/max-tokens-respects-endpoint-ceiling

Conversation

@WaylandYang

Copy link
Copy Markdown
Contributor

Lands @basil-k-aji-dev's #892 (fix for #891) with the two review points applied, as we did for #776 → #786: their mechanism and tests, carried with co-authorship, on current dev.

What it does. Since #786 every streamed call sends max_tokens 65,536 so that a cut reply is ours to detect; an endpoint whose completion limit is lower refuses instead of clamping, and every chunk fails (gpt-4o-mini caps at 16,384). When a 400 states the endpoint's own ceiling the call is retried once at that number, so gpt-4o-mini works again without any setting.

Review points applied.

  • The learned ceiling lives on the client (Arc<AtomicU32>, shared with clones such as the with_reasoning_effort copies), so a process pays the refusal once rather than once per chunk; it only ever goes down. Test: the next call and a clone's call start at the stated ceiling.
  • The number is read by shape rather than "any integer below what we sent": only a number the message itself calls tokens counts, with or without thousands separators, and nothing below 1,024. 16,384 no longer parses to 384, gpt-4o-mini-2024-07-18 no longer yields 2024, a context-window refusal lowers to the window and may still fail on the retry as today. Unit test with those messages.

utopia-llm 41 tests pass, workspace clippy clean.

Closes #891
Closes #892

🤖 Generated with Claude Code

…member it

Since #786 every streamed call sends max_tokens 65,536 so that a cut
reply is ours to detect. An endpoint whose completion limit is lower
refuses instead of clamping, and every chunk fails: gpt-4o-mini caps at
16,384 (#891).

When a 400 states the endpoint's own ceiling, the call is retried once
at that number, and the number is kept on the client, shared with its
clones, so a process pays the refusal once rather than once per chunk.
The ceiling only ever goes down. Only a number the message itself calls
tokens counts, with or without thousands separators and no lower than
1,024: the digits of a model name, a status code or our own echoed
request are not limits, and a message that parses to nothing leaves the
caller with exactly the 400 it gets today. A context-window refusal
lowers to the window and may still fail on the retry, as today.

Landed from #892 by basil-k-aji-dev with the two review points applied:
the ceiling on the client instead of a local, and the shape rule for the
number instead of "any integer below what we sent".

Closes #891
Closes #892

Co-authored-by: basil-k-aji-dev <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Wayland Yang <[email protected]>
@WaylandYang
WaylandYang merged commit 4f3275c into dev Sep 25, 2026
@WaylandYang
WaylandYang deleted the fix/max-tokens-respects-endpoint-ceiling branch September 25, 2026 08:14
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.

Graph extraction fails with OpenAI models in 0.1.0-rc6 (max_tokens too large)

1 participant