Skip to content

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

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

Linux2010 wants to merge 4 commits into
a2aproject:mainfrom
Linux2010:fix/1089-stream-array-wrapping

Conversation

@Linux2010

@Linux2010 Linux2010 commented May 31, 2026 •

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

Validation after merging upstream

  • ./scripts/lint.sh passed (three existing ty unused-ignore warnings).
  • uv run pytest: 2,623 passed, 215 skipped, 4 xfailed, 1 xpassed.
  • uv run pytest --cov=src --cov-report=term-missing: same results, 94% coverage.
  • PostgreSQL and MySQL tests requiring DSNs were skipped. The subscribe URL test also covers escaping reserved characters in task IDs.
  • Validated merge head b2967d7.

@Linux2010
Linux2010 requested a review from a team as a code owner May 31, 2026 03:07
@github-actions

github-actions Bot commented May 31, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

No coverage changes.

Generated by coverage-comment.yml

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

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.

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)]

@darrenhalden537-lang

Copy link
Copy Markdown

I did a quick local verification pass on this PR because it is linked from #1089.

Current PR head checked: 945de8a6ecf3420f8c1d8bcc085c032d86f387e6.

Results:

./scripts/lint.sh
# SUCCESS: All linting and formatting tasks complete!
# Ruff formatter reformatted 1 file: tests/compat/v0_3/test_conversions.py

uv run pytest tests/compat/v0_3/test_rest_transport.py::test_compat_rest_transport_stream_url_has_alt_sse_param tests/compat/v0_3/test_conversions.py::test_message_content_alias -q
# 2 passed in 0.43s

The formatter-only diff I saw locally was:

-    assert msg2.parts == [types_v03.Part(root=types_v03.TextPart(text='response'))]
+    assert msg2.parts == [
+        types_v03.Part(root=types_v03.TextPart(text='response'))
+    ]

So the failing lint check appears to be fixable by running the repo formatter and pushing the formatted test assertion. The targeted behavior tests still pass after formatting.

Linux2010 added a commit to Linux2010/a2a-python that referenced this pull request Jul 4, 2026
@Linux2010
Linux2010 force-pushed the fix/1089-stream-array-wrapping branch from 035cdb4 to 71c236b Compare July 25, 2026 03:54
Linux2010 added a commit to Linux2010/a2a-python that referenced this pull request Jul 25, 2026
Linux2010 added a commit to Linux2010/a2a-python that referenced this pull request Aug 2, 2026
@Linux2010
Linux2010 force-pushed the fix/1089-stream-array-wrapping branch from 325d542 to da24d49 Compare August 2, 2026 15:51
Linux2010 added a commit to Linux2010/a2a-python that referenced this pull request Aug 14, 2026
@Linux2010
Linux2010 force-pushed the fix/1089-stream-array-wrapping branch from da24d49 to 4391fe3 Compare August 14, 2026 14:36
@Linux2010

Copy link
Copy Markdown
Contributor Author

感谢审查!关于测试中丢弃 async list 结果的问题已处理:

测试已重构,不再使用 _ = [...] 丢弃模式,改为将 async for 的结果保存到 events 变量并做断言,确保流式事件被正确消费和验证。

已 rebase 到最新 upstream/main,CI 全部通过。请再次审查,谢谢!

Linux2010 and others added 3 commits September 16, 2026 22:12
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 force-pushed the fix/1089-stream-array-wrapping branch from 4391fe3 to 57663f1 Compare September 16, 2026 15:40
@ishymko
ishymko requested review from a team and removed request for a team November 12, 2026 10:28
@Linux2010

Copy link
Copy Markdown
Contributor Author

Hi @ishymko — this has been open since May, so before doing anything with it: given that 1.0 media-type validation has since landed and the v0.3 compat layer is in maintenance mode, is the ?alt=sse parameter plus the content alias for Message.parts still something the v0.3 compat layer should carry?

If yes, I'll rebase and refresh this. If it's no longer relevant (or the fix belongs elsewhere), say the word and I'll close it — no hard feelings either way. Planning to close it in ~two weeks if there's no signal, just to keep the queue honest.

@ishymko

ishymko commented Nov 13, 2026

Copy link
Copy Markdown
Member

Hey @Linux2010, thanks for the ping, I no longer actively maintain the repo, let me redirect this.

@Linux2010

Copy link
Copy Markdown
Contributor Author

Following up on the redirect above — @ishymko indicated he's no longer actively maintaining the repo, so re-raising this with the current maintainer team: @rohityan does the v0.3 compat layer still want the ?alt=sse parameter plus the content alias for Message.parts (PR as rebased onto current main, CI green)?

If the answer is "the 1.0 media-type validation direction makes this moot" or "v0.3 compat is frozen for new surface", I'll close this PR and the underlying question can live on #1089. Just need a direction to keep the queue honest.

This branch has not been deployed

No deployments
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)

4 participants