Repository navigation
fix(cron): isolate approval state per session #70768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DOUIF
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
DOUIF:fix/cron-context-isolation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """Regression tests for cron approval state isolation in long-lived gateways.""" | ||
|
|
||
| from gateway.session_context import clear_session_vars, reset_session_vars, set_session_vars | ||
| from tools.approval import _is_cron_session, _is_gateway_approval_context | ||
|
|
||
|
|
||
| def test_gateway_context_masks_stale_process_cron_flag(monkeypatch): | ||
| """A cron run must not make later Telegram turns look non-interactive.""" | ||
| monkeypatch.setenv("HERMES_CRON_SESSION", "1") | ||
| monkeypatch.setenv("HERMES_GATEWAY_SESSION", "1") | ||
| tokens = set_session_vars(platform="telegram", cron_session=False) | ||
| try: | ||
| assert _is_cron_session() is False | ||
| assert _is_gateway_approval_context() is True | ||
| finally: | ||
| clear_session_vars(tokens) | ||
| reset_session_vars() | ||
|
|
||
|
|
||
| def test_cron_context_is_task_local_without_process_env(monkeypatch): | ||
| """Cron approval mode works without mutating process-global os.environ.""" | ||
| monkeypatch.delenv("HERMES_CRON_SESSION", raising=False) | ||
| monkeypatch.setenv("HERMES_GATEWAY_SESSION", "1") | ||
| tokens = set_session_vars(platform="", cron_session=True) | ||
| try: | ||
| assert _is_cron_session() is True | ||
| assert _is_gateway_approval_context() is False | ||
| finally: | ||
| clear_session_vars(tokens) | ||
| reset_session_vars() |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 legacyHERMES_CRON_SESSION=1environment fallback in the same context is ignored. Keep a token from the job-local marker binding and reset it inrun_job()'s finally instead.