fix(models): route interleaved interactions function-call deltas by step index - #6834
Open
chelsealong wants to merge 1 commit into
Open
fix(models): route interleaved interactions function-call deltas by step index#6834chelsealong wants to merge 1 commit into
chelsealong wants to merge 1 commit into
Conversation
…tep index The Interactions streaming converter attached arguments_delta and step.stop events to state.parts[-1] instead of the function-call step identified by the event's index. When multiple function-call steps are interleaved, deltas for an earlier step were appended to the most recently started call, concatenating their raw JSON and producing invalid arguments (or swapped/merged names) in the final response. Track function-call parts by step index in _StreamState and route arguments_delta and step.stop to the matching step, retaining the existing last-part fallback for events without an index. Fixes google#6832
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.
Summary
Fixes #6832.
The Interactions streaming converter attached
arguments_deltaandstep.stopevents to
state.parts[-1](the most recently started part) instead of thefunction-call step identified by the event's
index. When multiplefunction-call steps are interleaved, argument deltas for an earlier step were
appended to the last-started call, concatenating their raw JSON strings. At
step.stopthis produces invalid JSON (e.g.{"a": 1}{"b": 2}→JSON_PARSE_ERROR), and the earlier call is finalized with no arguments —effectively swapping/merging function names and arguments in the final
response.
Fix
fc_parts_by_indexmapping to_StreamState, populated atStepStartfrom the step'sindex.arguments_deltaandstep.stopto the matching function-call partvia a small
_resolve_streaming_function_call_parthelper.events that carry no
index, so single-call streaming is unchanged.Testing Plan
test_interleaved_function_call_streaming_routes_by_index, whichstarts two calls (
get_weatherat index 0,get_timeat index 1), interleavestheir argument deltas, then stops both, asserting each call finalizes with its
own arguments.
makes the new test fail with
get_weather.args == Noneand the log shows thecorruption directly —
arg_str: {"city": "Paris"}{"zone": "UTC"}(both deltasconcatenated onto the last call).
pytest tests/unittests/models/test_interactions_utils.py→ 143 passed;including the related processor tests → 158 passed.
pyink --checkandisort --check-onlyboth clean on the two changedfiles.
AI assistance disclosure
This change was prepared with AI assistance (Claude). A human reviewed the
diff, the reproduction, and the test evidence above before submission.