From 58313502b72b9caa3c9bf6d1080952bfbb50be52 Mon Sep 17 00:00:00 2001 From: AlexFucuson9 Date: Thu, 2 Jul 2026 20:59:27 +0700 Subject: [PATCH] fix(cron): clean up HERMES_CRON_SESSION env var after each job run HERMES_CRON_SESSION was set via os.environ (process-global) in run_job() but never removed in the finally block. When the cron scheduler runs in-process via InProcessCronScheduler (same process as the gateway), this sentinel leaked into interactive gateway sessions, causing execute_code and terminal commands to be blocked with the cron-deny approval error. Add os.environ.pop('HERMES_CRON_SESSION', None) to the finally block alongside the existing TERMINAL_CWD cleanup. Fixes #56771 --- cron/scheduler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cron/scheduler.py b/cron/scheduler.py index 4c764bd13a445..b58b32bc28cf6 100644 --- a/cron/scheduler.py +++ b/cron/scheduler.py @@ -3031,6 +3031,9 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]: os.environ.pop("TERMINAL_CWD", None) else: os.environ["TERMINAL_CWD"] = _prior_terminal_cwd + # Remove the process-wide cron sentinel so it does not leak into + # interactive gateway sessions running in the same process (#56771). + os.environ.pop("HERMES_CRON_SESSION", None) # Release the cwd lock now that the env is restored, so a waiting # workdir job (or queued reader) can proceed without seeing the override. if _holds_cwd_write: