Skip to content

fix: add SSE parameter and content alias for v0.3 compat streaming#1091

Open
Linux2010 wants to merge 1 commit into
a2aproject:mainfrom
Linux2010:fix/1089-stream-array-wrapping
Open

fix: add SSE parameter and content alias for v0.3 compat streaming#1091
Linux2010 wants to merge 1 commit into
a2aproject:mainfrom
Linux2010:fix/1089-stream-array-wrapping

Conversation

@Linux2010
Copy link
Copy Markdown
Contributor

Summary

Fixes #1089 - Response Stream Array-Wrapping Crash (Transport Layer Mismatch)

Changes

  1. Add ?alt=sse parameter to streaming endpoints (rest_transport.py):

    • /v1/message:stream?alt=sse
    • /v1/tasks/{id}:subscribe?alt=sse

    This forces Google A2A API to return SSE format instead of JSON array-wrapped streams that cause protobuf.json_format.ParseError.

  2. Add AliasChoices for content field (types.py):

    • Message.parts now accepts both 'parts' (v1.0) and 'content' (v0.3) field names
    • Fixes ValidationError: parts Field required when parsing v0.3 wire format responses

Test Plan

  • Added test_message_content_alias to verify content/parts alias mapping
  • Added test_compat_rest_transport_stream_url_has_alt_sse_param to verify SSE URL parameter

🤖 Generated with Claude Code

Fixes a2aproject#1089 - Response Stream Array-Wrapping Crash

1. Add ?alt=sse parameter to streaming endpoints in rest_transport.py:
   - /v1/message:stream?alt=sse
   - /v1/tasks/{id}:subscribe?alt=sse

   This forces Google A2A API to return SSE format instead of
   JSON array-wrapped streams that cause protobuf Parse errors.

2. Add AliasChoices for 'content' field in Message class (types.py):
   - Accepts both 'parts' (v1.0) and 'content' (v0.3) field names
   - Fixes ValidationError when parsing v0.3 wire format responses

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Linux2010 Linux2010 requested a review from a team as a code owner May 31, 2026 03:07
@github-actions
Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

No coverage changes.

Generated by coverage-comment.yml

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the v0.3 compatibility layer by appending the ?alt=sse query parameter to streaming endpoints in rest_transport.py and adding support for the legacy content field as an alias for parts in the Message model. Corresponding unit tests were added to verify these changes. The reviewer suggested avoiding discarding the results of async list comprehensions in tests, recommending instead to store the events for assertions or consume the generator with a loop.

req = SendMessageRequest(
message=Message(message_id='msg-1', role=Role.ROLE_USER)
)
_ = [event async for event in transport.send_message_streaming(req)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

low

Using an asynchronous list comprehension solely to consume an async generator creates an unnecessary list in memory. Consider consuming the generator with a simple loop or storing the list of events to assert on them.

Suggested change
_ = [event async for event in transport.send_message_streaming(req)]
events = [event async for event in transport.send_message_streaming(req)]

# Test subscribe
captured_paths.clear()
sub_req = SubscribeToTaskRequest(id='task-123')
_ = [event async for event in transport.subscribe(sub_req)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

low

Using an asynchronous list comprehension solely to consume an async generator creates an unnecessary list in memory. Consider consuming the generator with a simple loop or storing the list of events to assert on them.

Suggested change
_ = [event async for event in transport.subscribe(sub_req)]
events = [event async for event in transport.subscribe(sub_req)]

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.

[Bug]: Response Stream Array-Wrapping Crash (Transport Layer Mismatch)

1 participant