The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(gateway): compression-check warn helper, partial fatal handler, registry branch collapse
Tekniumf256b4a77c94
diff --git a/gateway/run_adapters.py b/gateway/run_adapters.pyindex e73acb7ab01..6372f3ae1a7 100644--- a/gateway/run_adapters.py+++ b/gateway/run_adapters.py@@ -11,6 +11,7 @@ import loggingfrom typing import TYPE_CHECKINGimport asyncioimport contextlib+import functoolsimport osimport timeimport weakref as _weakref@@ -59,10 +60,10 @@ class GatewayAdapterLifecycleMixin:await awaitablereturn Truetask = asyncio.ensure_future(awaitable)- if await self._wait_or_detach(task, timeout):- await task- return True- return False+ if not await self._wait_or_detach(task, timeout):+ return False+ await task+ return Trueasync def _safe_adapter_disconnect(self, adapter, platform) -> None:"""Call adapter.disconnect() defensively (bounded, never raises).@@ -1258,10 +1259,7 @@ class GatewayAdapterLifecycleMixin:self, profile_name: str, platform: Platform) -> Callable[[BasePlatformAdapter], Awaitable[None]]:"""Route a secondary-profile fatal error to that profile's reconnect slot."""- async def _handler(adapter: BasePlatformAdapter) -> None:- await self._handle_profile_adapter_fatal_error(profile_name, platform, adapter)-- return _handler+ return functools.partial(self._handle_profile_adapter_fatal_error, profile_name, platform)async def _handle_profile_adapter_fatal_error(self, profile_name: str, platform: Platform, adapter: BasePlatformAdapter@@ -1472,14 +1470,12 @@ class GatewayAdapterLifecycleMixin:from gateway.platform_registry import platform_registryif platform_registry.is_registered(platform.value):adapter = platform_registry.create_adapter(platform.value, config)- if adapter is not None:- return adapter- # Registered but failed — never fall through to built-ins.- logger.error(- "Platform '%s' is registered but adapter creation failed "- "(check dependencies and config)", platform.value,- )- return None+ if adapter is None: # registered but failed — never fall through to built-ins+ logger.error(+ "Platform '%s' is registered but adapter creation failed "+ "(check dependencies and config)", platform.value,+ )+ return adapterexcept Exception as e:logger.debug("Platform registry lookup for '%s' failed: %s", platform.value, e)return _instantiate_builtin_adapter(platform, config)diff --git a/gateway/run_busy.py b/gateway/run_busy.pyindex 0af8b79e886..1b51314a5f4 100644--- a/gateway/run_busy.py+++ b/gateway/run_busy.py@@ -218,6 +218,13 @@ class GatewayBusySessionMixin:session_store = getattr(self, "session_store", None)if not session_key or session_store is None:return False+ def _assume_active(what: str, ident) -> bool:+ logger.warning(+ "Compression in-flight check failed while reading %s %s; treating compression as "+ "active to avoid interrupting a possible parent-session rotation", what, ident, exc_info=True,+ )+ return True+try:session_id = await asyncio.to_thread(self._lookup_session_id_under_store_lock, session_store, session_key@@ -225,12 +232,7 @@ class GatewayBusySessionMixin:except (AttributeError, TypeError):return Falseexcept Exception:- logger.warning(- "Compression in-flight check failed while reading session %s; "- "treating compression as active to avoid interrupting a possible "- "parent-session rotation", session_key, exc_info=True,- )- return True+ return _assume_active("session", session_key)session_db = getattr(self, "_session_db", None)if not session_id or session_db is None:return False@@ -243,12 +245,7 @@ class GatewayBusySessionMixin:except (AttributeError, TypeError):return Falseexcept Exception:- logger.warning(- "Compression in-flight check failed while reading lock holder "- "for session %s; treating compression as active to avoid "- "interrupting a possible parent-session rotation", session_id, exc_info=True,- )- return True+ return _assume_active("lock holder for session", session_id)@staticmethoddef _lookup_session_id_under_store_lock(session_store, session_key: str):@@ -316,14 +313,10 @@ class GatewayBusySessionMixin:text = (event.text or "").strip()if not self._pending_event_audio_paths(event):return text-- adapter = self._adapter_for_source(event.source)enriched_text, successful_transcripts = await self._transcribe_and_echo_pending_voice(- event, adapter, event.source, text, log_context="Busy-steer"+ event, self._adapter_for_source(event.source), event.source, text, log_context="Busy-steer")- if not successful_transcripts:- return text- return (enriched_text or text).strip()+ return (enriched_text or text).strip() if successful_transcripts else text@staticmethoddef _busy_reply_to(event: MessageEvent, reply_anchor):