The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway): watchers — flatten stall-notice send; boundary fallback early return
Tekniuma3bbb80d451d
diff --git a/gateway/run_watchers.py b/gateway/run_watchers.pyindex 79ba0d7533f..e3492e6f5e2 100644--- a/gateway/run_watchers.py+++ b/gateway/run_watchers.py@@ -188,11 +188,9 @@ class GatewaySessionWatchersMixin:agent = (getattr(self, "_running_agents", None) or {}).get(session_key)if agent is None or agent is _AGENT_PENDING_SENTINEL:return None- if not hasattr(agent, "get_activity_summary"):- return Nonetry:summary = agent.get_activity_summary()- except Exception:+ except Exception: # incl. AttributeError: agent without an activity summaryreturn Nonereturn summary if isinstance(summary, dict) else None@@ -269,27 +267,26 @@ class GatewaySessionWatchersMixin:notice = format_session_stall_notification(idle_seconds)# Bound the send: a wedged adapter transport (network hang, dead websocket) must not# block the watcher pass — siblings would go unevaluated and the watcher stop.- try:- result = await asyncio.wait_for(- adapter.send(str(source.chat_id), notice, metadata=metadata),- timeout=_STALL_NOTIFY_SEND_TIMEOUT_SECONDS,- )- except asyncio.TimeoutError:- logger.warning(- "Session stall notify send timed out after %.0fs for %s; will retry next tick",- _STALL_NOTIFY_SEND_TIMEOUT_SECONDS, session_key,- )- return False- # Adapters often return SendResult(success=False) instead of raising.- if result is not None and getattr(result, "success", True) is False:- logger.warning(- "Session stall notify failed for %s: %s",- session_key, getattr(result, "error", "send returned success=False"),- )- return False+ result = await asyncio.wait_for(+ adapter.send(str(source.chat_id), notice, metadata=metadata),+ timeout=_STALL_NOTIFY_SEND_TIMEOUT_SECONDS,+ )+ except asyncio.TimeoutError:+ logger.warning(+ "Session stall notify send timed out after %.0fs for %s; will retry next tick",+ _STALL_NOTIFY_SEND_TIMEOUT_SECONDS, session_key,+ )+ return Falseexcept Exception as exc:logger.warning("Session stall notify failed for %s: %s", session_key, exc)return False+ # Adapters often return SendResult(success=False) instead of raising.+ if result is not None and getattr(result, "success", True) is False:+ logger.warning(+ "Session stall notify failed for %s: %s",+ session_key, getattr(result, "error", "send returned success=False"),+ )+ return Falsereturn Trueasync def _notify_session_stall(diff --git a/gateway/stream_consumer.py b/gateway/stream_consumer.pyindex 3c84d9c3a67..8c33b67303f 100644--- a/gateway/stream_consumer.py+++ b/gateway/stream_consumer.py@@ -497,19 +497,18 @@ class GatewayStreamConsumer("falling back to send() for pre-prompt text (chat=%s)",_reason, self.chat_id,)- fallback_ok = Falsetry:send_result = await self.adapter.send(self.chat_id, finalize_text)- fallback_ok = getattr(send_result, "success", False)+ if getattr(send_result, "success", False):+ return Trueexcept Exception as send_err:logger.warning("%s boundary: fallback send also failed: %s", _reason, send_err)- if not fallback_ok:- logger.error(- "%s boundary: both finalize and fallback send failed "- "(chat=%s) — pre-prompt text may not have been delivered",- _reason, self.chat_id,- )- return fallback_ok+ logger.error(+ "%s boundary: both finalize and fallback send failed "+ "(chat=%s) — pre-prompt text may not have been delivered",+ _reason, self.chat_id,+ )+ return Falsedef on_delta(self, text: str) -> None:"""Thread-safe callback from the agent's worker thread. ``None`` signals a tool