Merge pull request 'fix(a2a): add cache-first check to enrich_peer_metadata_nonblocking' (#518) from sre/fix-enrich-nonblocking-cache-check into main
Some checks failed
Block internal-flavored paths / Block forbidden paths (push) Successful in 14s
Secret scan / Scan diff for credential-shaped strings (push) Successful in 12s
CI / Detect changes (push) Successful in 48s
E2E API Smoke Test / detect-changes (push) Successful in 46s
Handlers Postgres Integration / detect-changes (push) Successful in 46s
E2E Staging Canvas (Playwright) / detect-changes (push) Successful in 51s
CI / Platform (Go) (push) Successful in 12s
Runtime PR-Built Compatibility / detect-changes (push) Successful in 53s
CI / Shellcheck (E2E scripts) (push) Successful in 11s
CI / Canvas (Next.js) (push) Successful in 12s
Handlers Postgres Integration / Handlers Postgres Integration (push) Successful in 6s
E2E API Smoke Test / E2E API Smoke Test (push) Successful in 9s
CI / Canvas Deploy Reminder (push) Has been skipped
publish-runtime-autobump / autobump-and-tag (push) Failing after 1m7s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (push) Successful in 14s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (push) Successful in 2m10s
Sweep stale e2e-* orgs (staging) / Sweep e2e orgs (push) Successful in 8s
Sweep stale Cloudflare DNS records / Sweep CF orphans (push) Failing after 18s
ci-required-drift / drift (push) Failing after 1m40s
CI / Python Lint & Test (push) Successful in 7m7s
Continuous synthetic E2E (staging) / Synthetic E2E against staging (push) Failing after 7m44s

This commit is contained in:
hongming-pc2 2026-05-11 17:11:35 +00:00
commit 7064f6d9f2

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