fix(api_server): run platform event verifiers off-loop and fail closed

The platform callback verifier can do blocking network I/O (e.g. the
google-chat adapter fetches Google signing certs on a cache miss), which
would stall the event loop if called inline. Run sync verifiers via
asyncio.to_thread (await coroutine verifiers directly), and treat a
crashing verifier as a 401 rather than a 500 through the dispatch path —
a broken verifier must never admit an event.
This commit is contained in:
Teknium 2026-07-16 06:49:11 -07:00
parent a7ec1b6e39
commit 14f023cd00

View file

@ -1328,7 +1328,20 @@ class APIServerAdapter(BasePlatformAdapter):
status=503,
)
ok, code = verifier(request.headers.get("Authorization", ""))
auth_header = request.headers.get("Authorization", "")
try:
if asyncio.iscoroutinefunction(verifier):
ok, code = await verifier(auth_header)
else:
# Platform verifiers may do blocking network I/O (e.g. Google
# signing-cert fetches) — keep that off the event loop.
ok, code = await asyncio.to_thread(verifier, auth_header)
except Exception:
# Fail closed: a crashing verifier must never admit the event.
logger.exception(
"Platform HTTP event verifier failed for %s", platform_name
)
ok, code = False, "platform_event_verifier_error"
if not ok:
return web.json_response(
_openai_error(