Repository navigation
.NET: Run fails with “Cannot cancel run with status ‘incomplete’” after safety-blocked prompt in same thread #2298
Description
Activity
- addedtriageUsage: [Issues], Target: All issues that still need to be triagedUsage: [Issues], Target: All issues that still need to be triaged
on Nov 18, 2025 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.
- removedtriageUsage: [Issues], Target: All issues that still need to be triagedUsage: [Issues], Target: All issues that still need to be triaged
on Nov 20, 2025 Hi Ben Thomas (@alliscode) I am also hitting this issue.
I've traced the origin to Azure.AI.Agents.Persistent Specifically in
PersistentAgentsChatClient.GetStreamingResponseAsyncIt 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.Statusisincomplete, 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/jsonMy 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?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 errorThanks for the information, everyone. We're working to get this resolved.
- added.NETUsage: [Issues, PRs], Target: .NetUsage: [Issues, PRs], Target: .NetagentsUsage: [Issues, PRs], Target: Single agentUsage: [Issues, PRs], Target: Single agentbugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)Usage: [Issues], Target: all issues (Legacy, prefer issue type: bug)
on Nov 24, 2025 - 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 - moved this from Planned to Bug in Agent Framework
on Nov 28, 2025 Roger Barreto (@rogerbarreto) Is it fixed for python sdk as well?
Roger Barreto (@rogerbarreto) Is it fixed for python sdk as well?
- added a commit that references this issue
on Jan 12, 2026
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
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