[Bug]: A2ACardResolver.get_agent_card raises UnicodeDecodeError and RecursionError instead of AgentCardResolutionError

Aperta
#1,478 0 commenti 0 reazioni 2 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@rohityan ci sta già lavorando.

Dal 16/11/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

What happened?

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:

import asyncio
import httpx
from a2a.client import A2ACardResolver, AgentCardResolutionError

BODIES = {
    'latin-1 body': '{"name": "Café"}'.encode('latin-1'),
    'deep nesting': b'{"name": ' + b'[' * 100_000 + b']' * 100_000 + b'}',
}

async def main():
    for label, body in BODIES.items():
        transport = httpx.MockTransport(lambda _, b=body: httpx.Response(200, content=b))
        async with httpx.AsyncClient(transport=transport) as client:
            try:
                await A2ACardResolver(client, 'http://agent').get_agent_card()
            except AgentCardResolutionError as e:
                print(label, '-> AgentCardResolutionError')
            except Exception as e:
                print(label, '->', type(e).__name__, e)

asyncio.run(main())

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 byte
deep nesting -> RecursionError maximum recursion depth exceeded while decoding a JSON array from a unicode string
Code of Conduct
  • I agree to follow this project's Code of Conduct
Lingua principale
Python
Stelle
2.2k
Fork
540
Merge medio
2g 10h
PR unite (30g)
57

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di a2aproject/a2a-python

Tutte le issue di a2aproject/a2a-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.