Skip to content

[AI-3747] A tool's yes needs the caller's answer to its question - #2431

Merged
kanat merged 17 commits into
mainfrom
kanat/ai-3747-approval-needs-caller-answer
Nov 25, 2026
Merged

kanat merged 17 commits into
mainfrom
kanat/ai-3747-approval-needs-caller-answer

Conversation

@kanat

@kanat kanat commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Why

On a voice call, a tool with an approval question runs only after the caller says yes. The router took any confirm_tool_call(allowed: true) for a waiting call as that yes. It did not check that the caller had heard the question or spoken since. When the id matched no waiting call, it used the only one waiting. Details: AI-3747.

How it works

A yes runs the call only when all three hold. Anything else is answered back to the model with what is missing, and runs nothing.

confirm_tool_call(tool_call_id, allowed)
├─ allowed: false ───────────────────────── declined, no caller turn needed; the id may be empty
│                                            or wrong when one call waits (declining is always safe)
└─ allowed: true
   ├─ id names no waiting call ─────────────── "no question waiting" (no fallback)
   ├─ question cut off (barge-in, voice failed) ─ refused, call closed
   ├─ question not played to its end ──────────── refused, call still waits
   ├─ no caller speech since it played ────────── refused, call still waits
   └─ else ─────────────────────────────────────── runs once
