Skip to content
Source
Sign inSign up
TanStack/ai

permissions() refuses an asked client tool before the user answers the approval #2182

Closedwebberwang(GitHub profile, opens in a new tab) opened this issue 0 comments

Which project does this relate to?

@tanstack/ai-harness 0.3.0 (permissions()), with @tanstack/ai 1.4.0 (also checked in 1.5.0)

Describe the bug

When a permissions() rule decides ask for a client tool (a tool definition with no execute, run by the browser), the call is refused before the user can answer. Approving the approval afterwards does nothing.

What happens at the beforeTools boundary:

  1. permissions()'s onInterruptBoundary opens a tanstack/harness:approval interrupt for the call. The view shows it as an approval, as expected.
  2. In the same pass, emitBoundaryInterrupts → drainBoundaryToolRequests → boundaryToolRequests (activities/chat/index.js) prepares the pending client-tool requests through the tool middleware hooks, including onGuardToolCall.
  3. The permissions guard has no answer for the call yet, so it refuses: This call needs the approval of the user, and this run cannot ask for it. The refusal becomes the call's tool result.
  4. When the user approves, onInterruptResolution records the answer in the resumed run. But the call already has a result, so nothing runs, and the model reads the refusal.

A tool with needsApproval: true doesn't hit this, because boundaryToolRequests holds such a call until its approval resolves. permissions() has no equivalent hold, and a guard can only allow, skip or abort, not wait.

Your Minimal, Reproducible Example

const publish = toolDefinition({ name: 'publish', description: 'Publish', inputSchema: z.object({}) }) // no execute: a client tool
const harness = defineHarness({
  name: 'repro',
  adapter: fakeText(), // scripted: one call of `publish`, then text
  tools: [publish],
  plugins: () => [permissions({ rules: [{ tool: 'publish', decision: 'ask' }] })],
})
// Through createHarnessHandler + createHarnessClient + createSessionView:
// 1. send a message → view.store.get().approvals has 1 approval (correct)
// 2. approvals[0].approve() → no clientTool event ever fires; the model's next
//    request carries the tool result "This call needs the approval of the user,
//    and this run cannot ask for it."

Expected behavior

A client-tool call that a permission rule asks about is held, like a needsApproval call, until its approval resolves. Approved, it goes to the client. Rejected, the model gets the rejection message.

Additional context

This means per-call permission decisions (for example, ask only when an input field selects a priced option) can't be used for browser-run tools. A static needsApproval can't see the input.

  1. tanstack-source added labelsbug

Sign in to join this conversation.