Repository navigation
fix(response-stream): replay closed stream for subsequent root Answer nodes - #449
Open
tang-ontheway wants to merge 1 commit into
Open
tang-ontheway wants to merge 1 commit into
tang-ontheway wants to merge 1 commit into
Conversation
This branch has not been deployed
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
Ensure a second root
Answernode referencing a previously streamed variable replays the buffered text instead of omitting it when the firstAnsweralready consumed the closed stream.Fixes #435
Root Cause
_TemplateStream._read_root_variable_chunks()only replayedbuffered_eventson a closed stream whenselector in session.repeated_selectors(i.e., the same selector appeared twice inside a singleAnswertemplate). A subsequent rootAnswernode referencing the same selector once hasselector not in session.repeated_selectors, saw the exhausted selector cursor, and skipped its placeholder.Changes
src/graphon/engine/filter/builtin/response_stream/template_stream.py: Track per-segment reads insession.segment_positions[session.index]inside_read_root_variable_chunks()and replaybuffered_eventswhenever the stream is closed, no new unread events were popped, and this segment has not yet consumed any chunks (session.segment_positions.get(session.index, 0) == 0).tests/engine/test_response_stream_filter.py: Updatetest_response_stream_filter_repeats_variable_text_within_one_replyso streamed and non-streamed paths both assert"value/value!next:value", and addtest_response_stream_filter_replays_closed_stream_for_second_root_answercoveringLLM -> First Answer -> Second Answer.Verification
uv run ruff format --check&uv run ruff check(passed)uv run pytest tests/ -k response_stream -q(152 passed)