You serve an agent over AG-UI and one of its tools needs a human's approval. Two open bugs break this flow. In TypeScript, a durable Mastra agent pauses for approval and the AG-UI run never ends: no RUN_FINISHED, no interrupt, and the request hangs. In .NET, the approval works, but the next turn sends a history where the tool result has no tool call before it, and an OpenAI-compatible endpoint can reject it. This guide reproduces both and gives a tested workaround for each.
Everything below ran on Nov 28, 2026. TypeScript: @ag-ui/mastra 2.1.0, @mastra/core 1.86.0, @ag-ui/client 1.0.5, Node v24.22.1. .NET: AGUI.Client 1.0.1 with Microsoft.Extensions.AI 10.6.0 and, separately, 11.0.1, on .NET SDK 10.0.404.
We ran every test row 30 times, in two independent passes. All rows were identical in both passes, apart from random ids. The TypeScript tests use a scripted model: no network and no API key. The .NET tests capture the outgoing request and return a synthetic reply, so no model is called there either.
Who this hits
Bug 1, issue #3485 (Mastra). You are affected if all of these are true:
- You wrap a Mastra agent with
createDurableAgent({ agent }). - You serve it through
MastraAgentfrom@ag-ui/mastra, for example behind the CopilotKit runtime. - A tool pauses the run: it has
requireApproval: true, or it callssuspend().
A plain Mastra Agent with the same tools works.
Bug 2, issue #3364 (.NET). You are affected if you use AGUI.Client and your chat history holds a ToolApprovalRequestContent, the message that asked the user to approve a tool call. When you send that history again on the next turn, through AsAGUIMessages or AGUIChatClient, the bug appears. Approved and rejected calls are both affected.
Bug 1: a durable Mastra agent hangs at a tool approval
This is ag-ui-protocol/ag-ui#3485, opened Nov 26, 2026 and still open on Nov 28, 2026. It was reported on @ag-ui/mastra 1.1.6, noting that 2.0.2 has the same code path, with @mastra/core 1.85.0. A non-maintainer offered a one-line patch in a comment on the same day and asked before opening a PR. No PR has been merged. Our search of the repo's PRs for closeOnSuspend on Nov 28, 2026 found none.
The issue describes the symptom: "The AG-UI stream emits the tool call, then nothing: no RUN_FINISHED/interrupt, and the request stays open."
Why it happens
MastraAgent.run() calls agent.stream() without the closeOnSuspend option. In the 2.1.0 package, the local run path builds stream options with memory, runId, clientTools, requestContext and abortSignal, and never closeOnSuspend. For a durable agent, that option defaults to false. The stream stays open at the suspension, so the adapter never sees the end of fullStream and never sends RUN_FINISHED with the interrupt.
The @mastra/core 1.86.0 type docs for closeOnSuspend describe this case:
Defaults to
false: the stream stays open across suspension so a later resume can continue streaming on this same reader. Set totruesofullStream,text, andgetFullOutput()resolve at the suspension boundary (matching non-durableAgent.stream()), letting callers such as AG-UI or A2A react instead of hanging.
Reproduce it
Our test agent has one tool, confirm_operation, with requireApproval: true. The scripted model calls the tool on turn 1 and replies with text on turn 2. The agent is wrapped with createDurableAgent, registered on Mastra with InMemoryStore, and served with new MastraAgent({ agent, resourceId }). Each AG-UI run had 3 seconds to finish. Copied from the result files (identical in both passes):
ROW js repro_3485 case=durable+approval n=30 timeout_ms=3000 interrupt=0 finished_no_interrupt=0 timed_out=30 error=0 ended_without_run_finished=0 tool_execute_calls=0 tool_executed=0 stream_option_keys=memory,runId,clientTools,requestContext,abortSignal stream_closeOnSuspend=undefined
ROW js repro_3485 case=plain+approval n=30 timeout_ms=3000 interrupt=30 finished_no_interrupt=0 timed_out=0 error=0 ended_without_run_finished=0 tool_execute_calls=0 tool_executed=0 stream_option_keys=memory,runId,clientTools,requestContext,abortSignal stream_closeOnSuspend=undefined
The durable agent timed out in 30 of 30 runs. The only event was RUN_STARTED. A longer wait didn't help: with a 30 second timeout, 5 of 5 runs timed out, and again 5 of 5 when we ran it a second time. The plain Agent control ended with RUN_FINISHED and the interrupt in 30 of 30 runs.
A tool that calls suspend() instead of requireApproval behaves the same. The durable agent timed out in 30 of 30 runs, after the tool's execute was called and suspended. The plain Agent ended with the interrupt in 30 of 30.
Fix B: set closeOnSuspend on the wrapped Agent (no Proxy)
This is the fix we recommend. Pass defaultOptions: { closeOnSuspend: true } to the Agent you hand to createDurableAgent. The durable agent merges the wrapped agent's default options into its stream options. From our test code:
import { Mastra } from "@mastra/core";
import { Agent } from "@mastra/core/agent";
import { createDurableAgent } from "@mastra/core/agent/durable";
import { InMemoryStore } from "@mastra/core/storage";
import { MastraAgent } from "@ag-ui/mastra";
const inner = new Agent({
id: "hitl-agent",
name: "hitl-agent",
instructions: "Call confirm_operation, then reply.",
model,
tools: { confirm_operation },
defaultOptions: { closeOnSuspend: true },
});
const durable = createDurableAgent({ agent: inner });
const mastra = new Mastra({ agents: { hitl: durable }, storage: new InMemoryStore() });
const agui = new MastraAgent({ agent: mastra.getAgent("hitl"), resourceId: "user-1" });
Copied from the result files (identical in both passes):
ROW js fix_3485 case=durable+approval+fix=defaultOptions n=30 timeout_ms=3000 interrupt=30 finished_no_interrupt=0 timed_out=0 error=0 ended_without_run_finished=0 tool_executed=0 stream_closeOnSuspend=undefined distinct_event_sequences=1
ROW js fix_3485 case=durable+suspend+fix=defaultOptions n=30 timeout_ms=3000 interrupt=30 finished_no_interrupt=0 timed_out=0 error=0 ended_without_run_finished=0 tool_executed=0 stream_closeOnSuspend=undefined distinct_event_sequences=1
The run ended with the interrupt in 30 of 30 runs, for the approval tool and for the suspend() tool. stream_closeOnSuspend=undefined is expected here. Our spy records the options before the durable agent merges in the defaults.
Fix A: the issue's Proxy, with every other method bound
The issue's own workaround is "a Proxy around the durable agent whose stream adds { closeOnSuspend: true } before MastraAgent sees it." The durable agent has private # fields, so every other method must be bound to the real agent. This is the version we tested:
export function withCloseOnSuspend(agent) {
return new Proxy(agent, {
get(target, key) {
if (key === "stream") return (messages, options) => target.stream(messages, { ...options, closeOnSuspend: true });
const value = Reflect.get(target, key, target);
return typeof value === "function" ? value.bind(target) : value;
},
});
}
const agui = new MastraAgent({ agent: withCloseOnSuspend(mastra.getAgent("hitl")), resourceId: "user-1" });
It ended with the interrupt in 30 of 30 runs, for the approval tool and for the suspend() tool.
Don't use the Proxy unbound. We also wrote it the simple way, returning target[key] for everything except stream. It still produced the interrupt in 30 of 30 runs. But every run logged three TypeErrors: "Cannot read private member #wrappedAgent", from getMemory, listTools and the working-memory snapshot. The adapter then fell back to "sending full history", skipped A2UI, and failed its working-memory snapshot. The run looked fine and the adapter was quietly degraded. Use the bound version, or better, Fix B.
A plain Agent is unaffected by either fix. With Fix A or Fix B on a plain Agent, runs ended with the interrupt in 30 of 30, and the AG-UI event sequences were identical to no fix at all. A plain Agent ignores the option.
The full loop: approve or reject through @ag-ui/mastra 2.1.0
Ending the first run is only half of it. The client then has to send the decision back. @ag-ui/mastra 2.1.0 reads it from input.resume. Start a new run on the same thread, with the interrupt id from the first run's RUN_FINISHED event:
// run 1 ended with RUN_FINISHED, outcome.type "interrupt"; take outcome.interrupts[0].id
const second = {
...first, // same threadId, messages, tools, context, state
runId: crypto.randomUUID(),
resume: [{ interruptId, status: "resolved", payload: { approved: true } }],
};
agui.run(second).subscribe({ next: (event) => { /* ... */ } });
Approval interrupt ids look like mastra-approval::<runId>::<toolCallId>. To reject, send payload: { approved: false }. The 2.1.0 package also accepts status: "cancelled". We did not test that status.
The issue says the client resumes with forwardedProps.command.resume. In 2.1.0, the adapter reads input.resume, as above.
Results, with the fix in place (identical in both passes):
ROW js fix_3485 case=hitl-approve:durable+approval+fix=proxy n=30 timeout_ms=3000 pass=30 run1_interrupt=30 run2_finished=30 run2_interrupt_again=0 run2_timed_out=0 run2_error=0 final_text=30 exec_total=30 exec_0=0 exec_1=30 exec_more=0 model_calls_total=60
ROW js fix_3485 case=hitl-reject:durable+approval+fix=proxy n=30 timeout_ms=3000 pass=30 run1_interrupt=30 run2_finished=30 run2_interrupt_again=0 run2_timed_out=0 run2_error=0 final_text=30 exec_total=0 exec_0=30 exec_1=0 exec_more=0 model_calls_total=60
ROW js fix_3485 case=hitl-approve:durable+approval+fix=proxy+fresh-MastraAgent n=30 timeout_ms=3000 pass=30 run1_interrupt=30 run2_finished=30 run2_interrupt_again=0 run2_timed_out=0 run2_error=0 final_text=30 exec_total=30 exec_0=0 exec_1=30 exec_more=0 model_calls_total=60
ROW js fix_3485 case=hitl-approve:durable+approval+fix=defaultOptions n=30 timeout_ms=3000 pass=30 run1_interrupt=30 run2_finished=30 run2_interrupt_again=0 run2_timed_out=0 run2_error=0 final_text=30 exec_total=30 exec_0=0 exec_1=30 exec_more=0 model_calls_total=60
ROW js fix_3485 case=hitl-reject:durable+approval+fix=defaultOptions n=30 timeout_ms=3000 pass=30 run1_interrupt=30 run2_finished=30 run2_interrupt_again=0 run2_timed_out=0 run2_error=0 final_text=30 exec_total=0 exec_0=30 exec_1=0 exec_more=0 model_calls_total=60
- Approve: the first run ended with the interrupt, the second run finished with the model's final text, and the tool ran exactly once, in 30 of 30 runs, with either fix. No run asked again.
- Reject: the second run finished and the tool ran 0 times, in 30 of 30, with either fix.
- A new adapter for the second run: wrapping the same agent in a fresh
MastraAgentfor the resume also passed 30 of 30. - suspend() tool: resuming with Fix A ran the tool once and finished in 30 of 30.
- Plain Agent controls, no fix: approve, reject and suspend each passed 30 of 30.
These resumes ran in the same process, against the same agent instance and InMemoryStore.
Stuck on an AG-UI approval or resume flow? Send a minimal repro; you pay $79 only when our patch passes it.
Bug 2: the .NET SDK sends an orphaned tool result after an approval
This is ag-ui-protocol/ag-ui#3364, opened Nov 11, 2026 and still open on Nov 28, 2026, with 0 comments. The author published a minimal repro repository. A fix PR, #3418, was open and not merged on Nov 28, 2026.
The issue: "AGUIChatMessageExtensions.AsAGUIMessages loses the call inside ToolApprovalRequestContent.ToolCall while retaining its FunctionResultContent. The resulting history contains an orphaned tool result. AGUIChatClient sends the same malformed sequence."
The impact, quoted from the issue: OpenAI-compatible Chat Completions rejects this history with HTTP 400:
Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls'.
The issue adds: "In the original integrated scenario, this surfaces as a generic AG-UI StreamingError on the next user turn." We did not call a real provider, so we did not reproduce the 400 ourselves.
Why it happens
When a tool needs approval, the assistant message does not hold a plain FunctionCallContent. It holds a ToolApprovalRequestContent, and the tool call sits inside it. AsAGUIMessages only collects FunctionCallContent when it builds the assistant's toolCalls. It doesn't look inside the approval wrapper. So the tool call disappears, while the tool result that answers it is kept.
Reproduce it
We ran the author's repro as is. It builds a history (user, assistant tool call, tool result, assistant reply, next user turn) three ways: with an ordinary call, and with an approval-wrapped call that was rejected or approved. Its output, the same as in the issue:
=== ordinary ===
Input: 1 ordinary call(s), 0 approval-wrapped call(s).
AsAGUIMessages: 1 call(s), 0 orphaned result(s).
AGUIChatClient request: 1 call(s), 0 orphaned result(s).
PASS
=== rejected ===
Input: 0 ordinary call(s), 1 approval-wrapped call(s).
AsAGUIMessages: 0 call(s), 1 orphaned result(s).
AGUIChatClient request: 0 call(s), 1 orphaned result(s).
FAIL: result 'confirm-1' has no preceding tool call.
=== approved ===
Input: 0 ordinary call(s), 1 approval-wrapped call(s).
AsAGUIMessages: 0 call(s), 1 orphaned result(s).
AGUIChatClient request: 0 call(s), 1 orphaned result(s).
FAIL: result 'confirm-1' has no preceding tool call.
It exited with code 1, as designed, in both passes.
Our suite runs the same three histories 30 times each and checks two paths: the output of AsAGUIMessages, and the JSON request that AGUIChatClient actually sends, captured by an HTTP handler. Results, identical in both passes:
| History | Microsoft.Extensions.AI | As is: AsAGUIMessages | As is: AGUIChatClient request | With helper: both paths |
|---|---|---|---|---|
| Ordinary tool call | 10.6.0 | 30/30 pass | 30/30 pass | 30/30 pass |
| Rejected call | 10.6.0 | 0 calls, 1 orphaned: 30/30 fail | 30/30 fail | 1 call, 0 orphaned: 30/30 pass |
| Approved call | 10.6.0 | 0 calls, 1 orphaned: 30/30 fail | 30/30 fail | 1 call, 0 orphaned: 30/30 pass |
| Ordinary tool call | 11.0.1 | 30/30 pass | 30/30 pass | 30/30 pass |
| Rejected call | 11.0.1 | 30/30 fail | 30/30 fail | 30/30 pass |
| Approved call | 11.0.1 | 30/30 fail | 30/30 fail | 30/30 pass |
Upgrading Microsoft.Extensions.AI to 11.0.1 does not fix it. The rows are identical to 10.6.0.
What happens to the assistant message, as is: AsAGUIMessages turns it into an AGUIAssistantMessage with no toolCalls. AGUIChatClient drops it from the request entirely. The 6 input messages became 4 sent messages.
The fix
Before the history reaches AG-UI, replace each ToolApprovalRequestContent with the tool call it wraps. The helper from our suite:
using Microsoft.Extensions.AI;
public static class ApprovalHistoryExtensions
{
// Workaround for ag-ui #3364: replace each ToolApprovalRequestContent with the tool call it wraps,
// so AsAGUIMessages / AGUIChatClient emit the assistant toolCalls entry that the tool result answers.
// Message role, id, author and additional properties are kept; other messages pass through unchanged.
public static IEnumerable<ChatMessage> UnwrapApprovalRequests(this IEnumerable<ChatMessage> messages)
{
foreach (var m in messages)
{
if (!m.Contents.Any(c => c is ToolApprovalRequestContent))
{
yield return m;
continue;
}
var contents = m.Contents.Select(c => c is ToolApprovalRequestContent r ? (AIContent)r.ToolCall : c).ToList();
yield return new ChatMessage(m.Role, contents)
{
MessageId = m.MessageId,
AuthorName = m.AuthorName,
AdditionalProperties = m.AdditionalProperties,
};
}
}
}
Call it before AsAGUIMessages, and before you send the history through AGUIChatClient:
history = history.UnwrapApprovalRequests().ToList();
var wire = history.AsAGUIMessages(JsonSerializerOptions.Web).ToList();
// or
await client.GetResponseAsync(history);
With the helper, the assistant message carries toolCalls with confirm-1, confirm_operation and arguments "{}". The request sent 5 messages instead of 4, and no tool result was orphaned, in 30 of 30 runs for each history, on both paths, with Microsoft.Extensions.AI 10.6.0 and 11.0.1. The ordinary-call control still passed 30 of 30.
What the helper does not change. The user message that holds the ToolApprovalResponseContent, the approve or reject decision, becomes an AGUIUserMessage whose text is the type name Microsoft.Extensions.AI.ToolApprovalResponseContent, not the decision. AGUIChatClient does not send it at all. That was true before and after the fix. So the decision itself is not on the wire. The tool result is, for example Completed. or Rejected.. If your server needs the decision as a separate message, the helper does not give you that.
What we didn't test
- No real model and no API key. The Mastra tests used a scripted model. The .NET tests captured the request and returned a synthetic reply.
- We did not reproduce the HTTP 400 from issue #3364. It is quoted from the issue. We made no OpenAI call.
- Mastra resume from another process with persistent storage. Our resumes ran in the same process, on the same agent instance and
InMemoryStore. - The CopilotKit runtime, and the remote
@mastra/client-jspath. - Microsoft Agent Framework and Blazor.
- The open fix PR #3418, and the unmerged branch offered in the #3485 comment.
FAQ
Why does my Mastra durable agent hang at a tool approval through AG-UI?
Because of issue #3485, open as of Nov 28, 2026. MastraAgent.run() calls agent.stream() without closeOnSuspend, and a durable agent defaults it to false, so the stream stays open at the suspension and no RUN_FINISHED is sent. On @ag-ui/mastra 2.1.0 with @mastra/core 1.86.0, 30 of 30 runs emitted only RUN_STARTED and timed out. A plain Agent finished with the interrupt in 30 of 30.
How do I fix the durable agent hang without a Proxy?
Pass defaultOptions: { closeOnSuspend: true } to the Agent you wrap with createDurableAgent. The durable agent merges the wrapped agent's default options into its stream options. In our tests the run ended with the interrupt in 30 of 30 runs, for an approval tool and for a suspend() tool. A plain Agent behaved the same with or without it.
Is the Proxy workaround from issue #3485 safe?
Only if every method other than stream is bound to the real agent. The bound version ended 30 of 30 runs with the interrupt. Written naively, without bind, it also gave the interrupt in 30 of 30, but every run logged TypeErrors about the private #wrappedAgent field, and the adapter skipped A2UI, sent the full history and failed its working-memory snapshot.
How do I approve or reject a Mastra tool call through @ag-ui/mastra 2.1.0?
Start a new run on the same thread with input.resume set to [{ interruptId, status: 'resolved', payload: { approved: true } }]. Use payload { approved: false } to reject. With the fix, approving ran the tool exactly once and finished in 30 of 30 runs, and rejecting ran it 0 times in 30 of 30. The issue mentions forwardedProps.command.resume, but 2.1.0 reads input.resume.
Why does my AG-UI .NET history have an orphaned tool result and get an HTTP 400?
Because of issue #3364, open as of Nov 28, 2026. In AGUI.Client 1.0.1, AsAGUIMessages only turns FunctionCallContent into tool calls. An approved or rejected call sits inside ToolApprovalRequestContent, so it is dropped and its tool result is left without a call. The issue quotes an OpenAI-compatible endpoint rejecting this with HTTP 400. We did not call a real provider.
How do I work around it in .NET, and does Microsoft.Extensions.AI 11.0.1 fix it?
Replace each ToolApprovalRequestContent with the FunctionCallContent it wraps before you call AsAGUIMessages or send the history through AGUIChatClient. With that helper, approved and rejected histories passed 30 of 30 on both paths. Microsoft.Extensions.AI 11.0.1 alone does not fix it: as is, 0 of 30 passed, the same as 10.6.0. The fix PR #3418 was open and not merged as of Nov 28, 2026.
Related
- Vercel AI SDK tool approval runs twice: why, and how to stop it
- Google ADK for TypeScript: answering one parallel approval re-asks the other
- OpenAI Agents SDK tool approval and resume
- CrewAI human_feedback: resume skips your listeners
There is no AG-UI, Mastra or .NET template on the site yet. You can browse the templates index. If you work in TypeScript and are open to another framework, Tool approval with generateText is a tested Vercel AI SDK (TypeScript) starter, not AG-UI.
Stuck on an AG-UI approval or resume flow? Send a minimal repro; you pay $79 only when our patch passes it.