semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.NET: Bug: 1.79 streaming Responses tool continuation fails with previous_response_not_found

Open daemosofchaos opened this issue 3 months ago • 3 comments

Describe the bug

After upgrading the .NET Semantic Kernel packages from 1.78.0 to 1.79.0, a streaming OpenAI Responses API tool loop repeatedly fails on the framework-generated continuation request after a local tool completes successfully.

The tool returns normally and no local exception is logged, but the follow-up request that submits the function output fails with:

HTTP 400 (invalid_request_error: previous_response_not_found)
Parameter: previous_response_id
Previous response with id 'resp_…' not found.

Rolling the Semantic Kernel package family back to 1.78.0, without changing the application pipeline, provider configuration, model, or lower-level Responses packages, immediately restores reliable continuation.

This is similar to #13128, but appears to be a different or newly exposed regression:

  • #13128 used an SK 1.64 preview, was non-streaming, intermittent, and timing-sensitive.
  • This case uses SK 1.79, is streaming through Microsoft.Extensions.AI, reproduces repeatedly, and disappears on SK 1.78.

To Reproduce

  1. Create an OpenAI Responses IChatClient:
IChatClient responsesClient = openAIClient
    .GetResponsesClient()
    .AsIChatClient(modelId);
  1. Add one or more local functions, including functions adapted from Semantic Kernel plugins with KernelPlugin.AsAIFunctions(kernel).
  2. Wrap the client with the Microsoft.Extensions.AI function-invocation middleware:
IChatClient client = responsesClient
    .AsBuilder()
    .UseFunctionInvocation(configuration =>
    {
        configuration.AllowConcurrentInvocation = true;
        configuration.TerminateOnUnknownCalls = false;
    })
    .Build();
  1. Stream a request that invokes a local tool:
await foreach (ChatResponseUpdate update in client.GetStreamingResponseAsync(
                   messages,
                   new ChatOptions { Tools = tools },
                   cancellationToken))
{
    // Consume the streamed response.
}
  1. Observe that the local function completes and returns its result, but the immediate continuation that posts the function output fails with previous_response_not_found.
  2. Change the Semantic Kernel package family from 1.79.0 back to 1.78.0, rebuild, and repeat the same calls. The continuation succeeds.

In the affected application, the failure was especially easy to reproduce with file-read tools and larger text results, but it was not caused by the tool implementation. Small reads and other tool types could fail as well.

A/B result

With Semantic Kernel 1.79.0:

  • repeated immediate continuation failures;
  • the tool process itself completed successfully;
  • no swallowed tool exception was found.

With Semantic Kernel 1.78.0:

  • repeated small and large file reads succeeded;
  • a source-search tool succeeded;
  • six consecutive mixed tool continuations succeeded in the live application;
  • the same custom activity wrapper and function-invocation pipeline were enabled.

The lower-level package graph used for the controlled comparison was:

Microsoft.Extensions.AI                 10.5.2
Microsoft.Extensions.AI.Abstractions    10.5.2
Microsoft.Extensions.AI.OpenAI          10.5.2
OpenAI                                  2.10.0
System.ClientModel                      1.15.0

Both Microsoft.SemanticKernel.Connectors.OpenAI 1.78 and 1.79 were tried while diagnosing the 1.79 failure. Updating the connector alone did not resolve it; reliable behavior returned only after rolling the Semantic Kernel 1.79 packages back to 1.78.

Diagnostics already tried

The failure persisted under SK 1.79 after each of the following:

  • explicitly setting CreateResponseOptions.StoredOutputEnabled = true;
  • capturing every non-null ChatResponseUpdate.ConversationId, outside provider-specific update-type checks;
  • bypassing the application's custom tool-activity/telemetry invoker entirely;
  • invoking a single tool, so no application-level parallel scheduling or batch barrier was involved;
  • verifying that the tool returned successfully and that no tool exception appeared in diagnostic logs.

Those defensive changes remain useful, but none stopped the 1.79 failure. The package rollback did.

Expected behavior

After a local function completes, the framework-managed Responses API loop should submit the function output and continue the streamed turn reliably, as it does with Semantic Kernel 1.78.

Platform

  • Language: C#
  • Runtime: .NET 10
  • Source: NuGet Microsoft.SemanticKernel 1.79.0 (regression), 1.78.0 (working)
  • API: OpenAI Responses API through Microsoft.Extensions.AI.IChatClient
  • OS: Windows

Additional context

The dotnet-1.79.0 release was published on 2026-08-06. No currently open Semantic Kernel issue was found for this specific streaming 1.79 regression. The closest prior report is the stale-closed #13128.

A minimal standalone repository has not yet been extracted from the production application, but the version A/B result was repeated live and the application-level intermediaries above were individually ruled out.

daemosofchaos avatar Aug 15 '26 12:08 daemosofchaos

i'm taking a look at a minimal mocked streaming continuation and will trace which layer owns the response state. i'll share what i find.

atirna avatar Aug 15 '26 15:08 atirna

i traced the reported loop before trying a patch. GetResponsesClient().AsIChatClient() and UseFunctionInvocation() are supplied by the OpenAI and Microsoft.Extensions.AI packages, not Semantic Kernel. Across the dotnet-1.78.0 to dotnet-1.79.0 release diff, the only OpenAI connector change is audio-format mapping; there is not a Responses continuation or function-invocation implementation here to change.

The release did move Microsoft.Extensions.AI.Abstractions 10.5.0 -> 10.5.2 while Microsoft.Extensions.AI and .OpenAI stayed 10.5.0. The controlled dependency graph in this issue pins the MEAI packages to 10.5.2, so that looks like the layer worth reproducing against. Could you share a minimal HTTP-handler repro or confirm whether it still happens when using the exact 1.79 package graph with MEAI packages pinned to 10.5.0? I do not want to add a misleading SK regression test when the continuation state is owned outside this repo.

atirna avatar Aug 15 '26 15:08 atirna

Closing this after further instrumentation showed that the original Semantic Kernel attribution was incorrect.

The failure still occurs with Semantic Kernel 1.78, so the earlier 1.78 versus 1.79 A/B result was coincidental. Privacy-safe lifecycle tracing captured the relevant active-turn sequence:

response.completed:     store=true, status=completed
next continuation:      previous_is_latest=true
completion-to-request:  328 ms
provider response:      HTTP 400 previous_response_not_found

The fingerprint of the outgoing previous_response_id matched the immediately preceding completed response. A deterministic multi-tool-loop test also confirmed that the Microsoft.Extensions.AI function loop advances the chain correctly across successive responses and does not repeat the local tool invocation.

This rules out the reported SK version regression and an application-side conversation-ID overwrite for the captured failure. The evidence instead points to the provider accepting a stored response as completed but subsequently being unable to resolve that response for the immediate tool continuation.

We have added a narrowly scoped transport retry for this exact provider error. It replays only the identical function_call_output continuation request and does not execute the completed tool again.

Thank you for tracing which package layer owns the continuation state, and apologies for the initial misattribution. This should not remain open as a Semantic Kernel issue.

daemosofchaos avatar Aug 17 '26 12:08 daemosofchaos