Skip to content

fix(agent): refuse a call to a tool the turn did not offer (#4316) - #4322

Merged
mstomar125 merged 1 commit into
mainfrom
issue-4316-offered
Nov 20, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-4316-offered

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #4316 (the turn's scoped surface is not checked at dispatch). Lands with the confirmation card (#4321, merged): a remote tool the gate offers is only callable if THIS turn offered it.

Agent lane. Touches packages/agent (Michael's lane). The user's sign-off for the #4291 remote-tool build stands in for Michael's.

The gap

The executor gates what exists (RemoteToolHost::eligible(): enabled, approved, a runner, a confirmer where needed). A skill's tool_whitelist, the lookup rules and the offered-types hold narrow what the model is SHOWN on a turn. Nothing checked a call against what the turn showed: a model call to an approved remote tool this turn's whitelist scoped out was dispatched (after the confirmation, for a tool that needs one). Built-in tools behaved the same.

The fix

In the agent loop, at the point a model's call goes to the executor: a call whose tool name is not in the turn's offered list (tools, the surface the inference request carried) is refused before the executor, whatever the tool is, with an error result tool_not_offered. The message names the tool the model asked for and carries nothing of its arguments. A warning logs the session, iteration and tool name only.

All 1,066 existing agent-loop tests pass unchanged, so no existing behaviour relied on calling a tool that was not offered.

Tests

A scoped executor that can run visible and hidden_remote but offers only visible:

  • a call to the approved-but-scoped-out tool is refused: the executor ran nothing, the result is an error tool_not_offered, it names the tool, and the arguments (a marker string) appear nowhere in what the model sees;
  • a built-in the turn did not offer (get_node) is refused the same way;
  • an offered tool runs, and is not an error.

Mutants (5): check removed, check inverted, tool name dropped from the message, arguments leaked into the message, result not marked as an error. Each killed by a named test (agent_loop::a_built_in_tools_result_is_unchanged is a pre-existing flake under cargo test that shows up in some runs' failure lists; it passes under nextest).

🤖 Generated with Claude Code

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.

RemoteToolHost::execute does not check the turn's scoped surface

1 participant