Skip to content

The agent that grows with you

fix(gateway): resolve startup reclaim scopes off-loop; drop dead goals fallback

kshitijk4poor9a0c0e11b4b4
diff --git a/gateway/run_adapters.py b/gateway/run_adapters.py
index 6f2a9d435b3..416022c81df 100644
--- a/gateway/run_adapters.py
+++ b/gateway/run_adapters.py
@@ -534,20 +534,22 @@ class GatewayAdapterLifecycleMixin:
def _scope(profile_home): # local: tests bind this watcher onto bare SimpleNamespace runners
return GatewayAdapterLifecycleMixin._async_scope_or_null(_async_profile_runtime_scope, profile_home)
- for _pname, _phome in _handoff_watch_scopes(self):
+ # Resolve watch scopes off the loop: the profiles_to_serve() filesystem walk can stall the
+ # loop past the liveness probe. Bare stand-ins without the executor hop resolve inline.
+ offload = getattr(self, "_run_in_executor_with_context", None)
+
+ async def _resolve_scopes():
+ return (await offload(_handoff_watch_scopes, self) if callable(offload)
+ else _handoff_watch_scopes(self))
+
+ for _pname, _phome in await _resolve_scopes():
with _log_suppressed(logging.DEBUG, "Stale-handoff reclaim failed", exc_info=True):
async with _scope(_phome):
await _reclaim_stale(self)
- offload = getattr(self, "_run_in_executor_with_context", None)
try:
while self._running:
try:
- # Resolve watch scopes OFF the loop (the profiles_to_serve() filesystem walk can
- # stall the loop past the liveness probe on a thrashing host — see the sibling
- # fix in run_goals._loop_wakeup_watcher). Stand-ins keep the on-loop resolve.
- scopes = (await offload(_handoff_watch_scopes, self) if callable(offload)
- else _handoff_watch_scopes(self))
- for profile_name, profile_home in scopes:
+ for profile_name, profile_home in await _resolve_scopes():
# Idle gate (run_idle_gates): skip the scope entry when the profile's store
# holds no pending handoff. The root poll (None) is unscoped and stays cheap.
if profile_home is not None and not await off_loop_gate(
diff --git a/gateway/run_goals.py b/gateway/run_goals.py
index 9f1d7dfb1b7..b916ed83341 100644
--- a/gateway/run_goals.py
+++ b/gateway/run_goals.py
@@ -485,17 +485,11 @@ class GatewayGoalsMixin:
for sid, state in active_loops:
await self._loop_wakeup_fire_one(sid, state, now, warned_no_route, profile_name)
- offload = getattr(self, "_run_in_executor_with_context", None)
while self._running:
try:
- # Resolve watch scopes OFF the loop: _handoff_watch_scopes -> profiles_to_serve()
- # walks the filesystem (realpath chains + profile-dir scans) every pass; on a
- # thrashing host that stalls the loop past the liveness watchdog's 10s probe and
- # the gateway self-exits 75 (mini 27/9 wedges: [hermes] caught in posixpath.realpath).
- # Stand-in runners without the executor hop keep the historical on-loop resolve
- # (same defensive idiom as run_idle_gates.off_loop_gate).
- scopes = (await offload(_handoff_watch_scopes, self) if callable(offload)
- else _handoff_watch_scopes(self))
+ # Off-loop: profiles_to_serve() walks the filesystem (realpath chains + profile-dir
+ # scans) every pass; a stalled walk trips the loop-liveness watchdog (exit 75).
+ scopes = await self._run_in_executor_with_context(_handoff_watch_scopes, self)
for profile_name, profile_home in scopes:
# Idle gate (run_idle_gates): skip the scope entry when the profile's store holds
# no active loop. The root scan (None) is unscoped and stays cheap.