Files
coder/coderd/x/chatd/chatloop
Michael Suchacz a86012f82b refactor(coderd/x/chatd/chatloop): resolve tool name aliases in one toolBatch method (#30939)
Adds `(*toolBatch).resolve` for the `ToolNameAliases` lookup that
`runOne`, `notifyStepToolCallObservers`,
`notifyStepToolResultObservers`, and `isSerialToolCall` each repeated.
The last three become `toolBatch` methods instead of taking the tool map
and the alias map. Where they looked up a tool and then type-asserted
it, they now assert on the map value: a missing name gives a nil
interface, so the assertion fails as the missing-key check did.

It also fixes a latent bug: `runOne` looked up result provider metadata
by the name the model sent, while its other lookups use the resolved
name, so a runner called by an alias lost its metadata. This cannot
happen in production today: the only alias is `close_agent` to
`interrupt_agent` (`subagent.go:45`), and only `computer_use.go:112`
sets `ResultProviderMetadata`.

## Why it is safe

Each mutant below puts the raw name back at one call site, and each
fails a test:

| Call site | Failing test |
|---|---|
| `runOne` tool lookup | `TestExecuteSingleTool_ResolvesToolNameAlias`
and 5 more |
| `runOne` metadata lookup | `TestExecuteLocalTools_ProviderToolRunner`
|
| `notifyStepToolCallObservers` |
`TestExecuteToolsNotifiesStepToolCallObservers` |
| `notifyStepToolResultObservers` (either loop) |
`TestExecuteToolsNotifiesStepToolResultObservers` |
| `isSerialToolCall` | `TestExecuteToolsSerialToolCallOrder` |

No test called a serial tool or a provider runner by an alias, so this
PR adds one aliased call to `TestExecuteToolsSerialToolCallOrder` and
one to `TestExecuteLocalTools_ProviderToolRunner`. With the
`chatloop.go` of #30938, the first test still passes, and the second
fails because the aliased result has no metadata.

## Validation

- `go test -race -count=1 ./coderd/x/chatd/chatloop/` passes on #30938
and here.
- `go test -count=1 -p 4 -parallel 4 ./coderd/x/chatd/...` passes here
(20 packages).
- `golangci-lint run ./coderd/x/chatd/chatloop/...` reports 0 issues,
and the pre-commit hook passed.

## Stack

This stack replaces the 20-parameter `executeTools` and the 15-parameter
`executeSingleTool` in `chatloop` with methods on one `toolBatch` type,
and resolves tool name aliases in one place. Production behavior does
not change.

1. #30937 Cover provider tool runners in `ExecuteLocalTools`
2. #30938 Replace `executeTools` and `executeSingleTool` with
`toolBatch`
3. #30939 Resolve tool name aliases in one `toolBatch` method

> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.
2026-10-20 09:39:54 +00:00
..