Skip to content

fix(runtime): keep text sent with a terminal finish reason - #4718

Open
locker95 wants to merge 1 commit into
docker:mainfrom
locker95:fix/stream-terminal-chunk-content
Open

locker95 wants to merge 1 commit into
docker:mainfrom
locker95:fix/stream-terminal-chunk-content

Conversation

@locker95

Copy link
Copy Markdown
Contributor

When a provider sends the last content delta in the same chunk as finish_reason stop/length, handleStream returned before appending it, so the tail of the answer got cut off. Moved the reasoning/content handling above the early return and added a test for it.

Fixes #4715

Some OpenAI-compatible providers put the last content delta in the same
chunk as finish_reason "stop" or "length". The stream handler returned
on the finish reason before appending that chunk's content and
reasoning, so the end of the answer was dropped.

Accumulate reasoning, thinking signature and content before handling
the terminal finish reason.

Fixes docker#4715

Signed-off-by: Dean Chen <862469039@qq.com>
@locker95
locker95 requested a review from a team as a code owner October 26, 2026 01:26
@aheritier aheritier added area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Oct 26, 2026

@aheritier aheritier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No substantive code findings in the two-file diff. Accumulating content and reasoning before the terminal return fixes #4715 while preserving marker filtering, XML fallback, and refusal handling. The regression test covers stop and length, checking complete persisted/live text, accumulated reasoning, finish reason, and stopped state.

Validation: Source and tests reviewed at this commit; tests were not run locally.

CI / merge readiness: Not ready at review time. Both ci and codeql concluded action_required, with no CI jobs executed. The PR was conflict-free but blocked. Approval is withheld pending successful CI.

@locker95

Copy link
Copy Markdown
Contributor Author

yeah, ci and codeql never actually ran. both are sitting on action_required, and I can't approve the workflow from the fork.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime Runtime engine, agent loop execution, tool dispatch, loop detection kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The text in a streamed chunk that also carries finish_reason "stop" is dropped

2 participants