agent-native icon indicating copy to clipboard operation
agent-native copied to clipboard

Approving a tool call re-prompts the model instead of replaying the approved call, so long writes loop and don't save

Open nabilkhan199999 opened this issue 1 month ago • 1 comments

Summary

When a tool call needs approval and the user clicks Approve, the approved call is usually not replayed. The run goes back to the model, which issues the call again. Approval is matched on the exact input, so if the regenerated input differs at all, which it almost always does for long content such as a full skill, a new approval is requested and nothing is saved. Clicking Approve again repeats this.

In one case a short input (a one-line skill) did save after Approve, because the model happened to regenerate it identically.

The cause seems to be on the client side. The request sent on Approve carries the approval key, but its structuredHistory doesn't include the pending call, so the server has nothing to replay.

Environment

  • App: we first noticed the symptom in our internal app built on Agent-Native. Reproduced in a freshly scaffolded app (create --standalone --template chat), run with agent-native dev.
  • @agent-native/core: 0.207.1
  • @agent-native/toolkit: 0.207.1
  • Model: gpt-6-luna via ai-sdk:openai, effort high, Act mode
  • We use createAgentChatPlugin with the built-in chat transport and the framework's chat UI.
  • We do not use a custom chat engine or history serializer.
  • No page reload between the approval card appearing and clicking Approve.

Steps and observed behavior

Skill names and paths below are placeholders.

Run 1, new chat (long write, loops):

  1. Ask the agent to create a shared skill of about 300 words on any topic.
  2. The agent calls resources with action: "write", scope: "shared" and about 2,600 characters of content. requiresSharedResourceApproval requires approval, and the card "Approve to run resources?" appears.
  3. Click Approve.
  4. The new run shows "Contacting model", not "Running approved resources action". The model issues a new write to the same path, and approval_required fires again.
  5. Click Approve again. The same thing happens. Nothing is saved.

Run 2, same pattern, where we compared the content:

  1. In another chat, the approved call's content and the model's new call after Approve had different headings and different opening paragraphs. A new approval was requested, and nothing was saved.

Run 3, short write (saved):

  1. Ask for a one-line shared skill, then click Approve. The model's new call has the same input, the approval key matches, and it saves (Wrote resource: skills/<name>/SKILL.md (28 bytes)).

Run 4, a batch over several skills (repeats completed work):

  1. Ask the agent to shorten every skill, personal and shared. It shortens a personal skill without approval, then requests approval for a shared one.
  2. After the first Approve, the model started the task again from the beginning and applied the completed personal writes a second time. The built-in personal learn skill went from 1,217 to 634 bytes in the first run, then to 588 bytes after that Approve. Later approvals in the same turn kept producing new approval requests, and we stopped it with Deny after three.

In one of about six approvals during testing, the replay did run ("Running approved resources action" and a successful write). We couldn't tell what was different about that case.

What the Approve request shows (run 1)

We logged the body of the POST sent when Approve was clicked. A second chat, where the dev server had reloaded before Approve, showed the same pattern.

Field Contents
approvedToolCalls One key, resources:{"action":"write","content":"… (2,684 characters)
structuredHistory An earlier completed read of a shared skill and its result. No entry for the pending write.

Relevant code observations in 0.207.1

These are static observations from the published dist/:

  • In dist/agent/production-agent.js, findApprovedStructuredToolCall (around line 3305) looks in the request's structuredHistory for a tool call whose key is in approvedToolCalls and whose result says it did not execute. When it finds one, the server runs that call directly ("Running approved … action", around line 8837 onwards). When it doesn't, the request falls through to a normal model turn.

  • In dist/client/chat/runtime.js, pendingApprovalRuntimeMessages (around line 1897) builds the pending part of structuredHistory for an approval continuation. At around line 1924 it skips any tool call without a result:

    if (part.type !== "tool-call" || part.result === undefined)
        continue;
    

    A call that is waiting for approval hasn't run, so it has no result. It looks like this is the call that gets skipped, which would explain the empty match on the server.

As a local experiment, we let the pending call through to that history with a "did NOT execute" result. In the one run we tried, Approve then replayed the call directly ("Running approved resources action", then Wrote resource: skills/<name>/SKILL.md (2695 bytes)), with no second approval.

Expected behavior

Clicking Approve runs the call that was approved, with the input that was shown for approval, without asking the model to produce it again.

Impact

  • In our testing, long writes that need approval could not be completed from chat. For us that includes edits to shared skills.
  • Each approval can repeat completed work. If earlier calls in the turn had side effects, they may be applied again.
  • From the user's side, approval cards keep appearing and nothing is saved, so approval looks broken. Typing "approve" in chat, which is the natural next thing to try, starts another turn and another approval.

Possible directions

We don't know the history of this code, so these are options rather than a recommendation:

  • On the client, include the call that is awaiting approval in the pending approval history, so the server's existing replay path can find it. This is the experiment above.
  • On the server, replay from the call input it already holds when it creates the approval request, rather than relying on the client to send the call back. That might also cover the case where the page has been reloaded before the user approves, which we haven't tested.
  • Whichever route, if a replay isn't possible, it might help to tell the user the approval couldn't be applied, rather than silently handing the turn back to the model.

nabilkhan199999 avatar Oct 13 '26 15:10 nabilkhan199999

Thanks for the detailed report and reproduction steps. PR #7506 is merged as 9bb5cda on main. The approval continuation now keeps the approved tool call in replay history when the gate emits its placeholder tool_done, so the server can execute the original approved input. The regression covers the server's detailed placeholder event as well. The fix is in the merged source, so I’m closing this issue.

steve8708 avatar Oct 14 '26 01:10 steve8708