Repository navigation
fix(agentanalytics): suppress duplicate TOOL_COMPLETED and handle ReflectAndRetryToolPlugin errors - #1776
Open
haiyuan-eng-google wants to merge 1 commit into
Conversation
…lectAndRetryToolPlugin errors - Track recorded tool errors per (invocation, branch, toolOperationId) in onToolErrorCallback (cleared in beforeToolCallback and marked right before logEvent) so afterToolCallback skips emitting a duplicate TOOL_COMPLETED row when another plugin or callback recovers a failure. - Isolate id-less concurrent tool calls via weak-key identity tracking on ToolContext while preserving non-empty functionCallId matching across fresh wrapper contexts. - When ReflectAndRetryToolPlugin runs ahead of BigQueryAgentAnalyticsPlugin and short-circuits onToolErrorCallback (or converts a result error), detect ERROR_HANDLED_BY_REFLECT_AND_RETRY_PLUGIN in afterToolCallback and emit TOOL_ERROR (status=ERROR) instead of TOOL_COMPLETED.
haiyuan-eng-google
marked this pull request as ready for review
November 17, 2026 20:39
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Description of the change:
Problem:
When a tool failure is intercepted and recovered into a replacement result
MapbyOnToolErrorCallback, a downstream plugin, orReflectAndRetryToolPlugin,BigQueryAgentAnalyticsPluginpreviously either:TOOL_ERROR(inonToolErrorCallback) and a duplicateTOOL_COMPLETED(status = "OK", inafterToolCallback) for the same tool span whenBigQueryAgentAnalyticsPluginran before the recovering callback, oronToolErrorCallbackat all whenReflectAndRetryToolPluginwas registered ahead ofBigQueryAgentAnalyticsPlugin(short-circuitingPluginManager.onToolErrorCallback) and logged theERROR_HANDLED_BY_REFLECT_AND_RETRY_PLUGINguidance map asTOOL_COMPLETED(status = "OK") instead ofTOOL_ERROR(status = "ERROR").Solution:
ToolCallKey(invocationId, branch, operationId)in a boundedtoolErrorRecordedcache (maximumSize(10_000),expireAfterWrite(Duration.ofMinutes(10))), invalidating stale entries inbeforeToolCallback, marking immediately beforelogEvent("TOOL_ERROR", ...)inlogToolErrorEvent, and atomically consuming viatoolErrorRecorded.asMap().remove(...)inafterToolCallbackto suppress duplicateTOOL_COMPLETEDrows while isolating siblingParallelAgentbranches, concurrent empty-functionCallIdcalls (syntheticToolCallIds), and wrapperToolContextallocations."ERROR_HANDLED_BY_REFLECT_AND_RETRY_PLUGIN".equals(result.get("response_type"))inafterToolCallbackafter popping the"tool"span and emitTOOL_ERROR(status = "ERROR", extractingerror_details->error_type-> default fallback withmaxContentLengthtruncation andis_truncatedpropagation) regardless of plugin registration order.Testing Plan
Unit Tests:
Ran the full
agentanalyticstest suite (235tests across10test classes,0failures) andfmt:check:./mvnw -B -pl core -am -Dtest='com.google.adk.plugins.agentanalytics.*Test' test(Tests run: 235, Failures: 0, Errors: 0, Skipped: 0, includingafterToolCallback_afterRecoveredToolError_doesNotEmitDuplicateToolCompleted,afterToolCallback_concurrentIdLessTools_recoveredErrorDoesNotSuppressSibling,afterToolCallback_parallelBranchesAndWrapperContexts_isolatesErrorMarker, andafterToolCallback_reflectAndRetryPluginFirst_emitsToolErrorWithoutToolCompleted)../mvnw -B fmt:check -pl core(Processed 485 files (0 non-complying)).Checklist