From dbafa083b5f5b201b03a18c1d319fa9faf96a7d8 Mon Sep 17 00:00:00 2001 From: Ofer LaOr Date: Sat, 9 May 2026 06:58:11 +0000 Subject: [PATCH] fix(cron): avoid delivery origin as sender identity --- cron/scheduler.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cron/scheduler.py b/cron/scheduler.py index b8ea95692cd..df5fdfbb629 100644 --- a/cron/scheduler.py +++ b/cron/scheduler.py @@ -1204,10 +1204,31 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]: # don't clobber each other's targets (os.environ is process-global). from gateway.session_context import set_session_vars, clear_session_vars, _VAR_MAP + # Cron execution is an internal scheduler context, not a live inbound + # gateway message. Do not seed HERMES_SESSION_* contextvars from the + # stored ``origin`` (which is delivery routing metadata, not a sender + # identity). Several tool consumers branch on these vars during job + # execution and would otherwise behave as if a real user from the + # origin chat was driving the agent: + # - tools/terminal_tool.py: background-process notification routing + # (notify_on_complete / watch_patterns) reads HERMES_SESSION_PLATFORM + # and HERMES_SESSION_CHAT_ID to populate watcher_platform / chat_id, + # which would route completion notifications to the origin chat + # instead of via HERMES_CRON_AUTO_DELIVER_* below. + # - tools/tts_tool.py: picks Opus vs MP3 based on + # HERMES_SESSION_PLATFORM == "telegram". + # - tools/skills_tool.py + agent/prompt_builder.py: per-platform + # skill-disable lists and the system-prompt cache key both consume + # HERMES_SESSION_PLATFORM. + # - tools/send_message_tool.py: mirror source labelling and the + # send_message gate read HERMES_SESSION_PLATFORM. + # Cron output delivery itself reads job["origin"] directly via + # _resolve_origin(job) and the HERMES_CRON_AUTO_DELIVER_* vars set + # below, so clearing HERMES_SESSION_* here does not affect delivery. _ctx_tokens = set_session_vars( - platform=origin["platform"] if origin else "", - chat_id=str(origin["chat_id"]) if origin else "", - chat_name=origin.get("chat_name", "") if origin else "", + platform="", + chat_id="", + chat_name="", ) _cron_delivery_vars = ( "HERMES_CRON_AUTO_DELIVER_PLATFORM",