Skip to content

fix(cron): clean up HERMES_CRON_SESSION env var after each job run (#56771) - #901

Open
hashbender wants to merge 1 commit into
mainfrom
mirror/pr-57124
Open

fix(cron): clean up HERMES_CRON_SESSION env var after each job run (#56771)#901
hashbender wants to merge 1 commit into
mainfrom
mirror/pr-57124

Conversation

@hashbender

Copy link
Copy Markdown
Owner

Problem

When the cron scheduler runs in-process via InProcessCronScheduler (same Python process as the gateway), run_job() sets os.environ["HERMES_CRON_SESSION"] = "1" but never removes it in the finally block. Since os.environ is process-global and shared across all threads, this sentinel leaks into interactive gateway sessions.

Impact: After any cron job runs, execute_code and terminal commands in Telegram/gateway interactive sessions are blocked with the cron-deny approval error until the gateway process is restarted.

Root Cause

  • cron/scheduler.py:2444 — sets os.environ["HERMES_CRON_SESSION"] = "1"
  • cron/scheduler.py:3025+finally block cleans up TERMINAL_CWD, ContextVars, session DB, agent resources — but not HERMES_CRON_SESSION
  • tools/approval.py:2655check_code_execution_approval() reads HERMES_CRON_SESSION from os.getenv() and blocks execution

The codebase already uses ContextVars for per-job session state to avoid exactly this class of cross-session pollution, but HERMES_CRON_SESSION was left as a raw os.environ write.

Fix

Add os.environ.pop("HERMES_CRON_SESSION", None) to the finally block in run_job(), alongside the existing TERMINAL_CWD cleanup. This ensures the env var is only present while a cron job is actively running.

Fixes NousResearch#56771


Mirror-of: NousResearch#57124
NousResearch#57124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: execute_code blocked in interactive Telegram gateway session because HERMES_CRON_SESSION env var leaks from cron scheduler into user's shell

1 participant