fix(a2a): forward use_cache=False from fetch_agent_card to afetch_agent_card - #6732
Open
LHMQ878 wants to merge 1 commit into
Open
fix(a2a): forward use_cache=False from fetch_agent_card to afetch_agent_card#6732LHMQ878 wants to merge 1 commit into
LHMQ878 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe sync agent card fetcher now forwards ChangesAgent card caching
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…nt_card fetch_agent_card's uncached branch delegated to afetch_agent_card without forwarding use_cache. afetch_agent_card declares use_cache: bool = True, so the request re-entered the cached branch and was answered by _afetch_agent_card_cached (@cached(ttl=300)) -- an explicit use_cache=False was silently reinterpreted as use_cache=True and could return a card up to 5 minutes stale. The async entry point already honours use_cache=False, so the two entry points disagreed on the meaning of the same argument. Adds three tests: one for the defect, plus controls confirming the sync cached path still caches and the async path was already correct. Closes crewAIInc#6731
LHMQ878
force-pushed
the
fix/a2a-fetch-agent-card-use-cache
branch
from
July 30, 2026 16:34
5610b7e to
4afb1bc
Compare
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.
Closes #6731
Problem
fetch_agent_card(endpoint, use_cache=False)still returns a cached AgentCard. Theuncached branch of the sync entry point delegates to the async entry point without
forwarding
use_cache:afetch_agent_carddeclaresuse_cache: bool = True, so the request re-enters the cachedbranch and is answered by
_afetch_agent_card_cached, which carries@cached(ttl=300, serializer=PickleSerializer()). An explicituse_cache=Falseis silentlyreinterpreted as
use_cache=True, and the caller can receive a card up to 5 minutes stalewith no exception and no warning.
The async entry point already honours
use_cache=False, so before this change the twoentry points disagreed about the meaning of the same argument.
Fix
One argument. The cached branch, the
cache_ttl/ttl_hashmachinery, the running-loophandling and the auth-hash key derivation are all untouched.
Evidence
Patching
_afetch_agent_card_implwith a counter that returns a distinguishable card perreal fetch, and calling each entry point twice:
fetch_agent_card(..., use_cache=False)probe-agent-1,probe-agent-1probe-agent-1,probe-agent-2fetch_agent_card(..., use_cache=True)await afetch_agent_card(..., use_cache=False)Rows 2 and 3 are the important ones: the fix does not weaken the cache, and it brings the
sync path in line with the async path that was already right.
Tests
Three tests in a new
TestFetchAgentCardCachingclass inlib/crewai/tests/a2a/utils/test_agent_card.py. Acounting_fetchfixture monkeypatches_afetch_agent_card_implwith a counter returningcard-1,card-2, … so a cache hit isdirectly observable in the returned object rather than inferred.
test_sync_use_cache_false_refetchescard-1/card-2test_sync_use_cache_true_still_cachescard-1test_async_use_cache_false_refetchescard-1/card-2Control experiment
Reverting
agent_card.pyand keeping the tests:Exactly the one regression test fails; both controls pass, so they are not passing for the
wrong reason and the new test is genuinely pinned to this change.
Suite runs
lib/crewai/tests/a2a/utils/test_agent_card.py— 24 passed (21 pre-existing + 3 new)lib/crewai/tests/a2a/— 104 passed, 0 failedruff format --check/ruff checkonagent_card.py— clean (thetests/tree is inextend-exclude, so ruff skips it by design)mypy lib/crewai/src/crewai/a2a/utils/agent_card.py—Success: no issues foundOne note on how I ran these locally:
addoptsincludes--block-network, and on Windowsasyncio.run()builds aProactorEventLoopwhose_make_self_pipe()callssocket.socketpair(), which falls back to a realconnect()to localhost and tripspytest_recording's guard. Sincefetch_agent_card's uncached path goes throughasyncio.run, I ran with--allowed-hosts=127.0.0.1,::1to let the loop's self-pipethrough. This is a Windows-only artifact of
socketpair()— on Linux it is a realsocketpair(2)syscall that never touchesconnect, so CI needs no such flag.Related, deliberately not included
fetch_agent_cardtakescache_ttl: int = 300and honours it (ttl_hash = int(time.time() // cache_ttl)as a cache-key component — verified withcache_ttl=1andtwo calls 1.1s apart producing 2 real fetches).
afetch_agent_cardhas nocache_ttlparameter at all; its cache is a hardcoded
@cached(ttl=300). Giving the async side atunable TTL means reworking the decorator, which is a feature change rather than a bug fix,
so I left it out and described it in #6731 instead.
Duplicate check
Searched the repo for
fetch_agent_card,use_cache agent card, andagent_card.pyintitles. Prior hits: #4672 and #4675 (both closed, running-event-loop handling in the sync
wrappers — different defect, same function), #5949 (closed).
One overlap I want to flag rather than have a reviewer discover: #5852
(
feat(a2a): add optional signature verification to AgentCard fetch, open) addsuse_cache=Falseto this same call as an incidental part of a much larger signature-verification feature. That PR was opened 2026-05-18, has only bot reviews, was marked stale
by the workflow on 2026-07-04, is currently
behindits base, and contains no test for thecaching behaviour. If maintainers prefer to land #5852 instead, this PR's tests still apply
to it unchanged and I am happy to close this and offer them there — but the caching bug
seems worth fixing on its own, with coverage, independent of whether a feature PR from
two and a half months ago is revived.