You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: A2ACardResolver.get_agent_card raises UnicodeDecodeError and RecursionError instead of AgentCardResolutionError #1478
A2ACardResolver.get_agent_card() documents AgentCardResolutionError when "the response body cannot be decoded as JSON", and #1307 made the parser side keep that promise. Two bodies still escape as builtins, because the except clauses catch only json.JSONDecodeError: a card served as Latin-1 raises UnicodeDecodeError, and a deeply nested body raises RecursionError. A caller that handles AgentCardResolutionError around card discovery gets an unhandled exception from a remote agent's bad card.
Reproduced on caab6a2 (main), Python 3.10.21, httpx 0.28.1:
Expected: both lines print AgentCardResolutionError, the same as a body of [] does today.
Listing UnicodeDecodeError and RecursionError beside json.JSONDecodeError would cover it. A bare ValueError would also swallow one raised by a caller's signature_verifier, which runs in the same try. I only checked the 1.0 resolver, not the v0.3 compat path. Happy to open the pull request with a MockTransport test for each body if that fix works for you.
Relevant log output
$ python repro.py
latin-1 body -> UnicodeDecodeError 'utf-8' codec can't decode byte 0xe9 in position 13: invalid continuation bytedeep nesting -> RecursionError maximum recursion depth exceeded while decoding a JSON array from a unicode string
Hi @chrikrah, thank you for reporting this issue with a clear reproduction. I was able to reproduce the issue.
A2ACardResolver.get_agent_card() fetches the card over HTTP and calls response.json() on the httpx.Response object. When an endpoint serves non-UTF-8 bytes (such as Latin-1) or deeply nested JSON arrays that exceed recursion limits, response.json() raises UnicodeDecodeError or RecursionError. The current exception handler only catches json.JSONDecodeError. Because UnicodeDecodeError and RecursionError do not inherit from json.JSONDecodeError, they escape unhandled to the caller instead of being converted into AgentCardResolutionError.
As a workaround callers can catch and normalize these leaked exceptions around calls to A2ACardResolver.get_agent_card()using a helper wrapper.
Would you be interested in contributing towards a fix? The fix involves catching (json.JSONDecodeError, UnicodeDecodeError, RecursionError) directly without swallowing unrelated exceptions raised by a caller's signature_verifier. Let me know I can assign the issue to you.
Activity
rohityan commentedon Nov 17, 2026
Hi @chrikrah, thank you for reporting this issue with a clear reproduction. I was able to reproduce the issue.
A2ACardResolver.get_agent_card()fetches the card over HTTP and callsresponse.json()on thehttpx.Responseobject. When an endpoint serves non-UTF-8 bytes (such as Latin-1) or deeply nested JSON arrays that exceed recursion limits,response.json()raisesUnicodeDecodeErrororRecursionError. The current exception handler only catchesjson.JSONDecodeError. BecauseUnicodeDecodeErrorandRecursionErrordo not inherit fromjson.JSONDecodeError, they escape unhandled to the caller instead of being converted intoAgentCardResolutionError.As a workaround callers can catch and normalize these leaked exceptions around calls to
A2ACardResolver.get_agent_card()using a helper wrapper.Would you be interested in contributing towards a fix? The fix involves catching (json.JSONDecodeError, UnicodeDecodeError, RecursionError) directly without swallowing unrelated exceptions raised by a caller's signature_verifier. Let me know I can assign the issue to you.
fix(client): raise AgentCardResolutionError for card bodies json cann…