From 17f86ab36f60121d8eb9e91c02f7aa23040dfcbc Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 03:33:28 -0700 Subject: [PATCH] fix(gateway): enter per-message profile scope off the event loop too Same class as the handoff watcher (#100014): the secondary/primary message handlers and the scoped inbound-preprocess hop entered _profile_runtime_scope synchronously on the loop thread, so a slow profile .env read or external secret-source hydration stalled every other adapter's traffic. Route those three async sites through _async_profile_runtime_scope (asyncio.to_thread load, then the existing sync scope with prepared_secret_scope=). _format_session_info_scoped is already called via asyncio.to_thread and stays sync. --- gateway/run.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index 37c3c69379..73d2d0f5c8 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -17377,7 +17377,7 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew except Exception: pass if profile_home is not None: - with _profile_runtime_scope(profile_home): + async with _async_profile_runtime_scope(profile_home): return await self._handle_message(event) return await self._handle_message(event) @@ -17441,7 +17441,7 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew if getattr(source, "profile", None) else default_home ) - with _profile_runtime_scope(profile_home): + async with _async_profile_runtime_scope(profile_home): return await self._handle_message(event) return _handler @@ -20435,7 +20435,9 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew ) -> Optional[str]: """Run inbound preprocessing under the routed profile when multiplexed.""" if getattr(getattr(self, "config", None), "multiplex_profiles", False): - with _profile_runtime_scope(self._resolve_profile_home_for_source(source)): + async with _async_profile_runtime_scope( + self._resolve_profile_home_for_source(source) + ): return await self._prepare_inbound_message_text( event=event, source=source,