fix: raise a clear RuntimeError instead of a bare assert when streaming speaker selection yields no final result#7943
Open
roli-lpci wants to merge 1 commit into
Conversation
…ng speaker selection yields no final result SelectorGroupChatManager._select_speaker seeds `chunk` with the string "" before iterating create_stream() for speaker selection. If the stream yields no final CreateResult, the following `assert isinstance(chunk, CreateResult)` raises a bare, message-less AssertionError, and under `-O` (assertions stripped) the code falls through to `response = ""` and later crashes with an unrelated AttributeError. Seed `chunk` with None and raise an explicit RuntimeError, matching AssistantAgent._call_llm which already handles this case the same way.
ErenAta16
approved these changes
Jul 11, 2026
ErenAta16
left a comment
There was a problem hiding this comment.
Ran the two new tests on the branch — pass. The -O/PYTHONOPTIMIZE=1 angle is worth calling out on its own: even setting aside the message-less AssertionError, a bare assert silently vanishes under optimized mode, so this was not just "raises a worse-than-ideal error" but "fails an entirely different, more confusing way (or not at all, falling through to a later AttributeError) depending on how the interpreter is invoked." A real RuntimeError fixes both problems at once.
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
SelectorGroupChatManager._select_speaker(autogen_agentchat/teams/_group_chat/_selector_group_chat.py) seedschunk: CreateResult | str = ""before iteratingself._model_client.create_stream(...)for speaker selection. If the stream yields no finalCreateResult(a legitimate edge case: a provider hiccup, a cancelled/truncated stream, or a customChatCompletionClientimplementation),chunkis never aCreateResult, and the following line:raises a bare, message-less
AssertionError. Under-O/PYTHONOPTIMIZE=1, assertions are stripped entirely, so the code instead falls through toresponse = ""and crashes moments later with an unrelatedAttributeError: 'str' object has no attribute 'content'.Fix
Seed
chunkwithNone(a sentinel that can't be confused with real stream output) and replace the bareassertwith an explicitif not isinstance(chunk, CreateResult): raise RuntimeError(...). This mirrors the sibling streaming call site,AssistantAgent._call_llm(autogen_agentchat/agents/_assistant_agent.py), which already handles this exact situation the same way. No behavior change on the happy path: whencreate_streamyields a finalCreateResult,chunkends up being that result exactly as before.Test
Added
test_selector_group_chat_streaming_no_final_resulttotests/test_group_chat.py, parallel to the existingAssistantAgentregression testtest_streaming_without_final_result. It overridescreate_streamto yield chunks with no terminalCreateResultand asserts the clearRuntimeError. The existing selector suite (-k selector) passes unchanged.Scope
Single-function fix, matching an idiom already established elsewhere in the same package. Does not touch
AssistantAgent._call_llmor any other streaming call site.Note
This package currently carries a "maintenance mode" banner (#7521) as the org consolidates into a newer Agent Framework. Submitting anyway since the fix is small, correct, and cheap to review; happy to close without hard feelings if maintainer bandwidth doesn't allow a look.