fix(streaming): stop losing the tail of commentary truncated at a tool-call boundary - #88963
Open
liuhao1024 wants to merge 1 commit into
Open
fix(streaming): stop losing the tail of commentary truncated at a tool-call boundary#88963liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…l-call boundary
With streaming enabled on Telegram, the streamed commentary is routinely
cut mid-text when the tool_calls finish arrives; the partial stream is a
prefix of the full commentary. The interim-message path used the
prefix-based _interim_content_was_streamed verdict, so the gateway's
_interim_assistant_cb called on_segment_break() — finalizing the
truncated bubble — and the tail ("...pick it u" vs "...pick it up") was
permanently lost (NousResearch#88954).
That prefix semantics stays correct for the conversation-loop
"previewed" marks (the streamed prefix IS on the user's screen there,
and the contract test pins it per the NousResearch#65919 review). The gateway
decision needs the stricter test: add _interim_content_fully_streamed
(exact normalized equality) and use it for the interim-message verdict.
Only an exact match may skip the full-text resend; a partial prefix
falls through to on_commentary() and re-delivers the complete text —
a benign duplicate, never lost text.
Contributor
Author
|
The slice-7 failure ( |
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.
What does this PR do?
Stops permanently losing the tail of streamed commentary when the stream is truncated at the text→tool_calls boundary (#88954). With streaming enabled on Telegram, the streamed commentary is routinely cut mid-text when the
tool_callsfinish arrives — the partial stream is a prefix of the full commentary. The interim-message path used the prefix-based_interim_content_was_streamedverdict, so the gateway's_interim_assistant_cbreceivedalready_streamed=Trueand calledon_segment_break()— finalizing the truncated bubble as-is. The tail ("...to pick it u" instead of "...to pick it up") was never delivered. The reporter verified the provider is not at fault: the same proxy with tools streams the complete text.The fix keeps the two consumers' semantics distinct:
_interim_content_was_streamed(prefix match) stays unchanged — for the conversation-loop "previewed" marks the streamed prefix IS on the user's screen, and the contract test (test_interim_content_was_streamed_matches_prefix_not_exact, per the fix(desktop, ink): don't wipe messages before final message #65919 review) pins that behavior._interim_content_fully_streamed(exact normalized equality) is used for the interim-message verdict that feeds the gateway callback. Only an exact match may skip the full-text resend; a partial prefix falls through toon_commentary(), which re-delivers the complete text — a benign duplicate, never lost text (the outcome the old comment claimed but did not deliver on this path).Related Issue
Fixes #88954
Type of Change
Changes Made
run_agent.py_interim_content_fully_streamed(): same normalization pipeline, exact-equality verdict, with a docstring explaining why the gateway decision needs the stricter test._emit_interim_assistant_messageuses the exact verdict foralready_streamed.tests/run_agent/test_run_agent_codex_responses.pytest_interim_commentary_partial_stream_receives_full_text: a streamed prefix ("...pick it u") of the full commentary must yieldalready_streamed=Falsewith the FULL text, so the gateway re-delivers it.test_interim_commentary_exact_stream_still_marks_streamed: an exactly-streamed commentary keepsalready_streamed=True(no duplicate resend).How to Test
python -m pytest tests/run_agent/test_run_agent_codex_responses.py -qObserved result: 49 passed (includes the untouched prefix-contract test).
git stashtherun_agent.pychange and reruntest_interim_commentary_partial_stream_receives_full_text— Observed result: 1 failed (the truncated prefix is marked already_streamed, matching the reported loss).pytest tests/run_agent/test_plugin_stream_hooks.py tests/run_agent/test_verification_continuation_budget.py tests/run_agent/test_tool_call_incremental_persistence.py -q— Observed result: 25 passed, 7 failed; the same 7 fail identically on a stashed baseline (pre-existing local-environment failures, unrelated).Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass (codex responses suite: 49 passed; adjacent suites match the stashed baseline)Documentation & Housekeeping
docs/, docstrings) — the new helper's docstring documents the two-consumer split; or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A