fix(cron): do not seed HERMES_SESSION_* contextvars from cron origin (salvage of #22356)#22382
Merged
kshitijk4poor merged 2 commits intoMay 9, 2026
Conversation
This was referenced May 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Salvage of #22356 by @oferlaor (Closes #22351). Cherry-picked onto current main with original authorship preserved (origin PR is 366 commits behind main).
What changed
cron/scheduler.pywas seedingHERMES_SESSION_PLATFORM,HERMES_SESSION_CHAT_ID, andHERMES_SESSION_CHAT_NAMEfrom the cron job's storedoriginimmediately before constructingAIAgent. Those contextvars are designed to identify a live inbound gateway sender, not delivery routing metadata. This change replaces the seed with empty values:Cron output delivery is unaffected — it reads
job["origin"]directly via_resolve_origin(job)and theHERMES_CRON_AUTO_DELIVER_*contextvars, both of which are still set in the same block.Why this matters (tightened framing vs the original PR)
The original PR/issue framed this as access-control filtering stripping toolsets (
web_search,terminal,read_file) from authorized cron jobs. We were not able to reproduce that on current main — there is no per-identity toolset filter between the contextvar-set andAIAgentconstruction;enabled_toolsetsare passed straight through. We've left the structural fix in place though, because several tool consumers branch onHERMES_SESSION_*during job execution and were observably misbehaving as a result. The expanded comment in the diff lists them; the concrete ones:tools/terminal_tool.py(background-process notification routing) — when a cron job ranterminal(background=True, notify_on_complete=True),watcher_platform/watcher_chat_id/watcher_user_idetc. were populated from the seeded WhatsApp/Telegram origin instead of from the cron's ownHERMES_CRON_AUTO_DELIVER_*machinery, so completion notifications routed to the gateway origin chat. This is the most user-visible bug the change fixes.tools/tts_tool.py—platform == "telegram"decides Opus vs MP3. A cron with a non-telegram origin would silently pick the wrong format if the agent called TTS.tools/skills_tool.py+agent/prompt_builder.py— per-platform skill-disable lists and the system-prompt cache key both consumeHERMES_SESSION_PLATFORM. Cron was slotting into the origin platform's cache instead of cron's own.tools/send_message_tool.py— mirror source labelling and the_check_send_messagegate readHERMES_SESSION_PLATFORM.tools/cronjob_tools.py::_origin_from_env— falls back to the seeded vars; mostly defensive since the cronjob toolset is indisabled_toolsetsfor cron, but still wrong shape.Verification
E2E test against a fresh main worktree, simulating a cron job created from a WhatsApp group origin:
HERMES_SESSION_PLATFORM"whatsapp"""✅HERMES_SESSION_CHAT_ID"123-456-789@g.us"""✅HERMES_SESSION_CHAT_NAME"Test Group"""✅HERMES_CRON_AUTO_DELIVER_PLATFORM"whatsapp""whatsapp"✅ (delivery routing preserved)HERMES_CRON_AUTO_DELIVER_CHAT_ID"123-456-789@g.us""123-456-789@g.us"✅tools/cronjob_tools._origin_from_env(){platform: whatsapp, chat_id: ...}None✅tools/tts_toolplatform == "telegram"checkFalse(correct here, depends on origin)False✅enabled_toolsetspassed toAIAgent["web", "file", "terminal"]["web", "file", "terminal"](unchanged — confirms no filtering happens regardless)kwargs["platform"]toAIAgent"cron""cron"✅Tests run from the worktree:
No regressions in any consumer test path.
ruff checkclean.Files
cron/scheduler.py— the patch (kept @oferlaor's original edit; expanded the comment to document the real consumer list rather than "access-control filtering" so future readers don't go looking for a per-identity toolset filter that doesn't exist).scripts/release.py— addedagentsmithlaor@gmail.com → oferlaortoAUTHOR_MAPfor the contributor audit.Original PR
Closes #22351. Original PR (#22356, 366 commits behind main) being closed with credit pointing here.