Skip to content

[AI-3614] Log an approved tool call under its own name - #2250

Merged
kanat merged 6 commits into
mainfrom
kanat/ai-3614-approved-tool-line
Nov 23, 2026
Merged

kanat merged 6 commits into
mainfrom
kanat/ai-3614-approved-tool-line

Conversation

@kanat

@kanat kanat commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

When a caller says yes to a tool call on a voice call, the tool runs inside the model's confirm_tool_call (acceleration/internal/agent/approval.go, confirm). On main the only "a tool call came back" line for that run says tool=confirm_tool_call, and the original call's line says outcome=refused. An operator who reads the logs after "send the email" sees confirm_tool_call succeed and send_email refused, and cannot see that the email tool ran (AI-3614, found in the #2217 round-1 review).

How it works

caller asks          send_email ── executeTool ── askApproval
                     line: tool=send_email outcome=refused approval=asked   (new key)

caller says yes      confirm_tool_call ── executeTool ── confirm
                                                  └─ ToolRunner.Run(send_email)
                     line: tool=send_email tool_call=<original id>          (new line)
                           connector, success, error_code, outcome,
                           duration_ms of the run, approval=allowed,
                           confirmation=<confirm id>
                     line: tool=confirm_tool_call, its own success/outcome,
                           no connector, error_code or error                (changed)

caller says no /     confirm_tool_call ── confirm (runs nothing)
late yes             line: tool=confirm_tool_call ...                       (as on main)

The approved run gets its own report (WithToolReport) so its line carries its connector and failure. The confirm_tool_call line no longer carries them (loggedAnswer: app, agent, success only), so a count by connector or error code counts an approved run once. Only a confirmation that ran the approved call is cut down this way: one that failed on its own and ran nothing (arguments that are not an answer, a native call the router refused, a caller's own tool named confirm_tool_call) keeps its error_code and error, because no run line carries them. In writing nothing asks (approvalQuestion returns "" for a text agent; the app approves), so text calls already log under their own name.

outcome and the router_agent_tool_call_seconds label stay as they are: chat infra/shards/us-east{1,4}-acceleration/datadog/launch_tool_calls.tf excludes outcome:refused from the tool error-rate and p95-latency monitors, so a new outcome value for an asked call would pull its near-zero samples into both. The approved run adds no metric sample: the confirmation's sample already times it.

Line Before After
asked call tool=send_email tool_call=call-1 outcome=refused same, plus approval=asked
approved run none tool=send_email tool_call=call-1 connector=gmail outcome=ok success=true error_code="" duration_ms=812 approval=allowed confirmation=call-2
confirmation tool=confirm_tool_call tool_call=call-2 connector=gmail outcome=ok error_code="" duration_ms=815 tool=confirm_tool_call tool_call=call-2 outcome=ok success=true duration_ms=815 (no connector, error_code, error)
a tool that asks nothing unchanged unchanged

(Ids and numbers are made up.)

ClickHouse: the new line has the same msg as before, so logs.agent_session_events already types its tool, outcome, connector, success, error_code and duration_ms. The two new keys approval and confirmation stay in body until a chat ticket adds columns for them.

Changes

  • confirm logs the approved run under the call's own name, id and turn, with its own runner report, run duration and outcome (toolOutcome, answered and cancelled as the confirmation is).
  • The confirm_tool_call line drops the run's connector, error_code and error when confirm ran the approved call (it returns ran); the run's own line has them. A confirmation that ran nothing keeps its own error.
  • The line of a call answered with its approval question gains approval=asked.
  • logToolBack writes the line for both, so the field set is defined once.

Validation

  • go test ./internal/agent/ -count=1 on head bccd0fd (merged with main 644103a): ok. go vet, gofmt -l: clean.
  • Base probe on dff7498: the asked line, the confirmation line and a connector call that asks nothing log the key sets the tests pin (askedLineKeys, connectorLineKeys). The new tests fail on base (no approval key, 2 lines instead of 3); the control (TestAConnectorCallThatAnsweredNamesItsConnector) passes there.
Test Defect it catches
TestAnApprovedCallIsLoggedUnderItsOwnName no run line, wrong name/id/turn/connector/duration, a confirmation line that keeps the connector, a second metric sample
TestAnApprovedCallThatFailedIsLoggedAsFailed the run's failure not on its line, the returned error's text logged, a confirmation line that keeps the error
TestAnApprovedCallTheCallerTalkedOverIsLoggedAsStillRunning a held run logged as ok
TestAnApprovedCallCancelledByTheCallerIsLoggedAsCancelled a cancelled run logged as an error
TestAConfirmationThatFailedOnItsOwnKeepsItsError, TestANativeConfirmationTheRouterRefusedKeepsItsError, TestACallersToolNamedConfirmToolCallKeepsItsError a confirmation that ran nothing losing its error (keyed on the name, not on a run)
TestADeclinedCallLogsNoRun a run line for a no
TestAConnectorCallThatAnsweredNamesItsConnector (control) any key change on a call that asks nothing

27 mutants in the round-2 review: 23 killed, 1 equivalent (dead no-runner return), 3 survive on declined/lapsed/unknown returns where only an empty error_code differs (accepted).

🤖 Generated with Claude Code

kanat and others added 4 commits November 23, 2026 18:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n is

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The approved run has its own line with them; a count by connector counted it twice.

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.

Reviewed 64f0f16fa merged onto main ba73ccc6b. CI: draft, so go and integration were skipped (#2130). CodeQL and GitGuardian passed.

Checked and sound:

  • the asked call keeps outcome=refused, and router_agent_tool_call_seconds gets no new sample or label (it matches the chat monitors' !outcome:refused scope);
  • the approved run's duration_ms covers only Run;
  • the outcomes for talked-over, cancelled and declined calls;
  • the field set of a call that asks nothing equals main's (base control);
  • no tool arguments or results are logged;
  • the new tests pass with -race -count=20;
  • 19 mutants, all killed.

Verdict: request changes, for R1.1.

// The confirmation's line is about the answer; the approved run's own line carries the
// connector and the error, so a count by either does not count a run twice.
fields := a.loggedTool(*report, err)
if requested.Call.Name == confirmTool {

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.

[Should fix] R1.1 This keys on the name, so a confirm_tool_call that fails on its own and runs nothing also loses its error_code and error. There is then no run line, and the reason is logged nowhere. Probe with arguments {"tool_call_id":"call-1","allowed":{"a":1}}: main logs outcome=error success=false error_code=error error="agent: confirm_tool_call's arguments: json: cannot unmarshal object ..."; this head logs outcome=error success=false and nothing else. The same applies to a native confirmation refused in native.go:199 and :211 (the refusal branch), and to a call to a caller's own tool named confirm_tool_call (offersConfirm is false, approval.go:133).

Fix: use loggedAnswer only when confirm ran the call, for example by having confirm return a ran bool. Otherwise keep loggedTool(*report, err). The outer report is empty for a confirmation, so it carries no connector. Test row, which I checked fails on this head and passes with that change: TestAConfirmationThatFailedOnItsOwnKeepsItsError: confirmedLines({"tool_call_id":"call-1","allowed":{"yes":1}}, nil) gives 2 lines; lines[1] has tool=confirm_tool_call, success=false, error_code="error", and an error that contains confirm_tool_call's arguments.

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.

Fixed in 28b6eb8 (merged onto main in bccd0fd): confirm returns ran, and only a confirmation that ran the approved call gets the answer-only line; any other keeps loggedTool(*report, err). Tests: TestAConfirmationThatFailedOnItsOwnKeepsItsError (bad args), TestANativeConfirmationTheRouterRefusedKeepsItsError, TestACallersToolNamedConfirmToolCallKeepsItsError. Mutations: matching on the name again, ran always true, ran never true: each fails the tests named in the report.

hold := a.toolHolds[confirmation.ID]
answered := hold != nil && hold.answered
a.mu.Unlock()
a.logToolBack(call, a.loggedTool(*report, err), time.Since(began), toolOutcome(ctx.Err() != nil, err != nil, false, answered),

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.

[Nit] R1.2 An approved run that fails now gives two a tool call came back lines with outcome=error: the run's and the confirmation's. The metric still has one sample. The tool_call_errors runbook (chat infra/shards/us-east{1,4}-acceleration/datadog/launch_tool_calls.tf:73) says to read the outcome=error lines grouped by tool, so a count of those lines no longer matches the alert's count. Ticket: say in the runbook that confirm_tool_call lines repeat the run they confirm (or filter them out).

kanat and others added 2 commits November 23, 2026 20:19
The confirmation's line dropped the run's error by the name confirm_tool_call,
so a confirmation that ran nothing (bad arguments, a native call the router
refused, a caller's own tool of that name) logged its failure nowhere. confirm
now says whether it ran the approved call, and only then is the line about the
answer.

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 round 2, head bccd0fd merged onto main e416613)

Prior findings

  • R1.1 (a confirmation that failed on its own lost its error): fixed. confirm now returns ran (approval.go:231, true only after ToolRunner.Run returned), and telephony.go:759 cuts the line down only when it did. Bad arguments, a native refusal and a caller's own tool named confirm_tool_call keep error_code and error. The ran flag is true for an approved run that succeeded, failed, was cancelled mid-run, or was talked over, and false for declined, lapsed, unknown and the three failure cases (tests pin each).
  • R1.2 (runbook counts an approved failed run twice): ticket, not in this PR.

Checks

  • Round-1 mutation scripts rerun on this head (R1, R16, R19 no longer match the fixed code; I ran their equivalents): 27 mutants, 23 killed. Name match restored, confirmed never/always, ran false after the run, bad-args true, a second metric sample, and every round-1 mutant are killed.
  • Survivors: the no-runner branch returning true is an equivalent mutant (offersConfirm, approval.go:130, needs a runner before confirm is reached). Declined, lapsed and unknown returning true change only whether the line carries error_code=""; Nit, no action.
  • go test ./internal/agent/ -count=1 on the merge with current main: ok. New and ApprovedCall tests: -race -count=10 and -cpu 1 -count=20 ok. go vet and gofmt clean.
  • PR body is this PR's own and matches the code.
  • Nit (PR body): Validation names main 5d25eda and "14 mutants"; refresh to the final head at GO.
  • CI: draft, go and integration skipped (#2130); the other checks pass.

@kanat
kanat marked this pull request as ready for review November 23, 2026 19:41
@kanat
kanat merged commit e1be8e3 into main Nov 23, 2026
15 checks passed
@kanat
kanat deleted the kanat/ai-3614-approved-tool-line branch November 23, 2026 19:55
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