fix(a2a): add cache-first check to enrich_peer_metadata_nonblocking
All checks were successful
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 15s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 15s
CI / Detect changes (pull_request) Successful in 59s
E2E API Smoke Test / detect-changes (pull_request) Successful in 1m1s
CI / Platform (Go) (pull_request) Successful in 8s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 1m6s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 7s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 1m7s
CI / Canvas (Next.js) (pull_request) Successful in 9s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 1m11s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
sop-tier-check / tier-check (pull_request) Successful in 20s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 8s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 10s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 9s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 2m16s
CI / Python Lint & Test (pull_request) Successful in 6m54s
audit-force-merge / audit (pull_request) Successful in 15s

enrich_peer_metadata_nonblocking (a2a_client.py) never checked the
_peer_metadata cache before scheduling a background fetch — it always
returned None and always fired the executor thread pool. The docstring
promised "cache hit: return the cached record" but the code did not
implement it.

Fix: add the same TTL-check that enrich_peer_metadata uses before
scheduling the worker. On a warm cache hit the function now returns
immediately without touching the in-flight set or the executor.

Closes the remaining 5 test failures in test_a2a_mcp_server.py on main
that were not covered by PR #508's test-assertions fix.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · infra-sre 2026-05-11 16:59:54 +00:00
parent fc1b15b46a
commit 1380bf0907

View File

@ -187,11 +187,27 @@ def enrich_peer_metadata_nonblocking(
canon = _validate_peer_id(peer_id)
if canon is None:
return None
# Schedule background fetch unless one is already in flight for this
# peer. The synchronous version atomically reads-then-writes; the
# async version splits that into "schedule fetch" + "fetch fills
# cache later." The in-flight set keeps a flurry of pushes from
# one peer (e.g., a chatty agent) from spawning N parallel GETs.
# Cache-first: return immediately on warm hit (same TTL logic as the
# sync path). This is the hot-path optimisation — every push from a
# warm peer must return the record without touching the in-flight set
# or the executor. A background fetch that races to fill the cache
# will find the entry already present when it calls
# enrich_peer_metadata (which does its own fresh-TTL check), so it
# exits as a no-op with no extra network traffic.
current = time.monotonic()
cached = _peer_metadata_get(canon)
if cached is not None:
fetched_at, record = cached
if current - fetched_at < _PEER_METADATA_TTL_SECONDS:
return record
# Cache miss or TTL expired: schedule background fetch unless one is
# already in flight for this peer. The synchronous version atomically
# reads-then-writes; the async version splits that into "schedule
# fetch" + "fetch fills cache later." The in-flight set keeps a
# flurry of pushes from one peer (e.g., a chatty agent) from
# spawning N parallel GETs.
with _enrich_in_flight_lock:
if canon in _enrich_in_flight:
return None