Repository navigation
test: pin the panic text that a failed tool keeps from the model - #2487
Merged
baptmont merged 3 commits intoNov 25, 2026
Merged
Conversation
google#2120 keeps a recovered tool panic out of the model's function response. Four of the properties it states had no test that fails when they break, so a regression in any of them merged green. No non-test file changes. ModelErrorText promises the generic message however deeply the panic is wrapped, and every test wrapped once. TestModelErrorText covers depths 1, 2 and 5, a panic joined with another error, and an ordinary error that has to keep its own text. The real two-level path gets a runner test of its own: a panicking functiontool behind a workflow ToolNode, called through agenttool, so ToolNode wraps the error and agenttool wraps it again before the flow sees it. Plugins are handed the error itself, panic value and stack included, because that is what a deployment logs; only the model's function response gets the generic message. The test plugin manager now records the error each of its tool callbacks was handed, and TestCallToolPanics states it per case: the panic error, the ordinary error the tool returned when the agent's OnToolError is the step that panics, or no error at all when the call has not failed by the time the plugin's AfterTool runs. The panic texts became named constants, since each is now named two or three times in one case. retryandreflect builds "<type>: <details>" for the guidance the model reads. Dropping the type prefix, or emptying the error block of the retry-limit template, passed every test; it now fails TestRetryAndReflect_GuidanceCarriesErrorTypeAndText. The "wrapped panic" case justified itself with a route that cannot happen: an earlier OnToolError callback wrapping the error before this plugin sees it. PluginManager.RunOnToolErrorCallback returns as soon as a plugin answers or fails, and the agent's own callbacks run only after the plugins return nothing. The comment now names the route that exists. Fixes google#2172
baptmont
approved these changes
Nov 24, 2026
PratikDhanave
added a commit
to PratikDhanave/adk-go
that referenced
this pull request
Nov 27, 2026
The generic ToolNode error dropped the *toolinternal.PanicError from the chain, so when a workflow runs as an agent tool, ModelErrorText no longer saw a panic and the parent's function response carried the ToolNode text instead of the generic message. TestAgentTool_PanicInNestedWorkflowTool- StaysOutOfTheResponse (google#2487) pins that. Return a toolPanicError whose text stays generic but which unwraps to the PanicError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
2. Describe the change:
Problem:
#2120 keeps a recovered tool panic out of the model's function response. The
code does that correctly, but four of the properties it states have no test
that fails when they break, so a regression in any of them merges green.
#2172 names them:
ModelErrorTextholds "however deeply it is wrapped", and every testwrapped once.
OnToolErrororAfterToolcallback received.retryandreflectbuilds<type>: <details>for the guidance the modelreads; dropping the type prefix, or emptying the error block of the
retry-limit template, passed every test.
plugin_test.gojustified its "wrapped panic" case with aroute that cannot happen.
Solution:
Tests only. No production file changes, so nothing behaves differently.
TestModelErrorText(internal/toolinternal) runs the contractover an unwrapped panic, wrap depths 1, 2 and 5, a panic joined with another
error, and an ordinary error that must keep its own text.
TestAgentTool_PanicInNestedWorkflowToolStaysOutOfTheResponse(
tool/agenttool) is the runner case from the issue: afunctiontoolthatpanics behind a workflow
ToolNode, called throughagenttoolfrom an LLMagent.
ToolNodewraps the error atworkflow/tool_node.go:120andagenttoolwraps it again attool/agenttool/agent_tool.go:209, so the flowsees it two deep. The test asserts the root's function response is the
generic message and that no event of the run carries the panic value, the
stack or the error type. The unit test pins the contract; this one proves the
product still has a caller that needs it.
panickingPluginManagerininternal/llminternal/base_flow_test.gonow records the error each of itstool callbacks was handed, and
TestCallToolPanicsgainswantPluginErrs:per case, how the error handed to each plugin callback that ran starts. It
covers the three outcomes that differ — the panic error itself, the ordinary
error the tool returned when the agent's
OnToolErroris the step thatpanics, and no error at all when the call has not failed by the time the
plugin's
AfterToolruns. The long panic prefixes became named constants soeach case states the same text once instead of twice.
TestRetryAndReflect_GuidanceCarriesErrorTypeAndText(
plugin/retryandreflect) asserts the rendered guidance carries<type>: <details>on all four combinations of reflection vs retry-limitresponse and ordinary error vs recovered panic.
OnToolErrorcallback may wrap the error before this plugin sees it. It cannot:
PluginManager.RunOnToolErrorCallback(
internal/plugininternal/plugin_manager.go:241-255) returns as soon as aplugin answers or fails, and the agent's own callbacks run only after the
plugins return nothing. The comment now names the route that does exist —
a workflow
ToolNodeand thenagenttool— which is the one the newagenttooltest walks.Behavior change
Nothing. No non-test file is touched.
Testing Plan
Unit Tests:
With your source change reverted and your tests kept, which test fails?
This PR changes no source, so the revert check is the mutation each item of
#2172 names. Each was applied to
mainon its own, the whole workspace run(
go test -mod=readonly -count=1 work), and the mutation put back afterwards.Baseline, with no mutation, is green.
ModelErrorTextcheckserrand oneerrors.Unwrapinstead oferrors.AsTypeTestModelErrorText/{panic_wrapped_twice,panic_wrapped_five_deep,panic_joined_with_another_error}andTestAgentTool_PanicInNestedWorkflowToolStaysOutOfTheResponsepluginManager.RunOnToolErrorCallbackhanded the generic errorTestCallToolPanics/{before_tool_callback,plugin_before_tool_callback,tool_not_built_with_functiontool,tool_not_built_with_functiontool_without_content_capture}, plus theplugin/agentanalyticstests noted belowpluginManager.RunAfterToolCallbackhanded the generic errorTestCallToolPanics/{on_tool_error_callback,plugin_on_tool_error_callback}and the sameplugin/agentanalyticstestsretryandreflectbuildsErrorDetailswithout the type prefixTestRetryAndReflect_GuidanceCarriesErrorTypeAndTextexceeded.mdrenders an empty error blockretry_limit_exceededcases ofTestRetryAndReflect_GuidanceCarriesErrorTypeAndTextTestModelErrorText/panic_wrapped_oncestays green under mutation 1, as itshould: that mutation still recognizes a panic one level down.
One correction to the issue, on item 2. Mutations 2 and 3 are not caught only
by the new assertions: they also fail several
plugin/agentanalyticstests(
TestPanickingErrorWithIsErrorRecovery,TestPlugin_FinishTask_OverlappingErrorDoesNotStealCompletion, and two more).That module is not reached by
go test ./...from the repo root, which islikely why the issue reports the suite as green. Those tests do not pin the
panic text either: replacing the error with a fresh
errors.Newalso destroyssentinel identity, so
errors.Is(err, tool.ErrConfirmationRequired)stopsholding and they fail for that reason. The gap the issue describes is real; it
is one module wider than stated.
Worth saying, because it was the first defect the self-review found: an earlier
draft of the agenttool test scanned events with
fmt.Sprint(ev.LLMResponse.Content).genai.Contenthas noStringmethod,so that prints the parts as addresses and the leak check could never fire. The
test now serializes each event and asserts, before the leak check, that the
scanned text contains the function response, so a scan that reads nothing fails
loudly instead of passing.
Manual End-to-End (E2E) Tests:
None. The change adds no code that runs outside tests.
Checklist
Additional context
adk-python parity: this PR adds no behavior, so there is nothing to diverge.
The property being pinned — a recovered panic becoming a generic message for
the model — is ADK Go's own, decided in #2120.
Fixes #2172
🤖 Generated with Claude Code