Repository navigation
fix(a2a): keep streamed artifacts when a Task snapshot arrives mid-stream - #7230
Closed
chelsealong wants to merge 1 commit into
Closed
chelsealong wants to merge 1 commit into
chelsealong wants to merge 1 commit into
Conversation
…ream RemoteA2aAgent's client-side stream normalizer (make_stream_normalizer) replaced its running Task aggregate wholesale whenever a full Task item arrived. A running-Task snapshot carries status and, from many servers and proxies, no artifacts; when one lands after the first append=False chunk of an artifact has been folded in, that artifact is gone from the aggregate, and the next append=True chunk fails inside append_artifact_to_task with "append=True for nonexistent artifact_id" (google#6680, the delegation-path crash). The append/partial flag on the chunks is not the cause: the same sequence crashes with the flags the server actually sends, and the final chunk of a stream carries the accumulated content, so it must keep replacing (append=False) as pinned by test_convert_event_to_a2a_events_final_chunk_replaces. Merge the snapshot instead: artifacts the running task already holds and the snapshot lacks are carried over; an artifact the snapshot does carry wins for that id. Two regression tests: the exact chunk / snapshot / chunk sequence that raised, and the authoritative-snapshot case. Fixes google#6680
8 of 9 tasks
copybara-service Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
A running-Task snapshot mid-stream may carry status without artifacts. Carry over previously folded-in artifacts into the aggregate state so subsequent append chunks can resolve their target artifact, while returning the snapshot as received to the caller. Merge #7230 Fixes #6680 PiperOrigin-RevId: 993339769
Collaborator
|
Thank you @chelsealong for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 71c4fd7. Closing this PR as the changes are now in the main branch. |
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.
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):
Problem:
On the
RemoteA2aAgentdelegation path (orchestrator → remote specialist), streaming fails client-side with:Re-diagnosed per @surajksharma07's request on #6680 rather than reworking #6686. The cause is in the client-side stream normalizer (
_compat.make_stream_normalizer), not in the append/partial flag the server sends:A running-
Tasksnapshot is only as complete as its sender made it, and servers/proxies emit them with status and no artifacts. When one arrives after the firstappend=Falsechunk of an artifact has been folded into the aggregate, the aggregate is replaced wholesale and that artifact is gone; the nextappend=Truechunk then raises insideappend_artifact_to_task. Reproduced deterministically through the real normalizer with a2a-sdk 1.1.5:Sequence C uses exactly the flags the server sends today. This is a distinct root cause from what #6686 assumed. #6686 forced
append=Trueon the final chunk, which conflicts with thebase_llmcontract ("Final chunk:partial=False(aggregated content from entire turn)") and withtest_convert_event_to_a2a_events_final_chunk_replaces, and would have appended the full accumulated text on top of the already-streamed deltas in the common single-agent case. It masked the crash on the delegation path only because it changed which chunk the client saw first. I am closing #6686 in favour of this.Solution:
Merge the snapshot into the running aggregate instead of replacing it: artifacts the running task already holds and the snapshot lacks are carried over; an artifact the snapshot does carry wins for that id, so an authoritative snapshot still takes precedence.
from_adk_event.pyis untouched; the append/partial semantics stay as pinned onmain.Testing Plan
Unit Tests:
Two new tests in
tests/unittests/a2a/test_compat.py:test_stream_normalizer_task_snapshot_keeps_streamed_artifacts— the exact chunk / snapshot / chunk sequence. Fails onmainwith the reportedappend=True for nonexistent artifact_iderror, passes with the fix.test_stream_normalizer_task_snapshot_with_artifacts_is_authoritative— a snapshot that carries an artifact wins for that id; only missing ones are carried over.With the fix reverted and the tests kept:
2 failed(both new tests, with thenonexistent artifact_idmessage).Manual End-to-End (E2E) Tests:
The reproduction above is a 30-line script driving
make_stream_normalizer()directly withStreamResponseprotos; happy to attach it. @virktapvir, if you can re-run your deployed Agent Engine delegation repro against this branch without #6686 applied, that would confirm the diagnosis on the real path — the sequence I reproduced is the one your trace implies (the proxy emits aTaskstate between artifact events).Checklist
Built with an AI coding agent (Claude Code); diagnosis, reproduction and tests verified by running them as shown above.