Skip to content

fix(client): close HTTP responses when streams end early - #1470

Open
Harshil-1603 wants to merge 3 commits into
a2aproject:mainfrom
Harshil-1603:fix/close-client-http-streams
Open

Harshil-1603 wants to merge 3 commits into
a2aproject:mainfrom
Harshil-1603:fix/close-client-http-streams

Conversation

@Harshil-1603

Copy link
Copy Markdown
Contributor

Description

Closing a BaseClient.send_message() or subscribe() stream did not close the generators it was forwarding. For v1 REST and JSON-RPC, the underlying HTTP response stayed open after an explicit close, a single-message reply, or an interceptor exception.

Use aclosing at each forwarding boundary in BaseClient, the tenant decorator and the v1 HTTP transports so closure reaches the response's existing context manager immediately. The shared HTTP client remains open.

Validation:

  • The original 32 regression cases failed before the fix. All 40 closure/cancellation cases now pass across both bindings, with and without tenants and plugin hooks; 66 focused tests pass.
  • ./scripts/lint.sh passes (Ruff and ty; three existing unused-ignore warnings).
  • uv run pytest: 2,661 passed, 215 skipped, 4 xfailed, 1 xpassed.
  • The required coverage run also passes: 93.80%, above the 88% threshold.
  • git diff --check passes.

The regression uses the real client factory and HTTP transport stack with httpx.MockTransport and an open response stream whose closure is tracked. PostgreSQL/MySQL checks requiring unavailable DSNs retain their existing skips.

Implemented and tested with Codex assistance.

  • Followed the contribution guide and conventional PR title format.
  • Required tests, lint, type checks and coverage passed.
  • No public API or documentation change is needed.

@Harshil-1603
Harshil-1603 requested a review from a team as a code owner November 15, 2026 02:45
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

Base PR Delta
src/a2a/client/base_client.py 96.67% 96.70% 🟢 +0.04%
src/a2a/client/client_factory.py 89.94% 91.12% 🟢 +1.18%
src/a2a/client/transports/jsonrpc.py 95.51% 96.23% 🟢 +0.71%
src/a2a/client/transports/rest.py 89.95% 90.09% 🟢 +0.14%
src/a2a/client/transports/tenant_decorator.py 98.28% 98.33% 🟢 +0.06%
src/a2a/compat/v0_3/jsonrpc_transport.py 73.62% 75.63% 🟢 +2.01%
src/a2a/compat/v0_3/proto_utils.py 91.14% 91.51% 🟢 +0.37%
src/a2a/compat/v0_3/rest_transport.py 95.78% 95.88% 🟢 +0.10%
src/a2a/server/cluster/database_event_stream.py 93.64% 97.27% 🟢 +3.64%
Total 93.62% 93.76% 🟢 +0.13%

Generated by coverage-comment.yml

@Iwaniukooo11 Iwaniukooo11 self-assigned this Nov 16, 2026
async def __aiter__(self) -> AsyncIterator[bytes]:
yield self.payload
self.waiting.set()
await asyncio.Event().wait()

@Iwaniukooo11 Iwaniukooo11 Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a timeout in tests as now it can hang instead of fail

)
),
)
try:

@Iwaniukooo11 Iwaniukooo11 Nov 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please split those 5 if scenarios into separate tests. Also, tenant and plugin case can be handled in different test with re-using shared components

context,
):
yield event
async with aclosing(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please also apply those changes to compat layer

Close each legacy HTTP forwarding generator, including REST subscription fallback. Split cleanup scenarios into independent bounded tests and share tenant/plugin setup across protocol versions.

Assisted-by: OpenAI Codex
Preserve upstream HTTPX2 compatibility alongside the timeout marker, protocol matrix and deterministic stream cleanup.

Assisted-by: OpenAI Codex

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.

2 participants