Skip to content

AzureOpenAIChatModel reordering bug when streaming #4155

@robinmayerhofer

Description

@robinmayerhofer

Bug description

Streamed chunks might end up in a wrong order:

data: <A>
data: <B>

can end up as <B> => <A>

Environment

  • Spring AI 1.0.1
  • Java 21

Steps to reproduce
It's enough to inject the default AzureOpenAIChatModel, build a ChatClient and call

val chatClient = ChatClient.builder(chatModel).build()

chatClient
    .prompt(createPrompt(simpleResponseDeploymentName))
    .stream()
    .content()
    .collectList()
    .block()

On a local machine I need many sequential runs to trigger the issue, thus, a setup with WireMock is advisable.

Expected behavior
The response chunks should be ordered correctly.

Minimal Complete Reproducible example
Repo with test setup: https://github.com/robinmayerhofer/spring-ai-azure-openai-streaming-issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions