Files
coder/coderd
Michael Suchacz 78fa9a8613 refactor(coderd/x/chatd)!: retire the close_agent tool alias (#31005)
This PR breaks compatibility with chat histories that contain
`close_agent` tool calls, which chats from v2.34 and earlier have.
#26673 (v2.35) renamed `close_agent` to `interrupt_agent` and kept a
hidden alias, so a model that copied the old name from such a history
still interrupted the child. This PR deletes the alias:
`subagentToolNameAliases`, `ExecuteLocalToolsOptions.ToolNameAliases`
with `(*toolBatch).resolve` and its five call sites in `chatloop`, the
alias step in builtin input validation, and the `close_agent` entries in
the unbilled tool set, the plan policy, and the chatprompt lifecycle
list. Coder Agents is experimental (`coderd/x`), and our rule for
experimental persisted data is to drop the legacy shape outright and
delete the code that existed only to support it, instead of carrying it
forward.

What happens to an old chat:

- Replay does not change, because the replay path does not look up tool
names: the model still sees the historical `close_agent` call and its
stored result, and the UI renders them as before. The write path reads a
tool name only to parse `execute` commands and to keep structured error
results from subagent lifecycle tools. Dropping `close_agent` from that
lifecycle list changes nothing, because its calls are now rejected with
a plain-text error.
- If the model calls `close_agent` again, nothing runs and the child
keeps running. The tool result is the error `Tool not active in this
turn: close_agent`, and the model can retry with `interrupt_agent`.

**Why it is safe**

- Deleted alias-only tests:
`TestExecuteSingleTool_ResolvesToolNameAlias`, the
`AliasNamesClassifyAsCalled` billing row, the alias subtest of
`TestPartitionAmbiguousToolCallsGatesOnBuiltins`, the alias loop in
`TestUnbilledSubagentToolNamesMatchCatalog`, and the aliased calls that
#30939 added to `TestExecuteToolsSerialToolCallOrder` and
`TestExecuteLocalTools_ProviderToolRunner`; both tests are back to their
#30938 form.
- `TestExecuteSingleTool_UnknownAliasFallsThrough` is now
`TestExecuteSingleTool_RejectsUnknownTool` and asserts the exact error
above. The observer tests call the tool by its real name.
- Mutants of the active tool check, step observer notification, serial
dispatch, the unbilled set, the plan policy and builtin input validation
each fail a remaining test. Only the deleted alias test caught an empty
name passed to the tool handler; no chatd tool reads that name (MCP
tools use their original name).
- `git grep` finds no use of the removed identifiers and no backend code
that resolves `close_agent`. The rejection test still uses that name as
its input. The frontend keeps its `close_agent` display mapping, which
old histories still use.

**Review focus**

- A rejected `close_agent` call is now billed like any rejected tool
call; the rejection is immediate.
- `ARCHITECTURE.md`, "Generation goroutine": this PR deletes the
sub-bullet that called `close_agent` a deprecated alias of
`interrupt_agent`.
- The `resolved_tool_name` debug log field is gone. It differed from
`tool_name` only for aliased calls, and the alias is gone.

**Validation**

- `go test -count=1 ./coderd/x/chatd/ ./coderd/x/chatd/chatloop/
./coderd/x/chatd/chatprompt/`: ok
- `go vet` and `golangci-lint run --fix=false ./coderd/x/chatd/...`:
clean
- `paralleltestctx -custom-funcs="testutil.Context,chatdTestContext"
./coderd/x/chatd/...`: clean
- pre-commit hook: passed

**Stack**

This stack retires chatd compatibility paths for chat data that older
Coder versions stored.

This PR replaces #31003 and carries its change, adapted to the
`toolBatch` code that #30938 and #30939 merged. Mike chose to keep the
fallbacks that #31001 and #31002 removed, so those two layers and #31003
left the stack.

1. #30996 stamp chat message fixtures with the current content version
2. #30997 drop tests of the legacy content codec
3. #30998 retire the V0 chat message content decoder
4. #31000 inline the model config provider identity
5. #31005 retire the `close_agent` tool alias (this PR)

> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.
2026-10-30 02:00:59 +00:00
..