Skip to content

Conversation

@vaishnavyogesh
Copy link
Contributor

Resolves: #870 (comment)

Description

Fixes a bug where OpenAI (and potentially other providers) would emit TextCompleteEvent without a corresponding TextStartEvent after the first text cycle when responses contained multiple output items.

Root Cause

The textStarted flag in StreamState was never reset once a TextCompleteEvent was emitted. When OpenAI responses contained multiple output items (content parts), the flag remained true after the first text block completed, causing subsequent text blocks to skip their TextStartEvent and proceed directly to TextDeltaEvent.

Changes

  • StreamState: Added markTextCompleted() method to reset the textStarted flag
  • All Stream Handlers: Proactively added markTextCompleted() call before every TextCompleteEvent emission across all providers (OpenAI, Anthropic, Gemini, DeepSeek, OpenRouter, XAI, Groq, Ollama, Mistral)
  • Tests:
    • Added integration test with fixture for multiple output items scenario
    • Added unit test to verify markTextCompleted() properly resets the flag

Result

Each text block in a streaming response now properly emits its own complete cycle: TextStartEventTextDeltaEvent(s) → TextCompleteEvent, regardless of how many output items the provider returns.

Breaking Changes

None. This is a bug fix that maintains full backward compatibility while ensuring correct event emission for multi-part text responses.

This makes sure that are always consistent text-start..text-complete event pairs

Resolves: prism-php#870 (comment)
@sixlive sixlive merged commit a50b65d into prism-php:main Jan 26, 2026
14 checks passed
@vaishnavyogesh vaishnavyogesh deleted the fix/text-complete-without-text-start-evt branch January 27, 2026 05:26
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.

Open AI (GPT-4.1-mini) multiple TextComplete without TextStart events

2 participants