Skip to content

ai-openai-compat: streamText drops text when delta.tool_calls is null #7268

Closed

Description

@CommiAI

What version of Effect is running?

What steps can reproduce the bug?

I am using Inception Mercury 2 through the OpenAI-compatible provider.

During ordinary text streaming, Inception returns chunks containing valid text alongside tool_calls: null:

{
  "id": "chatcmpl-example",
  "object": "chat.completion.chunk",
  "created": 1,
  "model": "inception/mercury-2",
  "choices": [
    {
      "index": 0,
      "delta": {
        "content": "Hello",
        "role": "assistant",
        "tool_calls": null
      },
      "finish_reason": null
    }
  ]
}

When this chunk is processed by @effect/ai-openai-compat, the low-level client emits an UnknownChatCompletionEvent.

When using OpenAiLanguageModel.streamText, no text-delta part is emitted for "Hello".

This can be reproduced without an Inception credential by returning the payload above from a mocked SSE response and collecting the events from createResponseStream or the parts from streamText.

What is the expected behavior?

The valid delta.content text should be available through OpenAiLanguageModel.streamText.

A response containing tool_calls: null when no tool call is present should not cause the text in the same chunk to be lost.

What do you see instead?

The low-level client classifies the complete chunk as:

{
  "_tag": "UnknownChatCompletionEvent",
  "data": {
    "choices": [
      {
        "delta": {
          "content": "Hello",
          "tool_calls": null
        }
      }
    ]
  }
}

The high-level language-model stream skips the unknown event.
The stream reaches its finish event, but the resulting text is empty.

In a live Mercury 2 request, every text-bearing chunk had tool_calls: null, so all streamed text was lost.

Complete text generation, structured output, complete tool calls, and streamed tool calls otherwise worked in the same compatibility test.

Additional information

This appears related to #6346 and #6667.

Those changes made schema-mismatched SSE payloads observable as UnknownChatCompletionEvent, which made this incompatibility diagnosable.
In this case, however, the payload also contains ordinary text that a high-level streamText consumer cannot recover.

I can provide a focused pull request with regression coverage if that would be helpful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions