Skip to content

fix(examples): finalize open tool calls when the v1 example's turn is cancelled - #327

Merged
benbrandt merged 1 commit into
mainfrom
v1-example-finalize-tool-calls
Oct 30, 2026
Merged

benbrandt merged 1 commit into
mainfrom
v1-example-finalize-tool-calls

Conversation

@benbrandt

Copy link
Copy Markdown
Member

The v1 example agent (src/examples/agent.ts) could leave a tool call pending (e.g. call_1) if the turn was cancelled between steps.

Now prompt tracks the tool calls opened during the turn and, when the turn ends early (cancelled or errored), sends a final tool_call_update with status failed for each unfinished one before responding. v1 has no cancelled tool call status, so failed is the right final status.

Tested by driving the agent over stdio and sending session/cancel right after call_1 appears: before this change the turn returned cancelled with call_1 still pending; now call_1 gets failed first. Cancelling during the permission request still fails call_2 once. npm run check passes.

🤖 Generated with Claude Code

… cancelled

The v1 example agent left a tool call pending when the turn was
cancelled mid-way. Track open tool calls per turn and send a final
`failed` update (v1 has no `cancelled` tool call status) for each
before the prompt response returns.

Co-Authored-By: Claude <noreply@anthropic.com>
@benbrandt
benbrandt enabled auto-merge (squash) October 30, 2026 17:56
@benbrandt
benbrandt merged commit c959b06 into main Oct 30, 2026
5 checks passed
@benbrandt
benbrandt deleted the v1-example-finalize-tool-calls branch October 30, 2026 18:03
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.

1 participant