fix(ai-chat): emit output-denied state for rejected tool approvals#956
fix(ai-chat): emit output-denied state for rejected tool approvals#956threepointone merged 5 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 21c702c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
|
/bonk review this PR |
Co-authored-by: whoiskatrin <whoiskatrin@users.noreply.github.com>
|
All 173 tests pass, including all 22 test files. Here's my review: PR Review: fix(ai-chat): emit output-denied state for rejected tool approvalsVerdict: Approve -- this is a clean, well-scoped bug fix with good test coverage. SummaryThe core change is a one-line fix at Code review
The fix itself is minimal and correct: state: approved ? "approval-responded" : "output-denied",
Changeset is well-written and scoped to
Escapes Minor observations (non-blocking)
VerdictClean fix, correct logic, good tests. Ship it. |
Adds a new Vitest integration test that verifies when a tool approval is denied, convertToModelMessages produces a tool message containing a tool-approval-response (approved: false) and a tool-result with the expected toolCallId and toolName. The test sets up a worker/agent stub, persists a user and assistant tool approval-request message, sends a cf_agent_tool_approval with approved: false, converts persisted messages to model messages, and asserts the expected tool content. Also imports convertToModelMessages in the test file.
threepointone
left a comment
There was a problem hiding this comment.
very good pr, I added an extra paranoid e2e test for my sake, and merged from main. approved, will land when ci passes
Summary
Fixes #955.
When
CF_AGENT_TOOL_APPROVALis sent withapproved: false,AIChatAgentnow transitions tool parts tooutput-denied(instead ofapproval-responded).This aligns with AI SDK expectations so
convertToModelMessagescan emit atool_resultfor denied approvals (required by Anthropic tool-use sequencing).What changed
packages/ai-chat/src/index.ts_applyToolApproval()now sets:approved: true->approval-respondedapproved: false->output-deniedapprovalobject to preserveapproval.id.packages/ai-chat/src/tests/client-tool-duplicate-message.test.tsoutput-denied.approval-requestedstate also transitions tooutput-deniedand preservesapproval.id.@cloudflare/ai-chatpatch release.Reviewer guide (quick pass)
_applyToolApprovalinpackages/ai-chat/src/index.ts.CF_AGENT_TOOL_APPROVAL handles rejection (approved: false)CF_AGENT_TOOL_APPROVAL with approved: false and autoContinue does NOT continueCF_AGENT_TOOL_APPROVAL rejection from approval-requested sets output-deniedValidation
npm run test:workers --workspace @cloudflare/ai-chat -- src/tests/client-tool-duplicate-message.test.ts -t "rejection|approved: false"