fix(cron): isolate approval state per session - #70768
Open
DOUIF wants to merge 1 commit into
Open
Conversation
Collaborator
teknium1
reviewed
Jul 30, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating cron provenance from the gateway process; the current-main leak is real (cron/scheduler.py:3014 and tools/approval.py:241).
Problems
gateway/session_context.py:244adds_CRON_SESSIONtoclear_session_vars(), which writes"".get_session_env()returns any non-_UNSETContextVar value without consultingos.environ(gateway/session_context.py:325-331). Afterrun_job()calls its finally cleanup (cron/scheduler.py:3765), a later standalone/legacyHERMES_CRON_SESSION=1path in that context is misclassified as non-cron and can bypasscron_mode: deny.
Suggested changes
- Bind the cron marker directly in
run_job()and retain its ContextVar token; reset that token in the finally block after generic session cleanup. This restores the pre-job_UNSETstate and preserves the documented environment fallback. - Add a real
run_job()-then-env-fallback regression. Open duplicate #58663 already carries this token-reset pattern and broader stale-environment coverage.
Automated hermes-sweeper review.
| _SESSION_UI_SESSION_ID, | ||
| _SESSION_MESSAGE_ID, | ||
| _SESSION_PROFILE, | ||
| _CRON_SESSION, |
Contributor
There was a problem hiding this comment.
Adding this marker to the generic clear list makes clear_session_vars() set it to "". get_session_env() treats that explicit empty value as authoritative, so a later legacy HERMES_CRON_SESSION=1 environment fallback in the same context is ignored. Keep a token from the job-local marker binding and reset it in run_job()'s finally instead.
This was referenced Aug 2, 2026
Open
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.
Summary
HERMES_CRON_SESSIONmutation with session-local ContextVar stateRoot cause
The gateway scheduler and normal Telegram/API turns share one process. Setting
os.environ["HERMES_CRON_SESSION"] = "1"inside a job permanently changes process-global state, so later non-cron turns and MCP children inherit cron approval behavior.Verification