fix(streaming): restore real-time chunk delivery in tool/chat paths#261
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e16f651871
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| if delta.tool_calls: | ||
| for tc_chunk in delta.tool_calls: | ||
| tc_id = tc_chunk.id or f"call_{tc_chunk.index}" |
There was a problem hiding this comment.
Preserve streamed tool-call fragments under one call ID
In the new streaming chat_with_tools path, the accumulator key is recomputed as tc_chunk.id or f"call_{tc_chunk.index}" for every delta, so when later deltas omit id (a common streaming pattern after the first tool-call chunk), argument/name fragments are split across two entries instead of being merged. That can produce malformed tool_calls (e.g., one entry with partial args and another with missing name), which then breaks downstream tool execution in ToolCallAgent.act() when output_queue is enabled.
Useful? React with 👍 / 👎.
| and part_response.candidates | ||
| and getattr(part_response.candidates[0], "finish_reason", None) | ||
| ): | ||
| finish_reason = str(part_response.candidates[0].finish_reason) |
There was a problem hiding this comment.
Normalize Gemini streamed finish reasons before returning
The streamed Gemini tool path now returns finish_reason as str(part_response.candidates[0].finish_reason) (for example "STOP") without mapping it to the normalized values used elsewhere ("stop", "length", "tool_calls"). In streaming agent flows (output_queue set), this can prevent ToolCallAgent._should_terminate_on_finish_reason() from recognizing terminal no-tool responses, causing extra think/act iterations instead of clean termination.
Useful? React with 👍 / 👎.
|
Addressed the automated review items in commit e578bf7:
Validation:
|
Summary
output_queuethrough tool-call chat path so provider deltas are emitted upstreamclient.aio.models.generate_content_stream(...)+async forto avoid event-loop blockingstreamed_contentmetadata)Verification
uv run python -m pytest tests/test_tool_streaming_output.py tests/test_chatbot_integration.py::TestChatBotIntegration::test_ask_tool_with_manager tests/test_agent_llm_integration.py::TestAgentLLMIntegration::test_streamed_tool_response_does_not_enqueue_full_content_twice -q