Skip to content

The agent that grows with you

fix(runtime): re-apply main's per-profile hooks and cron owner in the unified init path

Tekniumbda776074d11
diff --git a/gateway/run_bootstrap.py b/gateway/run_bootstrap.py
index 3b10ee0daa9..1b056b8c883 100644
--- a/gateway/run_bootstrap.py
+++ b/gateway/run_bootstrap.py
@@ -282,7 +282,7 @@ async def _start_gateway_start_control_socket(runner):
def _start_gateway_start_cron_and_housekeeping(runner):
"""Start the cron scheduler thread + gateway housekeeping thread; returns
``(cron_stop, cron_provider, cron_thread, housekeeping_thread)``."""
- from gateway.run import (Any, Dict, Platform, _multiplex_profile_homes, _start_gateway_housekeeping, asyncio, logger, threading)
+ from gateway.run import (Any, Dict, Platform, _cron_tick_profile_homes, _start_gateway_housekeeping, asyncio, logger, threading)
# The event loop is passed so cron delivery can use live adapters (E2EE support).
from cron.scheduler_provider import (
InProcessCronScheduler, resolve_cron_scheduler, scheduler_for_profile_mode)
@@ -295,14 +295,15 @@ def _start_gateway_start_cron_and_housekeeping(runner):
# Multiplex: tell the ticker which profile homes to tick, else secondary profiles' jobs never run.
if isinstance(cron_provider, InProcessCronScheduler) and multiplex_cron:
try:
- profile_homes = _multiplex_profile_homes(runner.config)
+ profile_homes = _cron_tick_profile_homes(runner.config)
if profile_homes:
cron_start_kwargs["profile_homes"] = profile_homes
# Per-profile adapters so each profile's cron output goes via its own bot, not the default's.
cron_start_kwargs["profile_adapters"] = getattr(runner, "_profile_adapters", None)
- # runner.adapters belongs to "default"; naming it keeps the ticker from routing a secondary's
- # cron through the default bot (even before that profile's adapter connects).
- cron_start_kwargs["default_profile"] = "default"
+ # runner.adapters belongs to the LAUNCH profile (default, or the --profile name); naming
+ # it keeps the ticker from routing a secondary's cron through that bot and lets a named
+ # multiplexer's own jobs reuse its live adapters.
+ cron_start_kwargs["default_profile"] = runner._primary_profile_name
logger.info(
"Cron scheduler will tick %d profile(s) under multiplex: %s", len(profile_homes),
[p[0] if isinstance(p, tuple) else p for p in profile_homes])
diff --git a/gateway/run_runtime_init.py b/gateway/run_runtime_init.py
index 3d5c90f43ee..6e6edd514bf 100644
--- a/gateway/run_runtime_init.py
+++ b/gateway/run_runtime_init.py
@@ -248,10 +248,11 @@ class GatewayRuntimeInitMixin:
# ``pairing_store``: global/default store (CLI, callers without profile context); ``pairing_stores``:
# per-profile map ``authz_mixin._is_user_authorized`` routes through (one whitelist per profile).
from gateway.pairing import PairingStore
- from gateway.hooks import HookRegistry
+ from gateway.hooks import ProfileHookRegistries
self.pairing_store = PairingStore()
self.pairing_stores: Dict[str, "PairingStore"] = {}
- self.hooks = HookRegistry()
+ # One HookRegistry per served profile home, resolved from the active scope at emit time.
+ self.hooks = ProfileHookRegistries()
# Per-chat voice reply mode: "off" | "voice_only" | "all"
self._voice_mode: Dict[str, str] = self._load_voice_modes()
# Per-(guild,user) transcript dedup: the voice/STT pipeline can emit one utterance twice.
diff --git a/tests/gateway/test_multiplex_phase0.py b/tests/gateway/test_multiplex_phase0.py
index 69f324519b5..69857bfbe24 100644
--- a/tests/gateway/test_multiplex_phase0.py
+++ b/tests/gateway/test_multiplex_phase0.py
@@ -73,6 +73,7 @@ class TestMultiplexConfigFlag:
import asyncio
from types import SimpleNamespace
from gateway import run as run_mod
+ from gateway import run_bootstrap
from cron.scheduler_provider import InProcessCronScheduler
captured = {}
@@ -89,7 +90,7 @@ class TestMultiplexConfigFlag:
_primary_profile_name="rex", _draining=False, _external_drain_active=False)
async def _go():
- return run_mod._start_gateway_start_cron_and_housekeeping(runner)
+ return run_bootstrap._start_gateway_start_cron_and_housekeeping(runner)
cron_stop, _provider, cron_thread, hk = asyncio.run(_go())
cron_stop.set()
diff --git a/tests/gateway/test_unified_runtime_init_multiplex.py b/tests/gateway/test_unified_runtime_init_multiplex.py
new file mode 100644
index 00000000000..5c68807fd1e
--- /dev/null
+++ b/tests/gateway/test_unified_runtime_init_multiplex.py
@@ -0,0 +1,14 @@
+"""The unified runtime's init path must build per-profile registries, not process-wide ones."""
+
+from gateway.hooks import ProfileHookRegistries
+from gateway.run_runtime_init import GatewayRuntimeInitMixin
+
+
+def test_init_registries_builds_per_profile_hook_registries():
+ class _Runner(GatewayRuntimeInitMixin):
+ def __getattr__(self, name): # unrelated collaborators the init path touches
+ return lambda *a, **k: {}
+
+ runner = _Runner()
+ GatewayRuntimeInitMixin._init_registries_and_clocks(runner)
+ assert isinstance(runner.__dict__["hooks"], ProfileHookRegistries)