Skip to content

fix(cron): clean up HERMES_CRON_SESSION env var after each job to prevent process-wide leak into gateway sessions - #60386

Closed
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/60350-cron-env-leak
Closed

fix(cron): clean up HERMES_CRON_SESSION env var after each job to prevent process-wide leak into gateway sessions#60386
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/60350-cron-env-leak

Conversation

@webtecnica

Copy link
Copy Markdown
Contributor

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 applies cron_mode: deny, permanently blocking execute_code and dangerous terminal commands for interactive users.

Root cause

cron/scheduler.py:2590 sets 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 the finally block of run_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

…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.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cron Cron scheduler and job management comp/cli CLI entry point, hermes_cli/, setup wizard sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state duplicate This issue or pull request already exists labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #57124 (the earliest open PR adding os.environ.pop("HERMES_CRON_SESSION", None) in run_job()'s finally, Closes #56771). Same code site, same mechanism; the previously-closed #59242 was already consolidated into #57124. Note for the reviewer: this PR also bundles an undisclosed unrelated change — a new _warn_vulnerable_deps() (pip-audit / pip list --outdated) wired into three hermes update output paths in hermes_cli/main.py, which the PR title/description do not mention. If that dependency-audit warning is wanted, it should be split into its own focused PR. Maintainer should pick among the open cron-env cleanups (#57124 / #56796 / #56784).

@webtecnica

Copy link
Copy Markdown
Contributor Author

Closing as duplicate — the sweeper identified this as already covered by another PR. Thanks for the contribution!

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

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/cron Cron scheduler and job management duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] execute_code blocked in WeCom gateway session — HERMES_CRON_SESSION env var leaks from in-process cron ticker (corroborating #56771)

2 participants