Skip to content

Commit 5412bdd

Browse files
Fix duplicate "Generating image..." tool call step
Only emit toolCallCreated on the in_progress event; treat the subsequent generating event as a no-op to avoid rendering two identical steps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6a8e2da commit 5412bdd

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

routers/chat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ async def iterate_stream(s, response_id: str = "") -> AsyncGenerator[str, None]:
366366
)
367367
)
368368

369-
case ResponseImageGenCallInProgressEvent() | ResponseImageGenCallGeneratingEvent():
369+
case ResponseImageGenCallInProgressEvent():
370370
current_item_id = event.item_id
371371
yield sse_format(
372372
"toolCallCreated",
@@ -377,6 +377,10 @@ async def iterate_stream(s, response_id: str = "") -> AsyncGenerator[str, None]:
377377
)
378378
)
379379

380+
case ResponseImageGenCallGeneratingEvent():
381+
# Intermediate state — tool call step already created by in_progress
382+
continue
383+
380384
case ResponseImageGenCallPartialImageEvent():
381385
# Display partial image as it streams in
382386
img_html = (

tests/test_tool_output_rendering.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,11 +914,12 @@ async def test_image_gen_partial_image_emitted(self):
914914

915915
@pytest.mark.anyio
916916
async def test_image_gen_no_duplicate_tool_call_on_generating(self):
917-
"""The generating event should not create a second toolCallCreated if in_progress already did."""
917+
"""The generating event should NOT create a second toolCallCreated —
918+
only the in_progress event creates the tool call step."""
918919
events = await self._stream_events()
919920
tool_calls = [e for e in events if e["event"] == "toolCallCreated"]
920-
# Both in_progress and generating emit toolCallCreated, but that's acceptable
921-
# (they render to the same step_id so HTMX deduplicates)
922-
# Just verify they all reference the same item
923-
for tc in tool_calls:
924-
assert f'id="step-{IG_ITEM_ID}"' in tc["data"]
921+
# Only in_progress should emit toolCallCreated, not generating
922+
assert len(tool_calls) == 1, (
923+
f"Expected exactly 1 toolCallCreated event (from in_progress only), got {len(tool_calls)}"
924+
)
925+
assert f'id="step-{IG_ITEM_ID}"' in tool_calls[0]["data"]

0 commit comments

Comments
 (0)