Skip to content

Conversation

@sixlive
Copy link
Contributor

@sixlive sixlive commented Dec 29, 2025

Description

Fixes streaming event ordering in multi-turn tool conversations. Previously, providers emitted StreamEndEvent before tool execution completed and produced duplicate StreamStart/StreamEnd pairs across tool call turns.

Changes:

  • Modified StreamState::reset() to preserve streamStarted flag across tool call turns
  • Added conditional StreamEndEvent emission in all 9 provider Stream handlers (only emit when no pending tool calls)
  • Added state reset before recursive streaming in Ollama handler to clear tool call state between turns

Before:

StreamStartEvent (turn 1)
StreamEndEvent (turn 1)      <- Too early
ToolResultEvent              <- After StreamEnd
StreamStartEvent (turn 2)    <- Duplicate
StreamEndEvent (turn 2)

After:

StreamStartEvent (once)
ToolCallEvent
ToolResultEvent
StreamEndEvent (once at true end)

Breaking Changes

@sixlive sixlive self-assigned this Dec 29, 2025
@kinsta
Copy link

kinsta bot commented Dec 29, 2025

Preview deployments for prism ⚡️

Status Branch preview Commit preview
✅ Ready Visit preview Visit preview

Commit: 80fde00cd0f1be2bfc33098aed863c5a5eece221

Deployment ID: 312fed28-6d58-4006-a475-c9bec2139f4f

Static site name: prism-97nz9

@sixlive sixlive merged commit 825f6af into main Dec 29, 2025
14 checks passed
@sixlive sixlive deleted the fix-stream-events branch December 29, 2025 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants