Repository navigation
Conversation
_run_approval_guards returned approved_run=True on force before any guard ran, so an operator-confirmed rm -rf /-class command or sudo -S password piping skipped the unconditional floor entirely (#157918). The floor now runs ahead of the force fast path; force keeps skipping the interactive approval layers. Tests: force=True on a hardline command and on sudo -S piping raises _Rejected; force=True on a benign command still auto-approves. Fixes #157918
…floor with check_all_command_guards force skipped the human-only refusal of a command the hardline scan could not read to the end, which YOLO and approvals.mode: off still apply, so a pre-confirmation outranked a bypass. Both paths now take the floor from one helper (_floor_verdict) instead of a copied sequence, and the tests assert the refusal reason in their own file.
|
@greptileai review |
૮ >ﻌ< ა ci reviewran on 34e5649 — test(terminal): stub the new guard in the modal test; pin th ℹ️ InfoCI caches · View report · View job27 / 27 cache hits (0 misses) per-job cache resultshits
missesnone Compressed archive bytes. Not-restored bytes use the main-size reference; missing sizes remain unknown. debug infoCI timingsCI timings · View report · View jobWall time 6m13s vs 6m23s (-2.6%). 4 job(s) slower, 8 faster, 1 unchanged.
|
[Low impact] The PR appears safe to merge; no blocking issue was found.
|
This comment has been minimized.
This comment has been minimized.
BearHuddleston
left a comment
There was a problem hiding this comment.
TL;DR: One blocker: the new import breaks an old test stub, so Python tests / Run tests (3/3) and the required All required checks pass (v2) gate are red on this head. The fix is one line in that test. There's also one optional test nit. The floor change itself checks out.
| # | Finding | Severity | Where | Status |
|---|---|---|---|---|
| 1 | The tools.approval stub in tests/tools/test_managed_browserbase_and_modal.py lacks the new name, so importing terminal_tool fails there and the required gate is red |
Blocker | tools/terminal_tool.py:142 |
Open |
| 2 | No test pins that force still skips the approval layers: routing it back through check_all_command_guards passes the suite |
Nit (optional) | tests/tools/test_terminal_force_floor.py:59 |
Open |
Thanks for carrying #158143 forward. CI run 45228287945 on this head passed Python tests 1/3 (test_terminal_force_floor.py 7 passed) and 2/3, the lints, and the macOS and Windows lanes; 3/3 failed only on finding 1. I ran the new test file against a git archive of the merge-base 352b249f67: the 5 refusal cases fail with DID NOT RAISE _Rejected and the 2 allowed cases pass, as the PR body says. A mutation probe over _floor_verdict, check_preconfirmed_command_guards and the force branch (5 test files, 67 tests) caught 8 of 10 mutants. The two survivors are finding 2 and a mutant that checks the unread refusal ahead of the isolated-container fast path, which matches check_all_command_guards' own container behaviour, so I'm not raising it.
Probes with real imports against a temp home, base vs head:
- The real remote path-completion command (the script in
methods_complete._backend_dir_entries) still runs forced on local, ssh and docker-with-mounts for every directory I tried (/workspace,~,/,/dev, a name with spaces,-rf,*). Only a directory literally named$(rm -rf /)is now refused, and completion just returns nothing for it. The forced guard pass costs about 10 ms per completion, the same scan every unforced terminal call already pays. check_preconfirmed_command_guardsgives the same verdict ascheck_all_command_guardsunderapprovals.mode: offin all 35 cells of 7 commands x 5 backends (local, ssh, modal, isolated docker, docker with mounts). Only the unread refusal's reason text differs, by design.- An
approvals.denyrule matchingsh -c*now also stops remote path completion. That follows from the documented never-bypassable deny contract, so I'm not raising it.
The _floor_verdict extract leaves check_all_command_guards unchanged (the container branch never returns None; the other returns _floor_block's result as before). A GPT Sol reviewer (gpt-6.2-sol) read the diff with these leads and raised the same two items, nothing else.
Details and tested patches are in the inline comments.
Written and posted by Hermes Agent, Bear's AI agent, without Bear reading it first. An approval from it is never on behalf of hermes-agent-core: where that team's review is requested or required, the approval comes from Bear himself.
|
|
||
| from tools.approval import ( | ||
| check_all_command_guards as _check_all_guards_impl, | ||
| check_preconfirmed_command_guards as _check_preconfirmed_guards, |
There was a problem hiding this comment.
The new check_preconfirmed_command_guards import breaks tests/tools/test_managed_browserbase_and_modal.py, so Python tests / Run tests (3/3) and All required checks pass (v2) are red on this head.
That test installs a types.SimpleNamespace stub as sys.modules["tools.approval"] (lines 169-175). The stub defines check_all_command_guards but not the new name, and this module imports both at load time, so loading terminal_tool under the stub raises ImportError: cannot import name 'check_preconfirmed_command_guards' at this line. It's the only such stub of tools.approval under tests/.
- CI run 45228287945, job
Python tests / Run tests (3/3): 30160 passed, 1 failed,test_terminal_tool_respects_direct_modal_mode_without_falling_back_to_managed, with that error. - Locally on this head the file gives 6 passed, 1 failed (same test, same error). With the patch below it's 7 passed, and
scripts/check --only ruff,healthis clean.
The fix goes in the stub, outside this diff; production code stays as it is:
diff --git a/tests/tools/test_managed_browserbase_and_modal.py b/tests/tools/test_managed_browserbase_and_modal.py
index 6031bdb..5322360 100644
--- a/tests/tools/test_managed_browserbase_and_modal.py
+++ b/tests/tools/test_managed_browserbase_and_modal.py
@@ -170,6 +170,7 @@ def _install_fake_tools_package():
detect_dangerous_command=lambda *args, **kwargs: None,
check_dangerous_command=lambda *args, **kwargs: {"approved": True},
check_all_command_guards=lambda *args, **kwargs: {"approved": True},
+ check_preconfirmed_command_guards=lambda *args, **kwargs: {"approved": True},
load_permanent_allowlist=lambda *args, **kwargs: [],
DANGEROUS_PATTERNS=[],
)There was a problem hiding this comment.
Fixed in 34e5649: the tools.approval stub in tests/tools/test_managed_browserbase_and_modal.py now has check_preconfirmed_command_guards. That file passes locally (7/7) together with test_terminal_force_floor.py.
| ]) | ||
| def test_force_runs_a_confirmed_command_the_floor_allows(command, config): | ||
| verdict = terminal_tool._run_approval_guards(command, config["env_type"], config, force=True) | ||
| assert verdict.approved_run is True |
There was a problem hiding this comment.
Optional: nothing pins the other half of the contract, that force still skips the approval layers.
Both allowed rows (ls -la locally, rm -rf / in an isolated container) are also approved by check_all_command_guards when no approval surface is present. So a change that sends the force branch back through _check_all_guards passes all 7 tests here and the 60 in the four neighbouring files I ran (test_approved_command_clean_slate, test_command_guards, test_approval_deny_rules, tui_gateway/test_backend_dir_entries_preconfirmed, which fakes terminal_tool entirely). That's the regression the completion path's force=True exists to avoid (#115478).
The test below uses cron's default cron_mode: deny as the approval layer. It asserts that the unforced call is refused, so the row isn't vacuous, and that the forced one runs. It passes on this head, and it is the only test that catches that mutant (1 failed of 8). scripts/check --only ruff,health is clean with it.
| assert verdict.approved_run is True | |
| assert verdict.approved_run is True | |
| def test_force_skips_the_approval_layers(monkeypatch): | |
| """Only the floor binds a forced command, not an approval layer that refuses it unforced (cron's default deny).""" | |
| monkeypatch.setenv("HERMES_CRON_SESSION", "1") | |
| with pytest.raises(terminal_tool._Rejected): | |
| terminal_tool._run_approval_guards("rm -rf build/", "local", LOCAL, force=False) | |
| assert terminal_tool._run_approval_guards("rm -rf build/", "local", LOCAL, force=True).approved_run is True |
There was a problem hiding this comment.
Added as test_force_skips_the_approval_layers in 34e5649, using your cron-default-deny version. Thanks for running the mutation probe.
…skips the approval layers (#157918)
BearHuddleston
left a comment
There was a problem hiding this comment.
TL;DR: Re-reviewed at 34e5649: both of my earlier findings are fixed, and nothing new came up. No blockers from me on this head.
| # | Finding | Severity | Where | Status |
|---|---|---|---|---|
| 1 | The tools.approval stub in the modal test lacked the new name, so the required gate was red |
Blocker | tests/tools/test_managed_browserbase_and_modal.py:173 |
Fixed in 34e5649: the file passes, and Python tests / Run tests (3/3) and All required checks pass (v2) are green |
| 2 | No test pinned that force still skips the approval layers |
Nit | tests/tools/test_terminal_force_floor.py:62 |
Fixed in 34e5649: test_force_skips_the_approval_layers catches the force-through-check_all_command_guards mutant |
The new commit is test-only and matches the two patches from my first review byte for byte. tools/ and tui_gateway/ haven't changed since a124d8e1, so the rest of that review carries over.
CI run 45269560497 on this head is green across the board: Python tests 1/3, 2/3 and 3/3 with 0 failures (the modal test 7 passed, test_terminal_force_floor.py 8 passed), lints, macOS, Windows x64 and arm64, the SSH and Docker backends, and the repository guards. I reran my earlier probes unchanged:
- The force-floor file against a
git archiveof the merge-base352b249f67gives 5 failed and 3 passed. The five refusal rows still fail there, and the new test passes on the base by design, since the base's force approves everything. - The mutation probe (5 test files, 68 tests) now catches 9 of 10 mutants. The one survivor is the container-ordering mutant I didn't raise last time, because it matches
check_all_command_guards' own container behaviour. - The remote path-completion probe and the parity probe against
approvals.mode: off(35 cells) give identical output toa124d8e1.
A GPT Sol reviewer (gpt-6.2-sol) re-checked the new commit in the same session and marked both items resolved, with nothing new.
No new inline comments.
Written and posted by Hermes Agent, Bear's AI agent, without Bear reading it first. An approval from it is never on behalf of hermes-agent-core: where that team's review is requested or required, the approval comes from Bear himself.
terminal_tool(force=True)returned "approved" before any guard ran, so the floor documented as never bypassable — hardline commands, runtime self-delete, password piping intosudo -S,approvals.denyrules — did not apply to a forced command.forceis internal (not in the model schema) and its only caller today is the TUI path completion with a constant script, so this was latent.forcenow skips the approval layers but not the floor:tools/approval.py::check_preconfirmed_command_guardsruns the same floor ascheck_all_command_guards(both through_floor_verdict, so they cannot drift), and also refuses a command the hardline scan could not read to the end — YOLO andapprovals.mode: offrefuse those too, and a caller's pre-confirmation should not outrank them. An isolated container keeps its existing semantics (deny rules only).Salvaged from #158143 by @hr1juldey (their commit is first, authorship kept); the later commits add the unread-command refusal, share the floor sequence instead of copying it, and move the tests to
tests/tools/test_terminal_force_floor.pywith reason assertions (hardline, the sudo stdin guard, deny rule in an isolated container, Docker with host mounts, unread command). All five refusal cases fail on main.Fixes #157918