Auto-continuation after tool approval
- Dominant language
- TypeScript
- Stars
- 349
- Forks
- 92
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 24
Description
## The gap
Human approval of a tool call takes **two** `generateText` calls:
1. `generateText({ prompt })` returns a tool call marked `needsApproval` and stops.
2. The user approves, `approveToolCall()` saves an approval message.
3. **The app has to call `generateText({ promptMessageId })` again** before the tool runs.
Approving does not resume anything, so an app that stops at step 2 silently strands the approval, and nothing in the API signals a second call is required.
The stop comes from `willContinue` in `src/vercel/client/utils.ts`:
```ts
if (step.toolCalls.length > completedOutputs) return false;
```
A tool awaiting approval has no result. Correct for the pause, but nothing recognises that the call is ready once the approval lands.
## What it should do
Approving a tool call resumes generation without a second request from the caller.
## Design worth keeping
Supersedes #217 and #219, which built this against AI SDK v6 and cannot be carried to v7. Their decisions are worth reusing:
- **Save-only approve/deny, execution deferred.** Approving records intent; the tool runs on resumption.
- **Atomic stream finish with message save**, fixing a race between the two.
- **Atomic idempotency check** for the double-approval window, throwing if already handled.
- **Indexed approval lookup**, so `approveToolCall` is O(1).
- **Continuation streams into a separate message**, not the one that requested approval.
- **Non-string tool outputs** work, via AI SDK's `createToolModelOutput`.
Those PRs also carry ~1,900 lines of tests, including `approval-bugs.test.ts`, which names the defects found while building it. Worth reading before reimplementing.
## Open question
Whether this belongs in v1. Agent v2 makes approval a first-class Run state (`waiting` with `reason: "approval"`, resolved via `agent.toolCalls.approve` / `.deny`), which is Slice 6. If v2 lands first this is wasted work, so decide before starting.
Contributor guide
Research direction
First resolve whether this belongs in v1 or should wait for Agent v2's approval Run state. Read src/vercel/client/utils.ts, approveToolCall, and the superseding issues' approval-bugs.test.ts and related tests before defining the continuation flow. Done means approval resumes generation without a second caller request while preserving the listed atomicity, idempotency, lookup, stream, and output requirements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100