Repository navigation
fix(agent): stop losing reasoning streams and never commit an empty reply - #1675
Merged
Merged
Conversation
vLLM and OpenRouter stream chain-of-thought in `delta.reasoning`; vLLM 0.33 marks `reasoning_content` deprecated in favour of it. The chat adapter only read `reasoning_content`/`thinking`, so a `reasoning` stream decoded as no reasoning at all — a turn that spent its whole output on thinking arrived as an empty reply. The first non-empty of `reasoning`, `reasoning_content`, `thinking` now wins; an empty higher-priority field no longer masks a populated fallback.
A model step that ended `stop` with no text and no tool call was returned as a completed run with an empty reply. Two shapes reach that path: the model thought and stopped right after the thought, or it produced nothing at all. When the step did think, retry it once with thinking switched off (through the scoped request controls, so the session's level is untouched) and an explicit request for the answer. A step still empty afterwards — and a step that never produced anything — ends the run as `incomplete` with reason `empty_answer` ([RESPONSE_UNCONFIRMED]) instead of completing silently.
ace331
force-pushed
the
fix/reasoning-field
branch
from
November 23, 2026 06:35
94f3409 to
cf5fc52
Compare
ace331
enabled auto-merge (squash)
November 23, 2026 06:37
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.
Context
A request to a vLLM-backed provider finished
finish_reason=stopwith an emptybody and 99 billed tokens. The service did not drop the response: the model
spent the whole turn thinking and stopped after the thought, and the client
never read that thought because the field is spelled
delta.reasoning— whichthe chat adapter did not know.
Server-side evidence (nginx 200s with 9.8 KB / 11.1 KB SSE bodies; a replay
with
max_tokens=99producing 46 frames / 99 tokens and no content) puts themissing content in the reasoning stream. vLLM 0.19.1
DeltaMessageonly hasreasoning; 0.33 marksreasoning_contentdeprecated and converges on it, asdoes OpenRouter.
Changes
fix(llm): decode every spelling of the streamed reasoning fieldThe adapter read
reasoning_contentthenthinking. It now takes the firstnon-empty of
reasoning,reasoning_content,thinking.This also fixes a latent bug in the old chain:
.or_else()ran before thenon-empty filter, so a delta carrying
reasoning: ""plus a populatedreasoning_contentdiscarded the fallback.fix(agent): never commit an answer-less turn as completedtool_calls.is_empty()used to returnOk(assistant_text)unconditionally, soa step with no text and no tool call was committed as a completed run with an
empty reply. Two shapes reached that path: the model thought and stopped right
after the thought, or it produced nothing at all.
the scoped request controls (the session's configured level is untouched),
plus a request-only instruction asking for the answer. The thought is not
replayed: a reasoning-only assistant turn is rejected upstream.
the run as
incompletewith reasonempty_answer.StreamTruncation'sunknown-reason fallback already renders it as
[RESPONSE_UNCONFIRMED], so noclient-side mapping changes.
(
max_retries > 0); it never applies to fusion routing, whose own"exactly one fusion call" error is the better diagnosis.
Behaviour change worth a look
normal_reasoning_only_and_empty_replies_are_not_transport_errorsassertedthat a
stopwith empty content is not incomplete. That is the behaviour thisPR deliberately overturns, so the test is rewritten as
empty_replies_end_incomplete_and_a_reasoning_only_one_is_retriedwith threescenarios: truly empty → incomplete; reasoning-only then answered → completed,
with the retry instruction asserted and the thought absent from the replayed
request; reasoning-only twice → incomplete with the streamed thought still in
history.
Not changed
usage.prompt_tokens_details.cached_tokensis already read bychat_usage,with
prompt_cache_hit_tokens/cache_read_input_tokensfallbacks. A cacheread of 0 on this service comes from using the Anthropic
/v1/messagespath,which vLLM 0.19.1 does not fill; the OpenAI path reports it.
Verification
cargo test -p future-agent --lib -- agent::run_loop— 183 passedcargo test -p future-agent --lib -- llm::adapters::openai_chat— 31 passed(three new cases for the field spellings)
cargo test -p future-agent --lib -- fusion— 15 passedcargo test -p future-agent --lib -- empty— 126 passedrustfmt --checkon the three touched files only; the repository-widecargo fmtbaseline is dirty and was left alone.