Explore sub-agents enforced their tool limit in one place.
`buildTurnEnvironment` set the turn's active tool list from
`allowedExploreToolNames`, but `write_file`, `edit_files`,
`attach_file`, `process_list`, and `process_signal` stayed registered.
chatloop reads an empty active list as every registered tool
(`isToolActive`), and that check decides both which tools the model is
offered and which calls run. So a change that dropped or emptied
`ActiveTools` before the model call would give those tools to every
Explore sub-agent. #30868 lists that change as the one mutant only its
removed end-to-end tests caught. Plan mode does not have the gap,
because `filterToolsForTurn` also removes blocked tools from the
registered set.
This PR turns the Explore allowlist into one predicate,
`exploreToolAllowed`. Explore children now drop the tools it blocks
right after the plan-mode filter, and `allowedExploreToolNames` still
builds the active list from the same predicate. The `false` entries in
the old map were no-ops, so the predicate lists only the five allowed
built-ins. An Explore sub-agent is offered and can call the same tools
as before. Root Explore chats and plan mode are unchanged; root Explore
chats still rely on the active list alone.
Tools that join after the filter keep their current behavior:
`appendDynamicTools` returns early for Explore chats, `find_tools` from
the deferred MCP search stays active and defers only MCP tools that
already pass the allowlist, provider tools are a separate list that is
already cut to `web_search` for Explore children, and computer use
exists only in computer-use chats.
Refs #30867
## Testing
- `TestBuildTurnEnvironmentToolPolicy` now requires every tool
registered for an Explore child to be offered. Without the production
change, `ExploreChild` and `ExploreChildAfterMCPReplacement` fail with
`Should be empty, but was [write_file edit_files attach_file
process_list process_signal]`. With it, all rows pass.
- A throwaway runtime probe (not committed) ran an Explore child whose
fake model calls `write_file` and then `edit_files`, with `ActiveTools`
set to nil for Explore chats at the chatloop handoff:
| `ActiveTools` set to nil | Before this PR | With this PR |
|---|---|---|
| At the model call | The model is offered `write_file`, `edit_files`,
`attach_file`, `process_list`, and `process_signal` | The model is
offered only `read_file`, `execute`, and `process_output` |
| At the model call and at tool execution | Both calls run on the
workspace agent and return `{"ok": true}` | Both calls fail with `Tool
not found`, and the agent gets no write or edit |
- `go test ./coderd/x/chatd/...`, `go test ./coderd/ -run
'(?i)chat|explore|plan|mcp'`, `go test ./enterprise/coderd/ -run
'(?i)chat|explore|plan|mcp'`, and golangci-lint on `coderd/x/chatd`
pass.
> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.