-
Notifications
You must be signed in to change notification settings - Fork 52.1k
fix(cron): isolate approval context per job #76749
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
brendanlees
wants to merge
1
commit into
NousResearch:main
Choose a base branch
from
brendanlees:fix/cron-session-approval-context
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
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,60 @@ | ||
| """Regression coverage for task-local cron approval identity.""" | ||
|
|
||
| import os | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from cron.scheduler import run_job | ||
|
|
||
| _RUNTIME = { | ||
| "api_key": "test-key", | ||
| "base_url": "https://example.invalid/v1", | ||
| "provider": "openrouter", | ||
| "api_mode": "chat_completions", | ||
| } | ||
|
|
||
|
|
||
| def test_run_job_scopes_cron_identity_without_process_leak(tmp_path, monkeypatch): | ||
| """Cron policy is active during the run and absent from later gateway turns.""" | ||
| monkeypatch.delenv("HERMES_CRON_SESSION", raising=False) | ||
| observed = {} | ||
|
|
||
| def run_conversation(_prompt): | ||
| from gateway.session_context import get_session_env | ||
| from tools.approval import _is_cron_approval_context | ||
|
|
||
| observed["context_value"] = get_session_env("HERMES_CRON_SESSION", "") | ||
| observed["approval_context"] = _is_cron_approval_context() | ||
| observed["process_value"] = os.environ.get("HERMES_CRON_SESSION") | ||
| return {"final_response": "ok"} | ||
|
|
||
| job = {"id": "cron-context", "name": "test", "prompt": "hello"} | ||
| fake_db = MagicMock() | ||
|
|
||
| with ( | ||
| patch("cron.scheduler._hermes_home", tmp_path), | ||
| patch("cron.scheduler._resolve_origin", return_value=None), | ||
| patch("hermes_cli.env_loader.load_hermes_dotenv"), | ||
| patch("hermes_cli.env_loader.reset_secret_source_cache"), | ||
| patch("hermes_state.SessionDB", return_value=fake_db), | ||
| patch( | ||
| "hermes_cli.runtime_provider.resolve_runtime_provider", | ||
| return_value=_RUNTIME, | ||
| ), | ||
| patch("tools.mcp_tool.discover_mcp_tools", return_value=[]), | ||
| patch("run_agent.AIAgent") as mock_agent_cls, | ||
| ): | ||
| mock_agent = MagicMock() | ||
| mock_agent.run_conversation.side_effect = run_conversation | ||
| mock_agent_cls.return_value = mock_agent | ||
|
|
||
| success, _output, final_response, error = run_job(job) | ||
|
|
||
| assert success is True | ||
| assert final_response == "ok" | ||
| assert error is None | ||
| assert observed == { | ||
| "context_value": "1", | ||
| "approval_context": True, | ||
| "process_value": None, | ||
| } | ||
| assert os.environ.get("HERMES_CRON_SESSION") is None |
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
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 bridged name also requires updating the shared-shell snapshot exclusion in
tools/environments/base.py: its_VAR_MAPsynchronization contract currently excludes onlyHERMES_SESSION_*,HERMES_UI_SESSION_ID, andHERMES_CRON_AUTO_DELIVER_*. Otherwise a cron terminal child can persistHERMES_CRON_SESSION=1in the shared snapshot.