Skip to content

Add messageId to stream text deltas for reliable dedup #71

Description

@dremnik

Problem

Stream text events (thread.stream.text.*) carry a part/stream id, not the final message id. The final assistant message arrives via thread.event.created with a different id. The client has no reliable way to correlate them, causing duplicate rendering.

Root cause

Every major provider gives you a response/message id:

  • OpenAI Responses: item.id (msg_123) threaded through content events
  • Anthropic: message.id (msg_1nZdL29xx...) on message_start
  • xAI: id on the response, msg_... on output items
  • Google: responseId on GenerateContentResponse

The AI SDK only surfaces these on response-metadata and uses synthetic String(index) or String(blockCounter++) as the id on text-start/text-delta for Anthropic and Google. It throws away the association.

Fix

Resolve the real message id at the adapter boundary (per-provider), attach it as messageId on stream text parts, and use it for dedup on the client.

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