Repository navigation
[AI-3614] Log an approved tool call under its own name - #2250
Conversation
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
left a comment
There was a problem hiding this comment.
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, androuter_agent_tool_call_secondsgets no new sample or label (it matches the chat monitors'!outcome:refusedscope); - the approved run's
duration_mscovers onlyRun; - 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 { |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
[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).
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
left a comment
There was a problem hiding this comment.
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.
confirmnow returnsran(approval.go:231, true only afterToolRunner.Runreturned), andtelephony.go:759cuts the line down only when it did. Bad arguments, a native refusal and a caller's own tool namedconfirm_tool_callkeeperror_codeanderror. 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,
confirmednever/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 beforeconfirmis reached). Declined, lapsed and unknown returning true change only whether the line carrieserror_code=""; Nit, no action. go test ./internal/agent/ -count=1on the merge with current main: ok. New and ApprovedCall tests:-race -count=10and-cpu 1 -count=20ok.go vetandgofmtclean.- 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,
goandintegrationskipped (#2130); the other checks pass.
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 saystool=confirm_tool_call, and the original call's line saysoutcome=refused. An operator who reads the logs after "send the email" seesconfirm_tool_callsucceed andsend_emailrefused, and cannot see that the email tool ran (AI-3614, found in the #2217 round-1 review).How it works
The approved run gets its own report (
WithToolReport) so its line carries its connector and failure. Theconfirm_tool_callline no longer carries them (loggedAnswer: app, agent,successonly), 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 namedconfirm_tool_call) keeps itserror_codeanderror, because no run line carries them. In writing nothing asks (approvalQuestionreturns "" for a text agent; the app approves), so text calls already log under their own name.outcomeand therouter_agent_tool_call_secondslabel stay as they are: chatinfra/shards/us-east{1,4}-acceleration/datadog/launch_tool_calls.tfexcludesoutcome:refusedfrom 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.tool=send_email tool_call=call-1 outcome=refusedapproval=askedtool=send_email tool_call=call-1 connector=gmail outcome=ok success=true error_code="" duration_ms=812 approval=allowed confirmation=call-2tool=confirm_tool_call tool_call=call-2 connector=gmail outcome=ok error_code="" duration_ms=815tool=confirm_tool_call tool_call=call-2 outcome=ok success=true duration_ms=815(noconnector,error_code,error)(Ids and numbers are made up.)
ClickHouse: the new line has the same
msgas before, sologs.agent_session_eventsalready types itstool,outcome,connector,success,error_codeandduration_ms. The two new keysapprovalandconfirmationstay inbodyuntil a chat ticket adds columns for them.Changes
confirmlogs 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).confirm_tool_callline drops the run'sconnector,error_codeanderrorwhenconfirmran the approved call (it returnsran); the run's own line has them. A confirmation that ran nothing keeps its own error.approval=asked.logToolBackwrites the line for both, so the field set is defined once.Validation
go test ./internal/agent/ -count=1on head bccd0fd (merged with main 644103a): ok.go vet,gofmt -l: clean.askedLineKeys,connectorLineKeys). The new tests fail on base (noapprovalkey, 2 lines instead of 3); the control (TestAConnectorCallThatAnsweredNamesItsConnector) passes there.TestAnApprovedCallIsLoggedUnderItsOwnNameTestAnApprovedCallThatFailedIsLoggedAsFailedTestAnApprovedCallTheCallerTalkedOverIsLoggedAsStillRunningTestAnApprovedCallCancelledByTheCallerIsLoggedAsCancelledTestAConfirmationThatFailedOnItsOwnKeepsItsError,TestANativeConfirmationTheRouterRefusedKeepsItsError,TestACallersToolNamedConfirmToolCallKeepsItsErrorTestADeclinedCallLogsNoRunTestAConnectorCallThatAnsweredNamesItsConnector(control)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