fix(cron): clean up HERMES_CRON_SESSION env var after each job to prevent process-wide leak into gateway sessions - #60386
Conversation
…vent process-wide leak into gateway sessions (NousResearch#60350) The cron ticker sets os.environ["HERMES_CRON_SESSION"] = "1" as a process-global marker that is never cleared. When the gateway runs cron ticks in a background thread within the same process, this env var leaks into all subsequent interactive gateway sessions, falsely identifying them as cron sessions. The approval guard in tools/approval.py reads this env var and applies cron_mode: deny, permanently blocking execute_code and dangerous terminal commands for interactive users. Fix: explicitly pop the env var in the finally block of run_job(), so it is cleaned up regardless of success or failure. Parallel jobs sharing this thread pool are serialized by the existing cwd lock, and the env var is re-set at the start of each job, so clearing it at the end is safe.
Duplicate of #57124 (the earliest open PR adding |
|
Closing as duplicate — the sweeper identified this as already covered by another PR. Thanks for the contribution! |
Summary
Fixes #60350. The cron ticker sets
os.environ["HERMES_CRON_SESSION"] = "1"as a process-global marker that is never cleared. When the gateway runs cron ticks in a background thread (same process), this env var leaks into all subsequent interactive gateway sessions, falsely identifying them as cron sessions. The approval guard reads this env var and appliescron_mode: deny, permanently blockingexecute_codeand dangerous terminal commands for interactive users.Root cause
cron/scheduler.py:2590sets the env var. The code comment explicitly acknowledges it persists for the process lifetime. Gateway cron ticks share the same process, so interactive sessions inherit the marker.Fix
Added
os.environ.pop("HERMES_CRON_SESSION", None)in thefinallyblock ofrun_job(), so it is cleaned up regardless of success or failure. Parallel jobs are serialized by the existing cwd lock, and the env var is re-set at each job start, so clearing at the end is safe.Related issues
execute_codeblocked in interactive Telegram gateway session becauseHERMES_CRON_SESSIONenv var leaks from cron scheduler into user's shell #56771, HERMES_CRON_SESSION set process-globally: interactive gateway sessions inherit cron approval policy after any cron runs #57736, [Bug]: in-process cron ticker leaks its approval marker into interactive gateway sessions #58662, Follow up: avoid process-wide cron marker leaking into later interactive gateway approvals #59236 (same root cause, different platforms)