Skip to content

.Net: Bug: ResponsesAgentThread.GetMessagesAsync() loops because Azure SDK doesn’t advance pagination; add defensive “no-progress” guards and track upstream fix #12943

@CynthiaLuijkx

Description

@CynthiaLuijkx

Describe the bug
ResponsesAgentThread.GetMessagesAsync() can enter an infinite loop and repeatedly yield the same set of messages when used with Azure OpenAI. The root cause is upstream in the Azure SDK (Azure.AI.OpenAI): list calls for Responses items don’t propagate pagination args (after/before/order/limit), so the SDK re-fetches the same page even while has_more=true.
Tracking upstream issue: Azure/azure-sdk-for-net#50906

Even though this originates in the Azure SDK, Semantic Kernel should defensively handle non-advancing pagination so app code doesn’t hang.


To Reproduce
Happens some multi-turn conversations where the Responses API returns has_more=true near the end.

  1. Configure SK Agents with Azure OpenAI (Responses API) and obtain a previousResponseId from a multi-turn conversation that spans more than one page of items.

  2. Create a ResponsesAgentThread and enumerate messages:

    var agentThread = new OpenAIResponseAgentThread(_client, previousResponseId);
    
    await foreach (var t in agentThread.GetMessagesAsync())
    {
        <loop content>
    }
  3. Observe that the enumeration never completes and the same user/assistant messages repeat indefinitely.

  4. (Optional diagnostic) Log per page: count, first_id, last_id, and the outgoing cursor. You’ll see unchanged first_id/last_id on successive requests (non-advancing cursor).


Expected behavior

  • GetMessagesAsync() should always terminate and get the complete list of messages.

Platform

  • Language: C#
  • Source:
    • Semantic Kernel: 1.61.0(-preview)
    • Azure SDK: Azure.AI.OpenAI 2.2.0-beta.5
  • AI model: Azure OpenAI Responses with GPT-4.1

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETIssue or Pull requests regarding .NET codebugSomething isn't workingtriage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions