Skip to content

fix(client): raise AgentCardResolutionError for card bodies json cannot decode - #1540

Open
chrikrah wants to merge 2 commits into
a2aproject:mainfrom
chrikrah:fix/1478-undecodable-card-body
Open

chrikrah wants to merge 2 commits into
a2aproject:mainfrom
chrikrah:fix/1478-undecodable-card-body

Conversation

@chrikrah

Copy link
Copy Markdown
Contributor

Description

get_agent_card() now raises AgentCardResolutionError for a card body that response.json() rejects with UnicodeDecodeError (not UTF-8) or RecursionError (deep nesting), with the same message as a JSONDecodeError.

The deep-nesting test uses 100,000 levels: on Python 3.14, 10,000 levels decode without error, which fits the 3.14 failure that removed the RecursionError test from #1523.

$ uv run pytest tests/client/test_card_resolver.py   # 211d13a, src reverted, new tests kept
FAILED tests/client/test_card_resolver.py::TestGetAgentCard::test_get_agent_card_undecodable_body[latin-1]
FAILED tests/client/test_card_resolver.py::TestGetAgentCard::test_get_agent_card_undecodable_body[deep-nesting]
2 failed, 47 passed, 1 warning in 0.78s
$ uv run pytest tests/client/test_card_resolver.py   # 211d13a plus this change, Python 3.14.7
49 passed, 1 warning in 1.38s
$ uv run pytest -n 4 --cov=a2a --cov-report term --cov-fail-under=88   # Python 3.10.21
Required test coverage of 88% reached. Total coverage: 94.12%
2810 passed, 215 skipped, 4 xfailed, 1 xpassed, 219 warnings in 40.50s
$ uv run ruff check && uv run ruff format --check && uv run ty check   # ruff 0.15.16
All checks passed!
296 files already formatted
Found 3 diagnostics   # the 3 unused type: ignore warnings already on main, in files this does not touch
# not run: the Postgres and MySQL suites (no DSN set here)

@rohityan this follows your note on #1478: the three exceptions are caught around response.json() only, so a JSONDecodeError from a signature_verifier now propagates where it used to read "Failed to parse JSON for agent card". Once the workflows run I will watch the 3.14 job, since that is where #1523's recursion test broke.

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)
    • None needed: the docstring already promises this error.

Fixes #1478

…ot decode

A card served as Latin-1 raised UnicodeDecodeError and a deeply nested
card raised RecursionError from get_agent_card, because only
json.JSONDecodeError was caught. Catch all three around response.json(),
so an error raised by the caller's signature_verifier is not relabelled.

Fixes a2aproject#1478

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
@chrikrah
chrikrah requested a review from a team as a code owner November 27, 2026 13:44
On Python 3.14 the C recursion guard is bounded by stack size, so a body
nested 100,000 deep decodes on CI runners and the deep-nesting case never
reached the RecursionError branch. Raise it from response.json() instead,
and keep the Latin-1 case on a real body.

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

Base PR Delta
src/a2a/server/cluster/database_event_stream.py 96.36% 93.64% 🔴 -2.73%
Total 94.19% 94.17% 🔴 -0.03%

Generated by coverage-comment.yml

@Iwaniukooo11 Iwaniukooo11 left a comment

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.

Overall LGTM - Update PR body as you removed 100k- nesting test

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]: A2ACardResolver.get_agent_card raises UnicodeDecodeError and RecursionError instead of AgentCardResolutionError

2 participants