From 51e377d550fabac38ce84c9ae7defbee30ca1e7a Mon Sep 17 00:00:00 2001 From: Muhammad Usama <55662931+MuhammadUsamaMX@users.noreply.github.com> Date: Tue, 28 Jul 2026 18:28:12 +0500 Subject: [PATCH] fix(cron): deliver each profile's cron via its own adapter in multiplex Builds on a61183b (per-profile HERMES_HOME scoping in the multiplex ticker). Cron EXECUTION is now scoped per profile, but _start_multiplex still passed the default profile's `adapters` to `cron_tick` for every profile. As a result all secondary profiles' cron delivery (origin/home-channel replies and failure summaries) was sent through the DEFAULT profile's platform adapter -- e.g. a secondary Telegram profile's scheduled-job output went out the DEFAULT bot instead of that profile's own bot. Thread a `profile_adapters` map (profile name -> adapters) from the gateway (GatewayRunner._profile_adapters) into InProcessCronScheduler.start and select the per-profile adapter set in the multiplex tick loop, falling back to the shared `adapters` for the default profile (which owns them). No change to single-profile behavior. --- cron/scheduler_provider.py | 15 ++++++++++++++- gateway/run.py | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cron/scheduler_provider.py b/cron/scheduler_provider.py index 50c0ce213a..ee26506278 100644 --- a/cron/scheduler_provider.py +++ b/cron/scheduler_provider.py @@ -558,6 +558,7 @@ class InProcessCronScheduler(CronScheduler): interval=60, can_dispatch=None, profile_homes=None, + profile_adapters=None, ): import logging from cron.scheduler import tick as cron_tick @@ -585,6 +586,7 @@ class InProcessCronScheduler(CronScheduler): loop=loop, interval=interval, can_dispatch=can_dispatch, + profile_adapters=profile_adapters, ) return @@ -656,6 +658,7 @@ class InProcessCronScheduler(CronScheduler): loop=None, interval=60, can_dispatch=None, + profile_adapters=None, ): """Tick every served profile's cron store when multiplex_profiles is on. @@ -711,13 +714,23 @@ class InProcessCronScheduler(CronScheduler): logger.debug("Cron dispatch paused while gateway drains existing work") else: for entry in _existing_profile_homes(profile_homes): + _pname = entry[0] if isinstance(entry, tuple) else None home = entry[1] if isinstance(entry, tuple) else entry home_token = set_hermes_home_override(str(home)) try: with use_cron_store(home): + # Deliver each profile's cron via ITS OWN bot/adapter. + # Secondary profiles live in profile_adapters[name]; + # the default profile has no entry there and owns the + # shared `adapters` set — so fall back to it. Without + # this, every profile's cron output ships through the + # default profile's bot (wrong-bot cross-delivery). + _tick_adapters = adapters + if profile_adapters and _pname and profile_adapters.get(_pname): + _tick_adapters = profile_adapters[_pname] cron_tick( verbose=False, - adapters=adapters, + adapters=_tick_adapters, loop=loop, sync=False, can_dispatch=can_dispatch, diff --git a/gateway/run.py b/gateway/run.py index 23dadfe430..01204e1a44 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -32673,6 +32673,12 @@ async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool = profile_homes = _multiplex_profile_homes(runner.config) if profile_homes: cron_start_kwargs["profile_homes"] = profile_homes + # Per-profile adapters so each profile's cron output is + # delivered via its own bot/adapter instead of the default + # profile's. + cron_start_kwargs["profile_adapters"] = getattr( + runner, "_profile_adapters", None + ) logger.info( "Cron scheduler will tick %d profile(s) under multiplex: %s", len(profile_homes),