fix(a2a): do not cache remote agent card when validation fails - #6903
Closed
Ashfaqbs wants to merge 1 commit into
Closed
fix(a2a): do not cache remote agent card when validation fails#6903Ashfaqbs wants to merge 1 commit into
Ashfaqbs wants to merge 1 commit into
Conversation
RemoteA2aAgent._ensure_resolved() assigned self._agent_card before calling _validate_agent_card(). When validation raised (e.g. an RPC URL that fails the https/loopback check), the invalid card stayed cached. The next invocation's `if not self._agent_card:` guard then evaluated to False, so resolution and validation were both skipped and the previously-rejected card was reused to build the A2A client. Only assign self._agent_card after validation succeeds, so a failed validation is retried (and re-validated) on the next call instead of silently bypassed. Fixes google#6901
Author
|
Closing this — I see Thanks for maintaining this project — happy to keep contributing if there's anything in the backlog worth picking up. |
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Problem:
RemoteA2aAgent._ensure_resolved()(shared/cached resolution path) assignedself._agent_card = await self._resolve_agent_card(ctx)before callingawait self._validate_agent_card(self._agent_card). When validation raises (e.g. an RPC URL that fails the https/loopback check), the invalid card is already cached onself._agent_card. The next invocation'sif not self._agent_card:guard then evaluates toFalse, so resolution and validation are both skipped entirely and the previously-rejected, unvalidated card is reused to build the A2A client — the exact bypass described in #6901.Solution:
Hold the resolved card in a local variable, validate it, and only assign it to
self._agent_cardafter validation succeeds. A failed validation now leavesself._agent_cardasNone, so the next call re-resolves and re-validates instead of reusing the rejected card.Testing Plan
Unit Tests:
Added
test_ensure_resolved_does_not_cache_card_on_validation_failureintests/unittests/agents/test_remote_a2a_agent.py, assertingself._agent_cardstaysNoneafter a validation failure and that the next call re-resolves + re-validates (rather than reusing a cached invalid card) and succeeds once validation passes.Note: I tested against the commit just before
85b52f6a(chore(live): create top-level google.adk.live package...), since that commit's diff appears to be missing the actualsrc/google/adk/live/package it references (only the tests undertests/unittests/live/landed), which currently breaksimport google.adkonmain. That's unrelated to this change — flagging separately rather than bundling here.Manual End-to-End (E2E) Tests:
Not run — this is a pure caching-order bug, fully exercised by the unit test above (mocks
_validate_agent_cardto raise on the first call, succeed on the second, and asserts the card is neither cached nor reused across the failure).Checklist