fix(cron): restore HERMES_CRON_SESSION after jobs - #43549
Conversation
The cron scheduler runs in-process inside the gateway. Setting HERMES_CRON_SESSION=1 process-wide without restoring the prior value leaks cron approval context into later interactive gateway sessions, which can incorrectly block tools such as execute_code. Save the prior value before each job and restore it in finally: - unset HERMES_CRON_SESSION if it was not previously set - restore the previous value if it was Add regression tests covering both the unset and pre-existing cases. Fixes NousResearch#37968 Related: NousResearch#35515 NousResearch#43370
|
✅ Verified — cron session env var lifecycle Reviewed
The fix is correct and complete. No issues found. |
VerificationReviewed the diff — this is a clean fix for a real environment-variable leak bug. Root cause: Fix: saves Tests: two new tests — one verifying cleanup when the var was unset, one verifying restoration when it was set to a different value. Both are clean and cover the two branches. No issues found. |
|
Thanks for targeting a real approval-context leak. The premise remains live on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
|
Merged via #77022. Your PR's approach (save/restore the env var in finally) was a valid minimal fix, but the merged version uses a per-session ContextVar approach for stronger isolation that also covers the gateway/API/TUI entry points. Thank you for contributing! |
What does this PR do?
The cron scheduler runs in-process inside the gateway. Setting
HERMES_CRON_SESSION=1process-wide without restoring the prior value leaks cron approval context into later interactive gateway sessions, which can incorrectly block tools such asexecute_code.This PR saves the prior value before each job and restores it in
finally:HERMES_CRON_SESSIONif it was not previously setRelated Issue
Fixes #37968
Related: #35515 #43370
Type of Change
Changes Made
cron/scheduler.py: save and restoreHERMES_CRON_SESSIONaround each cron jobtests/cron/test_scheduler.py: add regression tests for unset and pre-existing env valuesHow to Test
uv run --extra dev pytest tests/cron/test_scheduler.py::TestRunJobSessionPersistence -qChecklist
Code
fix(scope):, feat(scope):, etc.)Documentation & Housekeeping