fix(core): replace parts[0] in telemetry and tools to support paralle… - #6604
Open
Harshitmishra001 wants to merge 1 commit into
Open
fix(core): replace parts[0] in telemetry and tools to support paralle…#6604Harshitmishra001 wants to merge 1 commit into
Harshitmishra001 wants to merge 1 commit into
Conversation
…l execution This systemic fix replaces hardcoded parts[0] assumptions with correct name-based matching in telemetry tracing, artifact loading, MCP resource loading, and CLI tooling. This resolves issues like google#5967 where parallel tools caused infinite loops or dropped telemetry.
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.
This systemic fix replaces hardcoded
parts[0]assumptions with correct name-based matching in telemetry tracing, artifact loading, MCP resource loading, and CLI tooling. This resolves issues like #5967 where parallel tools caused infinite loops or dropped telemetry.Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
If applicable, please follow the issue templates to provide as much detail as
possible.
Problem:
Across multiple subsystems (
tracing.py,load_artifacts_tool.py,load_mcp_resource_tool.py,cli_record.py), the framework assumed that afunction_responsealways resides atevent.content.parts[0]. In parallel tool execution, multiple tools execute and return responses in the samecontentblock, meaning indices are dynamic. This hardcoded assumption caused the framework to ignore tool responses entirely if they were located atparts[1]or higher, leading to infinite loops in tool calling (e.g., #5967) and dropped telemetry.Solution:
Systematically refactored these subsystems to replace
parts[0]lookups with robust loops that search the entireevent.content.partsarray for thefunction_responsematching the currenttool.name.Testing Plan
Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.
Unit Tests:
Please include a summary of passed
pytestresults.We updated
test_spans.py(which was previously relying on the brokenparts[0]assumption in its test fixtures) to map names correctly.All >10,000 unit tests across the framework pass locally with this refactor.
Manual End-to-End (E2E) Tests:
Please provide instructions on how to manually test your changes, including any
necessary setup or configuration. Please provide logs or screenshots to help
reviewers better understand the fix.
Created a custom test script to manually construct
types.Contentevents simulating multiple parallel tool outputs (e.g.,parts=[Part(function_response=A), Part(function_response=B)]). Prior to the fix, passing this event intoload_artifacts_toolcaused the tool to drop the response forB. Post-fix, the loop correctly matchesBby name and properly logs the tool context.Checklist
Additional context
This PR is a companion to PR #6595 (which fixed this exact issue for the Live flow signals). This PR addresses the remaining systemic occurrences in telemetry and native tools.