State on approval Cascade (STT -> LLM -> TTS) Native speech-to-speech
said askLocked gives the question to the voice a later reply (not the one that made the call) completed with speech
cut interrupted on the question's turn that reply completed interrupted
played + heard the agent is quiet (tickApprovals), or the edge is drained at the caller's next turn; heard keeps callerTurns then same
callerTurns++ a spoken turn is kept (respondTurn, adoptSpeculation), or a turn the caller typed on their own device (callerTyped: a caller named, not a customer's server, not a scheduled task) SpeechStopped in receiveSTS, in order with tool calls; a typed turn in respondNative

Text that is not the caller's own counts for nothing: a yes in a tool result, in model text, from a customer's server, from a scheduled task, or written by the agent.

Barge-in is decided as follows. A question the caller talked over, or the voice refused, counts as not heard. A yes to it runs nothing and closes the call. A question cut off can never be answered, so a yes to it closes the call (ToolApprovalDecided "Question not heard") and the model is told to call the tool again.

Validation

Base column: the same test run on main dca845c2e. "fail" there is the defect the test catches.

Case Test Base
yes in the turn that made the call TestAYesInTheTurnThatMadeTheCallRunsNothing fail (call ran)
no in that turn still declines TestANoInTheTurnThatMadeTheCallDeclinesIt pass (control)
yes after the question, before the caller spoke (text with no caller behind it), then a spoken yes TestAYesBeforeTheCallerSpokeRunsNothingAndTheCallWaits fail (call ran)
typed yes from the caller after the question played TestATypedYesFromTheCallerAfterTheQuestionPlayedRunsTheCallOnce not run on main; mutation-checked
yes after a turn a server or a scheduled task wrote TestAYesThatIsNotTheCallersOwnTurnRunsNothing not run on main; mutation-checked
no with an empty or wrong id, one call waiting TestANoUnderAnotherIDDeclinesTheOnlyCallWaiting not run on main; mutation-checked
no with a wrong id, two calls waiting TestANoUnderAnotherIDDeclinesNothingWhenTwoCallsWait not run on main; mutation-checked
yes after the caller answered TestAYesRunsTheCallOnceWithItsOwnID (existing) pass
yes in a reply speculated for the caller's turn TestAYesInAReplySpeculatedForTheCallersTurnRunsTheCall pass (control)
empty or other id with one call waiting TestAYesUnderAnotherIDRunsNothing fail (call ran)
barge-in during the question TestAYesToAQuestionTheCallerTalkedOverRunsNothing fail (call ran)
voice refused the question TestAYesToAQuestionTheVoiceRefusedRunsNothing fail
a second question cut off leaves the first TestCuttingOffASecondQuestionLeavesTheFirstStanding pass (control)
native: yes right after it was told to ask TestANativeYesBeforeTheQuestionWasSaidRunsNothing fail (call ran)
native: the reply after it said nothing TestANativeYesAfterAReplyThatSaidNothingRunsNothing fail
native: only the reply that made the call spoke TestANativeYesAfterOnlyTheReplyThatMadeTheCallSpokeRunsNothing fail
native: played, no caller speech; then a cut reply, speech, and the yes runs TestANativeYesBeforeTheCallerSpokeRunsNothing fail
native: words said while the question still played TestANativeYesToWordsSaidOverTheQuestionRunsNothing fail
native: barge-in during the question TestANativeYesToAQuestionTheCallerCutIntoRunsNothing fail
native: typed yes after the question played TestANativeTypedYesAfterTheQuestionPlayedRunsTheCallOnce not run on main; mutation-checked
native: yes after text a server wrote TestANativeYesToTextAServerWroteRunsNothing not run on main; mutation-checked
native: question said, caller spoke, yes TestANativeModelsConfirmationRunsTheCallWithItsOwnID (now with speech) pass
text chat asks nothing TestAToolThatNeedsApprovalIsNotAskedAboutInWriting (existing) pass (control)
  • go test ./internal/agent/ passes on the branch merged with main.
  • Every changed condition was mutated in one batched script: 41 of 41 mutants fail a test (final head).
  • Approval tests pass -count=50, -count=50 -cpu 1 and -race -count=10.

🤖 Generated with Claude Code

kanat and others added 12 commits November 24, 2026 23:22
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion and two questions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to an approval question

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[security R1] NO-GO — 2 Should fix, 2 Questions (ticket candidates).

The new rules hold for the routes checked: an exact id on a yes, no fallback for allowed: true, server-side, scheduled and caller-less typed turns not counted, cut-off questions closing the call, a decline scoped to this agent's own waiting call. 15 mutations of the new guards were tried, 13 killed by the PR's tests.

  • S1.1 [Should fix]: a question counts as played on an edge-queue check alone (see inline comment on heardLocked).
  • S1.2 [Should fix]: the drain gates in respondTurn and tickApprovals survive mutation (see inline comment on tickApprovals).
  • S1.3 [Question]: on a native speech-to-speech model, any voice-activity stop from the provider counts as the caller's turn (native.go SpeechStopped). It has no echo filter like the cascade's. Ticket candidate, not verified without live audio.
  • S1.4 [Question]: on a native model the router cannot check that the reply it marks as said held the question. This is by design of the change. Ticket only if a router-side check is wanted.

The failing test rows go to the fixer through the ticket.

Comment thread acceleration/internal/agent/approval.go Resolved
Comment thread acceleration/internal/agent/approval.go Resolved

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: NO-GO

Reviewed ec823c6 merged onto main 7e3836b. This is a draft, so CI ran only CodeQL, Analyze, GitGuardian and labeler, and all of them pass. go and integration run at gh pr ready. go test ./internal/agent/ passes on the merged tree, with build, vet and gofmt clean.

[Should fix] R1.1 (inline on approval.go:198): at the caller's turn a question counts as played as soon as the edge has nothing buffered. That is also true before the voice has produced any audio for the question. A typed turn from the caller at that point is then taken as the answer, and a yes in the reply to it runs the call.

[Should fix] R1.2: 5 of 11 extra mutants survive. Inline comments on the lines give a test row for each one, and each row fails under its mutant and passes on this head.

[Nit] R1.3 (inline on approval.go:234): on native, any later reply with audio marks the question said. This goes to a ticket.

Checked and sound:

  • The paths table: same-turn yes, yes before the caller spoke, wrong or empty id, no at any time, barge-in, native before playout, and text chat unchanged.
  • The caller's own turn: only a socket or request principal and scheduled delivery put a caller on the context. Chat-hook follow-ups, the consent callback and delegated results carry none, so no model or tool text is counted as a caller turn.
  • An earlier caller turn cannot answer a later question: heard is snapshotted when the question has played.
  • Two pending calls, and a call that lapses.
  • The new state is under Agent.mu, and no lock is held longer.

Verdict: request changes, for R1.1 and R1.2.

Comment thread acceleration/internal/agent/approval.go Resolved
Comment thread acceleration/internal/agent/agent.go Resolved
Comment thread acceleration/internal/agent/approval.go Resolved
Comment thread acceleration/internal/agent/native.go Resolved
Comment thread acceleration/internal/agent/approval.go Resolved
Comment thread acceleration/internal/agent/approval.go Resolved
kanat and others added 3 commits November 25, 2026 09:03
… quiet; tests for the surviving mutants

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eck); speculation row; why adoptSpeculation reads the edge

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ion filters; the own-reply test reaches the quiet floor

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: GO
Delta review of 814cd75 (scratch-merged onto origin/main 6395c5f).

