Skip to content

fix(cron): clean up HERMES_CRON_SESSION env var after each job run (#59236) - #59242

Closed
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/59236-cron-session-cleanup
Closed

fix(cron): clean up HERMES_CRON_SESSION env var after each job run (#59236)#59242
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/59236-cron-session-cleanup

Conversation

@webtecnica

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #59179 review feedback: the in-process cron scheduler sets os.environ["HERMES_CRON_SESSION"] = "1" process-wide but never clears it, causing the cron-mode approval behavior to leak into interactive gateway sessions.

Problem

When InProcessCronScheduler fires a job inside the gateway process, HERMES_CRON_SESSION=1 persists in os.environ for the lifetime of the process. Every subsequent interactive session (Telegram, Discord, etc.) inherits this marker, so:

  • cron_mode: deny (default): execute_code and dangerous commands are hard-blocked with "cron jobs run without a user present"
  • cron_mode: approve: dangerous commands are auto-approved without user prompt

Fix

1 line added in cron/scheduler.py:run_job() finally block (line 3187):

os.environ.pop("HERMES_CRON_SESSION", None)

Placed alongside the existing TERMINAL_CWD cleanup and ContextVar clear — the marker is now only present while a cron job is actively running.

Why this approach

The scheduler already has a well-established finally block for exactly this kind of cleanup (TERMINAL_CWD restore, ContextVar clear, lock release). Adding the pop here is:

  • Consistent with the existing cleanup patterns
  • Minimal — 1 line, no new imports or APIs
  • Backward compatible — the env var is still set before each job and cleared after

Closes #59236

@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists labels Jul 5, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #57124 — both PRs add the byte-identical os.environ.pop("HERMES_CRON_SESSION", None) in the same run_job() finally block of cron/scheduler.py, fixing the same process-global sentinel leak (this one cites #59236, #57124 cites #56771 — same bug). #57124 (opened 2026-07-02) is the earliest open PR, so it's canonical.

The in-process cron scheduler sets `os.environ["HERMES_CRON_SESSION"] = "1"`
process-wide but never clears it. Since `InProcessCronScheduler` runs in the
same process as the gateway, this env var leaks into every interactive session
after the first cron tick fires, causing the approval system to incorrectly
apply cron_mode (e.g. blocking execute_code with "cron jobs run without a
user present") to interactive gateway sessions.

Fix: add `os.environ.pop("HERMES_CRON_SESSION", None)` to the run_job()
finally block, alongside the existing TERMINAL_CWD cleanup and ContextVar
clear. The marker is now only present while a cron job is actively running.

Closes NousResearch#59236
@webtecnica
webtecnica force-pushed the fix/59236-cron-session-cleanup branch from 899bc99 to a4c3da6 Compare July 6, 2026 05:16
@webtecnica

Copy link
Copy Markdown
Contributor Author

Closing as duplicate of #57124 (opened 2026-07-02, byte-identical fix in the same finally block). The cron sentinel cleanup is covered there.

@webtecnica

Copy link
Copy Markdown
Contributor Author

Already commented — closing as duplicate.

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

Labels

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.

Follow up: avoid process-wide cron marker leaking into later interactive gateway approvals

2 participants