Skip to content

fix(terminal): force=True no longer skips the hardline floor - #159276

Open
c2h5oh wants to merge 5 commits into
mainfrom
fix/157918-force-floor
Open

c2h5oh wants to merge 5 commits into
mainfrom
fix/157918-force-floor

Conversation

@c2h5oh

@c2h5oh c2h5oh commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

terminal_tool(force=True) returned "approved" before any guard ran, so the floor documented as never bypassable — hardline commands, runtime self-delete, password piping into sudo -S, approvals.deny rules — did not apply to a forced command. force is internal (not in the model schema) and its only caller today is the TUI path completion with a constant script, so this was latent.

force now skips the approval layers but not the floor: tools/approval.py::check_preconfirmed_command_guards runs the same floor as check_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 and approvals.mode: off refuse 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.py with 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

hr1juldey and others added 4 commits November 23, 2026 18:28
_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.
@c2h5oh

c2h5oh commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 34e5649 — test(terminal): stub the new guard in the modal test; pin th

ℹ️ Info

CI caches · View report · View job

27 / 27 cache hits (0 misses)
4281.75 MiB restored
0 B not restored.

per-job cache results

hits

JobStepLogsRestoredΔ vs main
OS-specific tests / Windows-only tests (arm64, 2/2)Set up native ARM64 build dependencies / Cache ARM64 OpenSSL development filesview step26.23 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 2/2)Set up locked Python and test dependencies / Restore verified PM tools without savingview step222.55 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 2/2)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step856.03 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 1/2)Set up native ARM64 build dependencies / Cache ARM64 OpenSSL development filesview step26.23 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 1/2)Set up locked Python and test dependencies / Restore verified PM tools without savingview step222.55 MiB+0 B
OS-specific tests / Windows-only tests (arm64, 1/2)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step856.03 MiB+0 B
Repository guards / Repository guardsRun ./.github/actions/setup-pm / Restore verified PM tools without savingview step156.11 MiB+0 B
Repository guards / Repository guardsRun ./.github/actions/setup-pm / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Repository guards / Repository guardsRun ./.github/actions/setup-pm / Restore node dependency downloadsview step180.90 MiB+0 B
Python tests / Run tests (1/3)Set up locked Python and test dependencies / Restore verified PM tools without savingview step154.75 MiB+0 B
Python tests / Run tests (1/3)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Python tests / Run tests (1/3)Restore per-file duration cacheview step0.10 MiBunknown
Remote terminal backends / SSH + Docker backends (real sshd, real daemon)Set up locked Python and test dependencies / Restore verified PM tools without savingview step83.12 MiB+0 B
Remote terminal backends / SSH + Docker backends (real sshd, real daemon)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Python tests / Run tests (3/3)Set up locked Python and test dependencies / Restore verified PM tools without savingview step154.75 MiB+0 B
Python tests / Run tests (3/3)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Python tests / Run tests (3/3)Restore per-file duration cacheview step0.10 MiBunknown
Python tests / Run tests (2/3)Set up locked Python and test dependencies / Restore verified PM tools without savingview step154.75 MiB+0 B
Python tests / Run tests (2/3)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step43.14 MiB+0 B
Python tests / Run tests (2/3)Restore per-file duration cacheview step0.10 MiB+0 B
Python lints / Python lintsRun ./.github/actions/setup-pm / Restore verified PM tools without savingview step83.12 MiB+0 B
OS-specific tests / Windows-only testsSet up locked Python and test dependencies / Restore verified PM tools without savingview step236.13 MiB+0 B
OS-specific tests / Windows-only testsSet up locked Python and test dependencies / Restore uv dependency downloads and buildsview step102.91 MiB+0 B
OS-specific tests / macOS-only tests (2/2)Set up locked Python and test dependencies / Restore verified PM tools without savingview step107.16 MiB+0 B
OS-specific tests / macOS-only tests (2/2)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step167.62 MiB+0 B
OS-specific tests / macOS-only tests (1/2)Set up locked Python and test dependencies / Restore verified PM tools without savingview step107.16 MiB+0 B
OS-specific tests / macOS-only tests (1/2)Set up locked Python and test dependencies / Restore uv dependency downloads and buildsview step167.62 MiB+0 B

misses

none

Compressed archive bytes. Not-restored bytes use the main-size reference; missing sizes remain unknown.


debug info

CI timings

CI timings · View report · View job

Wall time 6m13s vs 6m23s (-2.6%). 4 job(s) slower, 8 faster, 1 unchanged.

  • Python lints / Python lints: +57.0s
  • OS-specific tests / macOS-only tests (1/2): +21.0s
  • OS-specific tests / Windows-only tests: -19.0s
  • OS-specific tests / Windows-only tests (arm64, 1/2): -15.0s
  • Python tests / Run tests (3/3): +12.0s

@alt-glitch alt-glitch added backend/local Local shell execution P3 Low — cosmetic, nice to have tool/terminal Terminal execution and process management type/security Security vulnerability or hardening labels Nov 23, 2026
@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no blocking issue was found.

Summary

terminal_tool(force=True) now skips approval prompts without skipping the command safety floor.

  • Forced terminal commands still pass through the command floor.

No actionable new issues or confirmed repository-rule violations were found. No previous review threads were supplied. Tests were not run during this review.

Reviews (2) · Last reviewed commit: "test(terminal): stub the new guard in th..." · Reviewed by Greptile

@blacksmith-sh

This comment has been minimized.

@alt-glitch alt-glitch added the comp/tools Tool registry, model_tools, toolsets label Nov 23, 2026

@BearHuddleston BearHuddleston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_guards gives the same verdict as check_all_command_guards under approvals.mode: off in 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.deny rule matching sh -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.

Comment thread tools/terminal_tool.py

from tools.approval import (
check_all_command_guards as _check_all_guards_impl,
check_preconfirmed_command_guards as _check_preconfirmed_guards,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,health is 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=[],
     )

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added as test_force_skips_the_approval_layers in 34e5649, using your cron-default-deny version. Thanks for running the mutation probe.

@BearHuddleston BearHuddleston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 archive of the merge-base 352b249f67 gives 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 to a124d8e1.

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.

This branch has not been deployed

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

Labels

backend/local Local shell execution comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have tool/terminal Terminal execution and process management type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: terminal force=True bypasses the hardline floor ("never run, regardless of --yolo")

4 participants