Repository navigation
refactor(coderd/x/chatd): replace executeTools and executeSingleTool with toolBatch - #30938
Conversation
|
@codex review
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review
|
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…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.
…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.
3af1d4c to
c207b3f
Compare
Replaces the 20-parameter
executeToolsand the 15-parameterexecuteSingleToolinchatloopwith methods on an unexportedtoolBatch.newToolBatchbuilds it once fromExecuteLocalToolsOptions,runreplacesexecuteTools, andrunOnereplacesexecuteSingleTool. The 12 internal test calls set only the options they use instead of up to 20 positional arguments.It also deletes two copies:
executeToolsfiltered out provider-executed calls thatExecuteLocalToolshad already removed. Only theExecuteLocalToolsfilter remains.runOnemetric defer repeated the body ofrecordToolResultMetrics. It now calls that function.Why it is safe
newToolBatchbuilds the tool, runner, and metadata maps with the linesexecuteToolsused, and the byte budget asExecuteLocalToolsdid.rundrops the empty-batch returns:ExecuteLocalToolsreturns before it when no local call is left.recordToolResultMetricslabels byresult.ToolName, whichrunOnesets totc.ToolNameand never changes. It skips a nilMetrics. Production never passes one, becauseExecuteLocalToolssetsNopMetrics()first; only the direct test calls, which omitMetrics, use that path.ProviderExecutedfilter failsTestExecuteLocalTools_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, inchatd_test.go, which this PR updates.Review focus
The metric defer stays a closure so that it reads
resultwhenrunOnereturns.Validation
go test -race -count=1 ./coderd/x/chatd/chatloop/passes on test(coderd/x/chatd/chatloop): cover provider tool runners in ExecuteLocalTools #30937 and here, including the 16 tests that reach this code:TestExecuteTools*(5),TestExecuteSingleTool_*(5),TestExecuteLocalTools*(6).TestActiveServer_ToolErrorRecordsMetric,TestActiveServer_ToolExecutionAndPolicy, andTestProcessChatPanicRecoveryin./coderd/x/chatd/pass on test(coderd/x/chatd/chatloop): cover provider tool runners in ExecuteLocalTools #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
executeToolsand the 15-parameterexecuteSingleToolinchatloopwith methods on onetoolBatchtype, and resolves tool name aliases in one place. Production behavior does not change.ExecuteLocalToolsexecuteToolsandexecuteSingleToolwithtoolBatchtoolBatchmethod