The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway): the fire's runner lookup, startup gate and live adapters resolve in the fire-startup sibling
kshitijk4poorf0d22a8c0712
diff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.pyindex 615824ec612..b24537a1cc4 100644--- a/gateway/platforms/api_server.py+++ b/gateway/platforms/api_server.py@@ -3984,8 +3984,7 @@ class APIServerAdapter(OpenAICompatRoutesMixin, BasePlatformAdapter):"""POST /api/cron/fire — Chronos fire webhook (NAS -> agent), authenticated by aNAS-minted JWT via the pluggable verifier, NOT API_SERVER_KEY. 202 + background run soa long turn never trips NAS's timeout; the store CAS claim guards double-fire on retry."""- # The startup wait's budget runs from here: a slow JWKS fetch must not push it past the- # dashboard forwarder's timeout (see api_server_fire_startup).+ # Startup-wait budget starts here so a slow JWKS fetch cannot outlast the forwarder timeout.received_at = asyncio.get_running_loop().time()from hermes_cli.config import cfg_get, load_configfrom plugins.cron_providers.chronos.verify import get_fire_verifier@@ -4034,18 +4033,10 @@ class APIServerAdapter(OpenAICompatRoutesMixin, BasePlatformAdapter):from cron.scheduler_provider import provider_supports_split_fire, resolve_cron_schedulerprovider = resolve_cron_scheduler()loop = asyncio.get_running_loop()- runner = self.gateway_runner or request.app.get("gateway_runner")- if runner is None:- with suppress(Exception):- from gateway.run import _gateway_runner_ref- runner = _gateway_runner_ref()- from gateway.platforms.api_server_fire_startup import refuse_until_started- refusal = await refuse_until_started(runner, job_id, received_at=received_at)+ from gateway.platforms.api_server_fire_startup import live_adapters_once_started+ refusal, adapters = await live_adapters_once_started(self, request, job_id, received_at=received_at)if refusal is not None:return refusal- # Live adapters (parity with the built-in ticker): E2EE / relay-fronted platforms- # have no native credential, so without them delivery fails.- adapters = getattr(runner, "adapters", None) or Nonedef _detach_fire(fire_fn, *fire_args) -> "web.Response":# The done callback owns the reservation once the task is detached.diff --git a/gateway/platforms/api_server_fire_startup.py b/gateway/platforms/api_server_fire_startup.pyindex aa4d3b6af90..aff58fb99f0 100644--- a/gateway/platforms/api_server_fire_startup.py+++ b/gateway/platforms/api_server_fire_startup.py@@ -10,6 +10,7 @@ gateway transport" (the result was lost). Wait for the gateway to finish startinfrom __future__ import annotationsimport asyncio+from contextlib import suppressfrom typing import Any, Optionalfrom aiohttp import web@@ -39,3 +40,18 @@ async def refuse_until_started(runner: Any, job_id: str, *, received_at: float){"error": "gateway unreachable; retry", "job_id": job_id}, status=503, headers={"Retry-After": "60"})await asyncio.sleep(_POLL_SECONDS)return None+++async def live_adapters_once_started(+ api_adapter: Any, request: "web.Request", job_id: str, *, received_at: float,+) -> tuple[Optional["web.Response"], Any]:+ """``(refusal, adapters)`` for a fire: the startup gate's retryable 503, else the gateway's LIVE adapters+ (parity with the built-in ticker: E2EE / relay-fronted platforms have no native credential, so without+ them delivery fails). ``None`` adapters when there is no runner (a self-hosted api_server)."""+ runner = api_adapter.gateway_runner or request.app.get("gateway_runner")+ if runner is None:+ with suppress(Exception):+ from gateway.run import _gateway_runner_ref+ runner = _gateway_runner_ref()+ refusal = await refuse_until_started(runner, job_id, received_at=received_at)+ return refusal, (getattr(runner, "adapters", None) or None)