Repository navigation
A refusal whose ledger says the messages fit lowers the completion ceiling to what the window leaves, and history trimming leaves a list shorter than the stored history unchanged - #1021
Merged
WaylandYang merged 2 commits intoOct 1, 2026
Conversation
…iling to what the window leaves, and history trimming leaves a list shorter than the stored history unchanged Signed-off-by: dada-yan <BinjunYann@gmail.com>
WaylandYang
approved these changes
Oct 1, 2026
WaylandYang
left a comment
Contributor
There was a problem hiding this comment.
Approving. Thanks @Maya-Kid. Reviewed at df4e879: the ledger is read only in the one wording OpenAI, DeepSeek and vLLM share, a refusal whose messages fit lowers the ceiling to what the window leaves instead of being read as a context refusal, and apply sends a list shorter than the stored history unchanged rather than swallowing the question. The two-response test pins the whole retry path.
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.
The two follow-ups from #973's review.
Problem
Context::applyreplaces the first N non-system messages of rig's list with the trimmed history, N being the size of the stored history. It trusted that rig's list holds the whole prior history. If the list ever held fewer messages, the current question would have been counted as history and dropped, silently.max_tokenson a small-window model has been read as a context-window refusal since Long conversations shed old exchanges and recover from context refusals #973. An example: "maximum context length is 8192 tokens. However, you requested 69536 tokens (4000 in the messages, 65536 in the completion)".chat_retrying_rate_limits_at. Chat sends none.Change
Trimming falls back.
applycounts the non-system messages it was given; when there are no more of them than the stored history holds, it returns the list unchanged and logs it. An oversized request then fails at the endpoint, as it would have, instead of going out without its question.Which part overflowed.
utopia-llmreads the ledger some endpoints put in the refusal: the window, the tokens the messages take and the tokens the completion asked for (OpenAI, DeepSeek and vLLM word it this way; DeepSeek's was confirmed in #973).stated_completion_ceilingreturns what the window leaves, and the existing retry sends the request once more at that ceiling and remembers it on the client.Verification
First verified on 2026-09-28 against dev 0815a41 in containers on a Linux host (workspace 1,255 passed). It was then rebased onto dev 798fb24 without conflicts: since 0815a41, only #996 touched
utopia-llm/src/lib.rs, in other lines. It was verified again there, on macOS (arm64): Rust 1.98.1, PostgreSQL 16 with pgvector 0.8.2, and Poppler 26.06.Tests
chat_context.rs:a_list_shorter_than_the_history_is_sent_unchanged.utopia-llm,a_completion_overflow_is_a_ceiling_to_lower_and_not_a_context_refusal:context_length_exceeded;utopia-llm,a_completion_overflow_is_retried_at_what_the_window_leaves: a scripted endpoint refuses 65,536 with a ledger of 200 in the messages, the retry asks for 7,992, and the answer comes back.On dev (798fb24) with the new tests
The control is dev plus the tests, with the code reverted:
utopia-llm, three tests fail:a_completion_overflow_is_a_ceiling_to_lower_and_not_a_context_refusal,a_completion_overflow_is_retried_at_what_the_window_leavesand the existing ceiling test. 42 pass.chat_context.rs,a_list_shorter_than_the_history_is_sent_unchangedfails; 4 pass.This branch
utopia-llm: 45 passed.cargo fmt --all --checkandcargo clippy --locked --workspace --all-targets -- -D warningsare clean.UTOPIA_TEST_REQUIRE_DB=1 UTOPIA_TEST_REQUIRE_PDFTOTEXT=1 cargo test --locked --workspace: 1,323 passed, 0 failed, 6 ignored.Known limits