Skip to content

.NET: Run fails with “Cannot cancel run with status ‘incomplete’” after safety-blocked prompt in same thread #2298

Description

@Pavan-Microsoft

When the user asks a safety-blocked question (e.g., “how to make a bomb”), the model correctly responds with a refusal message.
However, if any subsequent request is made within the same thread, the following error is thrown:

(None) Cannot cancel run with status 'incomplete'.
Code: None
Message: Cannot cancel run with status 'incomplete'.

This seems to indicate that the thread/run becomes stuck in an incomplete state after the safety violation, preventing any further operations.

Expected behavior:
Subsequent messages in the same thread should continue normally or should at least return a clear recovery method.

Actual behavior:
The run cannot be continued or canceled, blocking all further operations in that thread.

Please provide guidance on how to recover or handle this state.

Using: agent-framework 1.0.0b251114

Image

Activity

  1. alliscode commented on Nov 20, 2025

    @alliscode
    Member

    Pavan-Microsoft could you please give us more information on your setup, or even a minimal repro? How are you creating your agents, what service/model are you using, what language, etc.

  2. removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 20, 2025
  3. shunsaker-macu commented on Nov 21, 2025

    @shunsaker-macu

    Hi Ben Thomas (@alliscode) I am also hitting this issue.

    I've traced the origin to Azure.AI.Agents.Persistent Specifically in PersistentAgentsChatClient.GetStreamingResponseAsync It see's that there is a run that's not completed or canceled, because the status is actually "incomplete" which is like a failure, but not specifically checked here.
    https://github.com/Azure/azure-sdk-for-net/blob/3de860fc2104be81296b52d5eab279b6628216c8/sdk/ai/Azure.AI.Agents.Persistent/src/Custom/PersistentAgentsChatClient.cs#L87-L125

                // Get any active run ID for this thread.
                ThreadRun? threadRun = null;
                if (threadId is not null)
                {
                    await foreach (ThreadRun? run in _client!.Runs.GetRunsAsync(threadId, limit: 1, ListSortOrder.Descending, cancellationToken: cancellationToken).ConfigureAwait(false))
                    {
                        if (run.Status != RunStatus.Completed && run.Status != RunStatus.Cancelled && run.Status != RunStatus.Failed && run.Status != RunStatus.Expired)
                        {
                            threadRun = run;
                            break;
                        }
                    }
                }
    ...
                    else if (threadRun is not null)
                    {
                        // There was an active run; we need to cancel it before starting a new run.
                        await _client!.Runs.CancelRunAsync(threadId, threadRun.Id, cancellationToken).ConfigureAwait(false);
                        threadRun = null;
                    }
    

    I have set a breakpoint here and confirmed that the run.Status is incomplete, which isn't even recongnized as a possible RunStatus value in RunStatus.cs.

    Here's my complete stack trace:

    Call Stack: Azure.RequestFailedException:
       at Azure.AI.Agents.Persistent.HttpPipelineExtensions+<ProcessMessageAsync>d__0.MoveNext (Azure.AI.Agents.Persistent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Threading.Tasks.ValueTask`1.get_Result (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Azure.AI.Agents.Persistent.ThreadRuns+<CancelRunAsync>d__69.MoveNext (Azure.AI.Agents.Persistent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter.GetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Azure.AI.Agents.Persistent.ThreadRuns+<CancelRunAsync>d__67.MoveNext (Azure.AI.Agents.Persistent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter.GetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Azure.AI.Agents.Persistent.PersistentAgentsChatClient+<GetStreamingResponseAsync>d__10.MoveNext (Azure.AI.Agents.Persistent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.ThrowForFailedGetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Azure.AI.Agents.Persistent.PersistentAgentsChatClient+<GetStreamingResponseAsync>d__10.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (Azure.AI.Agents.Persistent, Version=1.2.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8)
       at Microsoft.Extensions.AI.FunctionInvokingChatClient+<GetStreamingResponseAsync>d__39.MoveNext (Microsoft.Extensions.AI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Extensions.AI.FunctionInvokingChatClient+<GetStreamingResponseAsync>d__39.MoveNext (Microsoft.Extensions.AI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.ThrowForFailedGetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Extensions.AI.FunctionInvokingChatClient+<GetStreamingResponseAsync>d__39.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (Microsoft.Extensions.AI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
       at Microsoft.Agents.AI.ChatClientAgent+<RunStreamingAsync>d__21.MoveNext (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Agents.AI.ChatClientAgent+<RunStreamingAsync>d__21.MoveNext (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.ThrowForFailedGetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Agents.AI.ChatClientAgent+<RunStreamingAsync>d__21.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at Microsoft.Agents.AI.OpenTelemetryAgent+ForwardingChatClient+<GetStreamingResponseAsync>d__3.MoveNext (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Agents.AI.OpenTelemetryAgent+ForwardingChatClient+<GetStreamingResponseAsync>d__3.MoveNext (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.ThrowForFailedGetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Agents.AI.OpenTelemetryAgent+ForwardingChatClient+<GetStreamingResponseAsync>d__3.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at Microsoft.Extensions.AI.OpenTelemetryChatClient+<GetStreamingResponseAsync>d__20.MoveNext (Microsoft.Extensions.AI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Extensions.AI.OpenTelemetryChatClient+<GetStreamingResponseAsync>d__20.MoveNext (Microsoft.Extensions.AI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.ThrowForFailedGetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Extensions.AI.OpenTelemetryChatClient+<GetStreamingResponseAsync>d__20.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (Microsoft.Extensions.AI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
       at Microsoft.Agents.AI.OpenTelemetryAgent+<RunStreamingAsync>d__8.MoveNext (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Agents.AI.OpenTelemetryAgent+<RunStreamingAsync>d__8.MoveNext (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1.ThrowForFailedGetResult (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Microsoft.Agents.AI.OpenTelemetryAgent+<RunStreamingAsync>d__8.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (Microsoft.Agents.AI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f300afd708cefcd3)
       at Macu.Ai.Agents.KCAgent.Api.Bot.EchoBot+<OnMessageAsync>d__6.MoveNext (Macu.Ai.Agents.KCAgent.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: H:\Documents\Repos\kc_agent_api_master\src\Macu.Ai.Agents.KCAgent.Api\Bot\EchoBot.cs:101)
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
       at Macu.Ai.Agents.KCAgent.Api.Bot.EchoBot+<OnMessageAsync>d__6.MoveNext (Macu.Ai.Agents.KCAgent.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: H:\Documents\Repos\kc_agent_api_master\src\Macu.Ai.Agents.KCAgent.Api\Bot\EchoBot.cs:101)
    , Message: Cannot cancel run with status 'incomplete'.
    Status: 400 (Bad Request)
    
    Content:
    {
      "error": {
        "message": "Cannot cancel run with status 'incomplete'.",
        "type": "invalid_request_error",
        "param": null,
        "code": null
      }
    }
    
    Headers:
    Request-Context: REDACTED
    x-ms-response-type: REDACTED
    x-ms-middleware-request-id: REDACTED
    openai-version: REDACTED
    openai-organization: REDACTED
    X-Request-ID: REDACTED
    openai-processing-ms: REDACTED
    Strict-Transport-Security: REDACTED
    apim-request-id: REDACTED
    X-Content-Type-Options: REDACTED
    x-ms-region: REDACTED
    azureml-served-by-cluster: REDACTED
    x-request-time: REDACTED
    Date: Fri, 21 Nov 2025 01:23:40 GMT
    Content-Length: 155
    Content-Type: application/json
    

    My agent is a gpt-4o model made from Azure AI Foundry portal UI.
    I'm using Agent Framework and Azure.AI.Agents.Persistent in c#.
    It looks like Pavan-Microsoft is using python, so maybe it won't be the same fix.
    Are you able to help me or should I open an issue in Azure.AI.Agents.Persistent?

  4. Pavan-Microsoft commented on Nov 21, 2025

    @Pavan-Microsoft
    Author

    Hi Ben Thomas (@alliscode)

    How the agents are created: We're creating the agent using AgentsClient.create_agent(...).

    Service/model used: gpt-4o-mini

    Language: Python (async), using the Azure SDKs.

    Sample referred: https://github.com/microsoft/agent-framework/blob/main/python/samples/getting_started/agents/azure_ai_agent/azure_ai_with_azure_ai_search.py

    When the user asks a safety-blocked question (e.g., “how to make a bomb”), the model correctly responds with a refusal message.
    However, if any subsequent request is made within the same thread, getting error

  5. alliscode commented on Nov 21, 2025

    @alliscode
    Member

    Thanks for the information, everyone. We're working to get this resolved.

  6. added
    .NETUsage: [Issues, PRs], Target: .Net
    agentsUsage: [Issues, PRs], Target: Single agent
    bugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)
    on Nov 24, 2025
  7. changed the title [-]Run fails with “Cannot cancel run with status ‘incomplete’” after safety-blocked prompt in same thread[/-] [+].NET: Run fails with “Cannot cancel run with status ‘incomplete’” after safety-blocked prompt in same thread[/+] on Nov 24, 2025
  8. moved this from Bug to In Progress in Agent Frameworkon Dec 1, 2025
  9. moved this from In Progress to Done in Agent Frameworkon Dec 1, 2025
  10. Pavan-Microsoft commented on Dec 2, 2025

    @Pavan-Microsoft
    Author

    Roger Barreto (@rogerbarreto) Is it fixed for python sdk as well?

  11. Pavan-Microsoft commented on Dec 4, 2025

    @Pavan-Microsoft
    Author

    Roger Barreto (@rogerbarreto) Is it fixed for python sdk as well?

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

Metadata

Metadata

Labels

.NETUsage: [Issues, PRs], Target: .NetagentsUsage: [Issues, PRs], Target: Single agentbugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions