Skip to content

test: pin the panic text that a failed tool keeps from the model - #2487

Merged
baptmont merged 3 commits into
google:mainfrom
sandeepvijayarao09:fix-2172-panic-text-tests
Nov 25, 2026
Merged

baptmont merged 3 commits into
google:mainfrom
sandeepvijayarao09:fix-2172-panic-text-tests

Conversation

@sandeepvijayarao09

Copy link
Copy Markdown
Contributor

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:

  1. ModelErrorText holds "however deeply it is wrapped", and every test
    wrapped once.
  2. Plugins are handed the full panic text; no test asserted what the plugin's
    OnToolError or AfterTool callback received.
  3. 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.
  4. A comment in plugin_test.go justified its "wrapped panic" case with a
    route that cannot happen.

Solution:

Tests only. No production file changes, so nothing behaves differently.

  • Depth. TestModelErrorText (internal/toolinternal) runs the contract
    over 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.
  • The real two-level path.
    TestAgentTool_PanicInNestedWorkflowToolStaysOutOfTheResponse
    (tool/agenttool) is the runner case from the issue: a functiontool that
    panics behind a workflow ToolNode, called through agenttool from an LLM
    agent. ToolNode wraps the error at workflow/tool_node.go:120 and
    agenttool wraps it again at tool/agenttool/agent_tool.go:209, so the flow
    sees 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.
  • Plugin receipt. panickingPluginManager in
    internal/llminternal/base_flow_test.go now records the error each of its
    tool callbacks was handed, and TestCallToolPanics gains wantPluginErrs:
    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 OnToolError is the step that
    panics, and no error at all when the call has not failed by the time the
    plugin's AfterTool runs. The long panic prefixes became named constants so
    each case states the same text once instead of twice.
  • Guidance shape. TestRetryAndReflect_GuidanceCarriesErrorTypeAndText
    (plugin/retryandreflect) asserts the rendered guidance carries
    <type>: <details> on all four combinations of reflection vs retry-limit
    response and ordinary error vs recovered panic.
  • The comment. The "wrapped panic" case said an earlier OnToolError
    callback may wrap the error before this plugin sees it. It cannot:
    PluginManager.RunOnToolErrorCallback
    (internal/plugininternal/plugin_manager.go:241-255) 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 does exist —
    a workflow ToolNode and then agenttool — which is the one the new
    agenttool test walks.

Behavior change

Nothing. No non-test file is touched.

Testing Plan

Unit Tests:

  • All unit tests pass locally.

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 main on 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.

Mutation Tests that fail
1. ModelErrorText checks err and one errors.Unwrap instead of errors.AsType TestModelErrorText/{panic_wrapped_twice,panic_wrapped_five_deep,panic_joined_with_another_error} and TestAgentTool_PanicInNestedWorkflowToolStaysOutOfTheResponse
2. pluginManager.RunOnToolErrorCallback handed the generic error TestCallToolPanics/{before_tool_callback,plugin_before_tool_callback,tool_not_built_with_functiontool,tool_not_built_with_functiontool_without_content_capture}, plus the plugin/agentanalytics tests noted below
3. pluginManager.RunAfterToolCallback handed the generic error those four, plus TestCallToolPanics/{on_tool_error_callback,plugin_on_tool_error_callback} and the same plugin/agentanalytics tests
4. retryandreflect builds ErrorDetails without the type prefix all four cases of TestRetryAndReflect_GuidanceCarriesErrorTypeAndText
5. exceeded.md renders an empty error block the two retry_limit_exceeded cases of TestRetryAndReflect_GuidanceCarriesErrorTypeAndText

TestModelErrorText/panic_wrapped_once stays green under mutation 1, as it
should: 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/agentanalytics tests
(TestPanickingErrorWithIsErrorRecovery,
TestPlugin_FinishTask_OverlappingErrorDoesNotStealCompletion, and two more).
That module is not reached by go test ./... from the repo root, which is
likely why the issue reports the suite as green. Those tests do not pin the
panic text either: replacing the error with a fresh errors.New also destroys
sentinel identity, so errors.Is(err, tool.ErrConfirmationRequired) stops
holding 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.Content has no String method,
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

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end. — not applicable, tests only.
  • Any dependent changes have been merged and published in downstream modules.

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

sandeepvijayarao09 and others added 2 commits November 23, 2026 23:46
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
baptmont merged commit ba236dc into google:main Nov 25, 2026
15 checks passed
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.
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.

functiontool: tests do not pin wrapped panics, plugin receipt of the panic text, or the retryandreflect error shape

2 participants