Prior findings

  • S1.1 = R1.1: fixed. heardLocked marks a question played only when the edge is drained and quietLocked() holds (the test the tick already used). I re-ran the security probes and reviewer probes P1-P7 on the merged head: 10 of 10 pass. With the fix reverted, P1, TestSecProbeTypedTurnBeforeTheQuestionsAudioRunsNothing and the PR's TestTypedYesBeforeTheQuestionsAudioRunsNothing fail.
  • S1.2: fixed. The tick playedLocked(true) and respondTurn drained := true mutants are killed.
  • R1.2: fixed. Killed: respondTurn drained always and never, native typed and stop drained always, tick marks played when not quiet, tick does not mark played, heard snapshot zero, no-fallback without lapsed == "", said-after-voice. Heard-drops-drained and heard-drops-quiet are killed too.
  • R1.2, adoptSpeculation drained := true: survives, and I accept it. Adoption needs !generating, an unchanged history length and the same harness. A question asked after the speculation started appends to history, so it is not adoptable. A question already on the edge makes speculate refuse. The one path that speculates over the agent (secondOpinion, overAgent) ends in a Stop ruling, which interrupts and cuts the question (cutLocked), so a yes to it is refused whatever played says. I found no reachable row.
  • Changed author test TestANativeYesAfterOnlyTheReplyThatMadeTheCallSpokeRunsNothing: it still tests its name. The call's own reply r1 spoke, the question reply r2 is silent, the caller speaks, and a yes is refused ("has not heard the question"). The added r2 only lets the test reach the "own reply counts" mutant instead of being masked by the quiet floor.
  • S1.3, S1.4, R1.3: tickets, not touched, not blocking.

New findings (delta hunks only; none blocking)

  • [Nit] approval.go:211 quietLocked: dropping !a.generating (X1) or !a.nativeAwaiting (X3) survives. generating covers only the microsecond gap in askLocked between the unlock and begin(), which no test can hit without a hook. nativeAwaiting is redundant for a native question, because the question is marked said only when its reply completed with audio, and the edge check covers the playout. Both conjuncts were already in tickApprovals.
  • [Nit] TestTypedYesBeforeTheQuestionsAudioRunsNothing and TestSpokenYesWhileTheQuestionIsOnTheEdgeRunsNothing pass "" to confirmationSays, which matches any text. The s.Empty(runner.asked()) assertion carries them and killed the mutants.
  • [Nit] speculate.go:283: the comment could add that over-agent speculation is cut by its Stop ruling.

Runs on the merged head

  • Mutations: 17 checked, 13 killed, 4 survived (adoption drained, which appears twice as R6 and X6, then X1 and X3, all accepted above).
  • -count=20 -cpu 1, approval filter: ok (786s).
  • -race -count=5: the first run failed only on TestAudioANativeModelHeardIsNotJudgedForWords (silence_test.go:233, a file this PR does not touch). That is the known base flake fixed by AI-3803 in #2424. It passes alone under -race -count=30, and a full rerun of the approval filter under -race -count=5 is ok (299s).
  • CI: draft, so go and integration are skipped; CodeQL, labeler and GitGuardian pass.

@kanat
kanat marked this pull request as ready for review November 25, 2026 17:01
@kanat
kanat merged commit a8eedf7 into main Nov 25, 2026
13 checks passed
@kanat
kanat deleted the kanat/ai-3747-approval-needs-caller-answer branch November 25, 2026 18:36
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