Skip to content

fix(ai): respect cancellation during tool input refinement - #21995

Closed
hulkbig wants to merge 1 commit into
vercel:mainfrom
hulkbig:fix/refine-tool-input-cancellation
Closed

hulkbig wants to merge 1 commit into
vercel:mainfrom
hulkbig:fix/refine-tool-input-cancellation

Conversation

@hulkbig

@hulkbig hulkbig commented Oct 3, 2026

Copy link
Copy Markdown

Background

If experimental_refineToolInput returns a pending promise, cancelling a request or reaching its timeout does not stop generateText or streamText from waiting. The same problem affects revalidation of previously approved tool calls.

Summary

Pass the existing abort signal to every refinement path and reuse the abort-aware promise helper already used by tool-call repair. Preserve cancellation through approval validation and streaming so it follows the normal abort path instead of becoming an invalid tool input or an ordinary stream error. The refinement callback API stays the same.

Add 14 mocked regression cases covering ordinary, dynamic, repaired, and approved calls; request cancellation; step/total timeouts; an already-aborted signal; and late callback rejection. Before the fix, 13 of the 14 cases failed.

Validation

  • Full ai Node suite: 4,190 passed, 3 skipped.
  • Full ai Edge suite: 4,182 passed, 4 skipped.
  • Root pnpm type-check:full, including examples: passed.
  • ai package build and lint on changed TypeScript files: passed.
  • Node 24.18.0; pnpm 11.23.0.

An initial type-check run overlapped with the package build and reported missing generated declarations. Regenerating declarations and rerunning the type check sequentially passed. No live-provider end-to-end test was run; the regression tests use mocked models and timers.

AI assistance: this patch and its tests were developed and reviewed with Codex. All results above were run locally against this change.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Related to #20942, which protects repairToolCall; this change covers the separate refinement callback.

@hulkbig

hulkbig commented Oct 5, 2026

Copy link
Copy Markdown
Author

Could a maintainer approve the pending fork workflows for head aad03030dc591aa6a6d1e96b5b3a4317ebbbf7fb? The CI run and latest Verify Changesets run currently require approval and have no jobs yet.

The Vercel preview separately reports “Authorization required to deploy” and needs a Vercel team member to authorize it through the existing check link. I will address any failures once the tests can run.

@hulkbig hulkbig closed this Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant