fix(cron): clean up HERMES_CRON_SESSION env var after each job run (#56771) - #901
Open
hashbender wants to merge 1 commit into
Open
fix(cron): clean up HERMES_CRON_SESSION env var after each job run (#56771)#901hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
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.
Problem
When the cron scheduler runs in-process via
InProcessCronScheduler(same Python process as the gateway),run_job()setsos.environ["HERMES_CRON_SESSION"] = "1"but never removes it in thefinallyblock. Sinceos.environis process-global and shared across all threads, this sentinel leaks into interactive gateway sessions.Impact: After any cron job runs,
execute_codeand 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— setsos.environ["HERMES_CRON_SESSION"] = "1"cron/scheduler.py:3025+—finallyblock cleans upTERMINAL_CWD, ContextVars, session DB, agent resources — but notHERMES_CRON_SESSIONtools/approval.py:2655—check_code_execution_approval()readsHERMES_CRON_SESSIONfromos.getenv()and blocks executionThe codebase already uses ContextVars for per-job session state to avoid exactly this class of cross-session pollution, but
HERMES_CRON_SESSIONwas left as a rawos.environwrite.Fix
Add
os.environ.pop("HERMES_CRON_SESSION", None)to thefinallyblock inrun_job(), alongside the existingTERMINAL_CWDcleanup. This ensures the env var is only present while a cron job is actively running.Fixes NousResearch#56771
Mirror-of: NousResearch#57124
NousResearch#57124