Skip to content

refactor(coderd/x/chatd/chatloop): resolve tool name aliases in one toolBatch method - #30939

Merged
ibetitsmike merged 2 commits into
mainfrom
mike/chatloop-tool-batch-aliases
Oct 20, 2026
Merged

ibetitsmike merged 2 commits into
mainfrom
mike/chatloop-tool-batch-aliases

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

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

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. test(coderd/x/chatd/chatloop): cover provider tool runners in ExecuteLocalTools #30937 Cover provider tool runners in ExecuteLocalTools
  2. refactor(coderd/x/chatd): replace executeTools and executeSingleTool with toolBatch #30938 Replace executeTools and executeSingleTool with toolBatch
  3. refactor(coderd/x/chatd/chatloop): resolve tool name aliases in one toolBatch method #30939 Resolve tool name aliases in one toolBatch method

Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.

@ibetitsmike

ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, posted this comment for @ibetitsmike.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T12:20:22.524107Z 00b4af0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 76b4c2b115

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, posted this comment for @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 00b4af02a4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike marked this pull request as ready for review October 19, 2026 12:17
ibetitsmike added a commit that referenced this pull request Oct 20, 2026
…LocalTools (#30937)

Adds `TestExecuteLocalTools_ProviderToolRunner`. No test ran a
`ProviderTool` runner (the local half of a provider-defined tool, such
as OpenAI computer use) through `ExecuteLocalTools`, so nothing checked
runner dispatch, the active-tool exemption for runners, result metadata,
or the skip of provider-executed calls. #30938 rewrites that code, so
this PR pins the behavior first.

The test sends a runner call and a provider-executed `web_search` call.
The runner is in neither `Tools` nor `ActiveTools`. The test checks that
only the runner call gets a result, and that the result has the runner's
output and its `ResultProviderMetadata`.

## Why it can fail

Each mutant is `chatloop.go` with one change, run with `go test
-overlay`. Each one fails the new test, and all other `chatloop` tests
pass with it.

| Mutant | New test fails with |
|---|---|
| Runners are not added to the tool map | `Tool not found: computer` |
| Runners are not exempt from the active-tool check | `Tool not active
in this turn: computer` |
| `ResultProviderMetadata` is not attached | nil metadata |
| Provider tools without a runner are not skipped | nil pointer panic |
| Both `ProviderExecuted` filters are removed | 2 results |

Removing only one of the two `ProviderExecuted` filters, in
`ExecuteLocalTools` or in `executeTools`, fails no test, because the
other filter still runs. #30938 deletes the one in `executeTools`.

`go test ./coderd/x/chatd/` also passes with runners left out of the
tool map and the metadata attachment removed. Its subtest
`TestActiveServer_ToolExecutionAndPolicy/provider_runner_executes_and_preserves_metadata`
replays a stored computer-use call and result; it does not run the
runner.

## Validation

- `go test -race -count=1 ./coderd/x/chatd/chatloop/` passes.
- `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.
@ibetitsmike
ibetitsmike force-pushed the mike/chatloop-tool-batch-aliases branch from 00b4af0 to 48af4ad Compare October 20, 2026 09:03
Base automatically changed from mike/chatloop-tool-batch to main October 20, 2026 09:26
ibetitsmike added a commit that referenced this pull request Oct 20, 2026
…with toolBatch (#30938)

Replaces the 20-parameter `executeTools` and the 15-parameter
`executeSingleTool` in `chatloop` with methods on an unexported
`toolBatch`. `newToolBatch` builds it once from
`ExecuteLocalToolsOptions`, `run` replaces `executeTools`, and `runOne`
replaces `executeSingleTool`. The 12 internal test calls set only the
options they use instead of up to 20 positional arguments.

It also deletes two copies:

- `executeTools` filtered out provider-executed calls that
`ExecuteLocalTools` had already removed. Only the `ExecuteLocalTools`
filter remains.
- The `runOne` metric defer repeated the body of
`recordToolResultMetrics`. It now calls that function.

## Why it is safe

- `newToolBatch` builds the tool, runner, and metadata maps with the
lines `executeTools` used, and the byte budget as `ExecuteLocalTools`
did. `run` drops the empty-batch returns: `ExecuteLocalTools` returns
before it when no local call is left.
- `recordToolResultMetrics` labels by `result.ToolName`, which `runOne`
sets to `tc.ToolName` and never changes. It skips a nil `Metrics`.
Production never passes one, because `ExecuteLocalTools` sets
`NopMetrics()` first; only the direct test calls, which omit `Metrics`,
use that path.
- With the duplicate filter gone, removing the remaining
`ProviderExecuted` filter fails
`TestExecuteLocalTools_ProviderToolRunner` (#30937). The other four
mutants from #30937 still fail it here.
- `git grep 'executeTools\|executeSingleTool'` finds one comment, in
`chatd_test.go`, which this PR updates.

## Review focus

The metric defer stays a closure so that it reads `result` when `runOne`
returns.

## Validation

- `go test -race -count=1 ./coderd/x/chatd/chatloop/` passes on #30937
and here, including the 16 tests that reach this code:
`TestExecuteTools*` (5), `TestExecuteSingleTool_*` (5),
`TestExecuteLocalTools*` (6).
- `TestActiveServer_ToolErrorRecordsMetric`,
`TestActiveServer_ToolExecutionAndPolicy`, and
`TestProcessChatPanicRecovery` in `./coderd/x/chatd/` pass on #30937 and
here.
- `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.
…oolBatch method

runOne, notifyStepToolCallObservers, notifyStepToolResultObservers, and
isSerialToolCall each repeated the ToolNameAliases lookup. They now call
(*toolBatch).resolve, and the observers and isSerialToolCall become
toolBatch methods instead of taking the tool map and alias map.

runOne also looks up result provider metadata by the resolved name, like
its other lookups. No production alias maps to a provider tool with
result metadata, so this changes nothing in production.

TestExecuteToolsSerialToolCallOrder calls one serial tool by an alias,
so dropping the alias lookup from isSerialToolCall now fails a test.
TestExecuteLocalTools_ProviderToolRunner now also calls the runner by an
alias and checks that the result keeps the runner's provider metadata.
This pins the resolved-name metadata lookup in runOne: with the raw name
from the model, a runner called by an alias loses its metadata, and the
test fails on the layer below.
@ibetitsmike
ibetitsmike force-pushed the mike/chatloop-tool-batch-aliases branch from 48af4ad to 4fe60d5 Compare October 20, 2026 09:26
@ibetitsmike
ibetitsmike merged commit a86012f into main Oct 20, 2026
29 checks passed
@ibetitsmike
ibetitsmike deleted the mike/chatloop-tool-batch-aliases branch October 20, 2026 09:39
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants