fix(agent): deduplicate ToolCall event in turn_streamed#5746
Merged
theonlyhennygod merged 1 commit intozeroclaw-labs:masterfrom Apr 15, 2026
Merged
Conversation
In turn_streamed, StreamEvent::ToolCall was sending a TurnEvent::ToolCall immediately during stream processing, and then the same event was sent again in the post-parse loop before tool execution. This caused every tool_call SSE event to be emitted twice to clients. Fix: remove the send from the StreamEvent::ToolCall match arm and let the unified post-parse loop (which covers both streaming and non-streaming paths) be the single place where ToolCall events are emitted.
Collaborator
|
I look forward to this resolving the streaming tool call duplications! You saved me some work, @c98 ! |
whtiehack
added a commit
to whtiehack/zeroclaw
that referenced
this pull request
Apr 18, 2026
StreamEvent::ToolCall 分支发了一次 TurnEvent::ToolCall,post-parse loop 又发一次,客户端每个 tool_call 收两次。 删除 StreamEvent::ToolCall 分支的早发射,保留 streamed_tool_calls 收集, 让统一的 post-parse loop 成为唯一发射点。 Ports upstream 9f0de18 (zeroclaw-labs#5746) to master_wecom's pre-workspace-split layout. Co-authored-by: c98 <ichuan.me@outlook.com> Co-authored-by: chuanzhi <ichuan.me@gmail.com>
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
In
turn_streamed,TurnEvent::ToolCallwas being emitted twice for every tool call:StreamEvent::ToolCallmatch arm during stream processingparse_responseloop before tool executionThis caused every
tool_callSSE event to be sent to clients twice, as shown below:Fix
Remove the
event_tx.send(TurnEvent::ToolCall {...})call from theStreamEvent::ToolCallmatch arm. The post-parse loop already covers both streaming and non-streaming paths, so it is the single, correct place to emitToolCallevents.A brief comment is left at the match arm to explain why the send is intentionally absent there.
Risk
Low — runtime/agent only; no API boundary changes. Existing test
turn_streamed_passes_tool_specs_to_providerpasses.Checklist
cargo fmt --all -- --checkpassescargo clippy --all-targets -- -D warningspassescargo testpasses