Python: fix(a2a): initialize _close_http_client on the user-supplied-client path - #8095
Open
Yufeng He (he-yufeng) wants to merge 1 commit into
Open
Python: fix(a2a): initialize _close_http_client on the user-supplied-client path#8095Yufeng He (he-yufeng) wants to merge 1 commit into
Yufeng He (he-yufeng) wants to merge 1 commit into
Conversation
…client path A2AAgent(url=..., http_client=mine) never set _close_http_client, so exiting the async context manager raised AttributeError instead of leaving the caller's client alone. Default the flag to False up front; the two paths that create the client still flip it to True. Fixes microsoft#7950 Signed-off-by: Yufeng He <40085740+he-yufeng@users.noreply.github.com>
Yufeng He (he-yufeng)
deployed
to
github-app-auth
September 6, 2026 10:39 — with
GitHub Actions
Active
Yufeng He (he-yufeng)
deployed
to
github-app-auth
September 6, 2026 10:39 — with
GitHub Actions
Active
Yufeng He (he-yufeng)
deployed
to
github-app-auth
September 6, 2026 10:40 — with
GitHub Actions
Active
Yufeng He (he-yufeng)
deployed
to
github-app-auth
September 6, 2026 10:40 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix resolves the reported failure while preserving existing ownership behavior with adequate regression coverage.
Pull request overview
Fixes A2AAgent cleanup when callers provide their own HTTP client.
Changes:
- Initializes HTTP-client ownership consistently across constructor paths.
- Adds tests for caller-owned and internally created client cleanup.
File summaries
| File | Description |
|---|---|
python/packages/a2a/agent_framework_a2a/_agent.py |
Defaults caller-provided clients to non-owned. |
python/packages/a2a/tests/test_a2a_agent.py |
Verifies both cleanup ownership paths. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
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.
Motivation & Context
A2AAgent(url=..., http_client=my_client)is the documented way to share an httpx client across agents, but that construction path never sets_close_http_client: the attribute is only assigned in theclient is not Noneearly return and in the branch that builds a client itself. Exitingasync with A2AAgent(...)on the third path therefore raisesAttributeError: 'A2AAgent' object has no attribute '_close_http_client'(_agent.py:371), and the caller's client is never treated according to any ownership rule at all.Maintainer direction confirmed in the issue ("Please proceed").
Description & Review Guide
_close_http_client = Falseis now set before the branch split, so every construction path has the attribute by the time__aexit__can run. The two self-created paths still flip it toTrue, so ownership semantics are unchanged.client is not None) keeps its existing_close_http_client = True; I did not touch that, though it is worth a separate look if the intent there differs.Related Issue
Fixes #7950
Contribution Checklist
pytest tests/test_a2a_agent.py tests/test_a2a_executor.py tests/test_utils.py— 161 passed. (test_a2a_group_chat.pyneeds theagent-framework-orchestrationsextra, not installed locally; CI covers it.)Verified before the fix, the new test fails with the exact
AttributeErrorfrom the issue; after the fix both tests pass and ruff is clean.