fix(agent): raise on empty stream instead of fabricating stop turn#38733
Open
liuhao1024 wants to merge 2 commits into
Open
fix(agent): raise on empty stream instead of fabricating stop turn#38733liuhao1024 wants to merge 2 commits into
liuhao1024 wants to merge 2 commits into
Conversation
When a streaming chat.completions request returns HTTP 200 but the SSE body yields zero usable chunks (empty stream, or a non-standard error frame the SDK doesn't surface), the streaming consumer exited its loop with no content and finish_reason=None, then fabricated a successful empty 'stop' turn via . The agent accepted the empty turn and could re-loop on a persistent condition, presenting as a silent hang with no error surfaced. Add a post-loop zero-chunk guard that raises RuntimeError when the stream produced no content, reasoning, tool calls, or finish_reason. This turns the silent-empty-turn failure mode into a normal recoverable error that flows through the existing retry/recovery machinery. Fixes NousResearch#38725
Contributor
|
Local review pass for #38725 coverage. Verified against commit
Current GitHub checks are passing except the expected skipped |
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?
Adds a post-loop zero-chunk guard in
interruptible_streaming_api_callthat raisesRuntimeErrorwhen a streaming response yields no content, reasoning, tool calls, or finish_reason. This prevents the agent from silently fabricating an empty "stop" turn and looping indefinitely on empty responses.Related Issue
Fixes #38725
Type of Change
Changes Made
agent/chat_completion_helpers.py: Added zero-chunk stream guard after the streaming loop exits — raisesRuntimeErrorwhenfinish_reason is Noneand all accumulators are empty, instead of falling through tofinish_reason or "stop"which fabricates a successful empty turn.tests/run_agent/test_streaming.py: Addedtest_empty_stream_raises_runtime_errorto verify the guard triggers on an empty stream iterator.How to Test
python -m pytest tests/run_agent/test_streaming.py::TestStreamingAccumulator::test_empty_stream_raises_runtime_error -xvspython -m pytest tests/run_agent/test_streaming.py -xChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
interruptible_streaming_api_callinagent/chat_completion_helpers.py(called fromrun_agent.pystreaming path)_is_provider_stream_parse_errorinrun_agent.pyhandles Anthropic parse errors but has no OpenAI equivalent — this guard fills that gap for the OpenAI-wire path