Skip to content

refactor(coderd/x/chatd): replace executeTools and executeSingleTool with toolBatch - #30938

Draft
ibetitsmike wants to merge 1 commit into
mike/chatloop-provider-runner-testfrom
mike/chatloop-tool-batch
Draft

ibetitsmike wants to merge 1 commit into
mike/chatloop-provider-runner-testfrom
mike/chatloop-tool-batch

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

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 (test(coderd/x/chatd/chatloop): cover provider tool runners in ExecuteLocalTools #30937). The other four mutants from test(coderd/x/chatd/chatloop): cover provider tool runners in ExecuteLocalTools #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

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.

…with toolBatch

ExecuteLocalTools unpacked its options into a 20-parameter executeTools,
which forwarded 15 of them to executeSingleTool. Both are now methods on
an unexported toolBatch built once from ExecuteLocalToolsOptions, and the
12 internal test call sites set only the options they use.

executeTools also re-filtered provider-executed calls that
ExecuteLocalTools had already removed; that duplicate filter is gone.
The runOne metric defer calls recordToolResultMetrics instead of
repeating its body.
@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-18T15:37:24.593096Z 4bd3d78 Manual request
ℹ️ 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. More of your lovely PRs please.

Reviewed commit: 4bd3d78942

ℹ️ 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".

This branch has not been deployed

No deployments
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.

1 participant