Skip to content

fix: concatenate list values in deep_merge_dicts during parallel tool call merge#5191

Open
enjoykumawat wants to merge 4 commits intogoogle:mainfrom
enjoykumawat:fix/parallel-state-delta-list-merge
Open

fix: concatenate list values in deep_merge_dicts during parallel tool call merge#5191
enjoykumawat wants to merge 4 commits intogoogle:mainfrom
enjoykumawat:fix/parallel-state-delta-list-merge

Conversation

@enjoykumawat
Copy link
Copy Markdown

Summary

  • Bug: When multiple tool calls run in parallel and each writes to the same state_delta key containing a list value, deep_merge_dicts silently drops all but the last value because lists hit the else branch and get overwritten.
  • Fix: Add a list-type check in deep_merge_dicts so list values are concatenated (d1[key] + value) instead of overwritten, preserving all entries from parallel function responses.
  • Tests: Added 5 unit tests covering list concatenation, scalar overwrite, nested dict merge, mixed-type handling, and an integration test for merge_parallel_function_response_events with state_delta lists.

Reproduction

# Tool A's delta: {"state_delta": {"items": ["a"]}}
# Tool B's delta: {"state_delta": {"items": ["b"]}}
# Before fix: {"state_delta": {"items": ["b"]}} — item "a" is lost
# After fix:  {"state_delta": {"items": ["a", "b"]}} — both preserved

Test plan

  • All 5 new unit tests pass (test_deep_merge_dicts_* and test_merge_parallel_function_response_events_merges_state_delta_lists)
  • All 32 existing tests in test_functions_simple.py pass (0 regressions)
  • Manual: create parallel tool calls that accumulate list state and verify no data loss

Fixes #5190

enjoykumawat and others added 2 commits April 7, 2026 18:08
… call merge

When multiple tool calls run in parallel and each writes to the same
state_delta key containing a list value, deep_merge_dicts silently drops
all but the last value because lists hit the else branch and get
overwritten.

Add a list-type check so that list values are concatenated instead of
overwritten, preserving all entries from parallel function responses.

Fixes google#5190
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the tests to test_functions_parallel.py

@wuliang229 wuliang229 self-assigned this Apr 7, 2026
enjoykumawat and others added 2 commits April 7, 2026 23:41
…nctions_parallel

Move tests for deep_merge_dicts and merge_parallel_function_response_events
with list state_delta merging from test_functions_simple.py to
test_functions_parallel.py per reviewer feedback.
@enjoykumawat
Copy link
Copy Markdown
Author

Done! Moved all the deep_merge_dicts and state_delta list tests to test_functions_parallel.py in commit 4b3db55. Also merged latest main to pick up any upstream changes. CI is re-running now.

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.

Parallel tool calls: state_delta list values silently overwritten during merge

2 participants