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.
This commit is contained in:
Muhammad Usama
2026-07-28 18:28:12 +05:00
committed by Teknium
parent b8c18b8cb7
commit 51e377d550
2 changed files with 20 additions and 1 deletions
+14 -1
View File
@@ -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,
+6
View File
@@ -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),