Skip to content

fix: settle approved tool calls that never ran (#2382) - #2392

Merged
threepointone merged 1 commit into
fix/1872-approval-tool-inputfrom
fix/2382-approved-tool-repair
Sep 28, 2026
Merged

threepointone merged 1 commit into
fix/1872-approval-tool-inputfrom
fix/2382-approved-tool-repair

Conversation

@threepointone

@threepointone threepointone commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2382. Stacked on #2391.

Problem

Approving a tool with autoContinue: false and never resubmitting leaves an approval-responded part in the transcript for good. OpenAI-compatible providers then reject every later request, because the tool call has no result. The conversation is stuck.

Change

repairInterruptedToolParts gets a repairApprovalResponded option. With it on, an approval-responded part that is not in the last message is settled:

  • approved: output-error with "The tool call was approved but did not run before the next turn started."
  • denied: output-denied

An approval in the last message is always kept. That covers the autoContinue: false resubmit flow, where the AI SDK runs the approved tool itself.

Think and AIChatAgent turn the option on only for new user and programmatic turns. It stays off for continuations, while a continuation is pending or deferred, and (in Think) while a connection-less continuation is queued. That way an approval that is about to run is never settled early.

Tests

  • repair-transcript.test.ts: 5 tests for approved, denied, last-message and option-off cases.
  • ai-chat stale-approval-repair.test.ts: 2 tests.
  • Think client-tools.test.ts: an approved tool that never ran is settled once the user sends a new message, and the tool never executes.
  • The ai-chat and Think tests fail without the fix.

@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a2287c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
agents Patch
@cloudflare/ai-chat Patch
@cloudflare/think Patch
@cloudflare/agent-think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@threepointone
threepointone added this pull request to stack #2395 September 28, 2026 10:50
@threepointone threepointone changed the title fix(agents,ai-chat,think): settle approved tool calls that never ran (#2382) fix: settle approved tool calls that never ran (#2382) Sep 28, 2026
@agent-think

agent-think Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (f41e4f2e → a2287c61, workflow run)

@threepointone
threepointone force-pushed the fix/2382-approved-tool-repair branch from d9af377 to 7443ec5 Compare September 28, 2026 10:57
@threepointone
threepointone marked this pull request as ready for review September 28, 2026 10:57

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2392

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2392

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2392

hono-agents

npm i https://pkg.pr.new/hono-agents@2392

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2392

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2392

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2392

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2392

commit: a2287c6

@threepointone
threepointone force-pushed the fix/2382-approved-tool-repair branch from 7443ec5 to 75273c9 Compare September 28, 2026 11:36
@threepointone
threepointone force-pushed the fix/2382-approved-tool-repair branch from 75273c9 to a2287c6 Compare September 28, 2026 11:58
@threepointone
threepointone merged commit 4f26402 into main Sep 28, 2026
16 of 30 checks passed
@threepointone
threepointone deleted the fix/2382-approved-tool-repair branch September 28, 2026 12:29
@github-actions github-actions Bot mentioned this pull request Oct 2, 2026
tombeckenham added a commit to tombeckenham/agents-tom that referenced this pull request Oct 7, 2026
…gine

Ports four upstream changes to the legacy AIChatAgent onto AGUIChatAgent:

- cloudflare#2352: clear a stale auto-continuation when the active stream finishes
  with stop and the tool batch is complete (finishReason read from
  RUN_FINISHED via the accumulator).
- cloudflare#2391: a tool call whose arguments complete after its approval request
  refreshes the persisted approval snapshot; the event-to-chunk projection
  re-sends the approval request after the late tool-input-available.
- cloudflare#2392: settle an approved tool call that never ran once a new turn moves
  past it. The pre-turn repair now also runs on submitted turns.
- cloudflare#2040: reconcile reused tool-call IDs one-to-one in the AG-UI reconciler
  (same-call claim, per-row result merge, stale-copy drop).

Test plumbing: the legacy-wire WebSocket wrapper translated each frame once
per listener through a stateful projector, so a second listener lost
chunks. It now translates once per frame.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transcript repair keeps approval-responded tool parts forever; if their continuation never runs, every later turn fails at OpenAI-compatible providers

1 participant