Fix streamed Markdown cleanup at EOF - #910
Open
wkramme wants to merge 1 commit into
Open
Conversation
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.
Summary
This fixes streamed Markdown responses that can appear to stop unexpectedly and lose their final content when the provider closes the stream without emitting a PartEndEvent.
What changed
Problem
The streaming handler incrementally parses complete lines and stores the final partial line in termflow_line_buffers.
Previously, that final buffer was only processed when a PartEndEvent arrived. However, providers can end an otherwise successful stream without sending that event. In that case:
Root cause
Text-part cleanup was tied exclusively to PartEndEvent.
Thinking streams already had post-stream cleanup for parts that remained open after the event iterator ended, but streamed text parts did not have an equivalent fallback. This left a gap specifically for graceful provider EOF without a matching PartEndEvent.
Implementation details
The new _finish_text_part() helper performs the complete text-part teardown:
The helper is called from:
The cleanup remains safe against duplicate calls because the relevant state is removed with dict.pop().
Testing
Validated with focused renderer and streaming tests:
text 140 passedAlso verified:
The public checkout's local test environment currently has a pre-existing dependency mismatch during test configuration import:
text ModuleNotFoundError: No module named 'pydantic_ai.capabilities'The focused tests passed in the development checkout before the change was ported to this clean upstream-based branch. The dependency mismatch is unrelated to this PR and should be resolved by synchronizing the local environment with the repository's pinned dependencies.