Repository navigation
fix(hitl): make session and always approval grants actually stick - #464
Merged
Merged
Conversation
Approving a command or a network host "for this session" or "always" did not prevent the next matching call from prompting again. Five distinct defects, all on the human-in-the-loop approval path. Shell commands are not governance-gated (`default_hitl_tools()` is `["mcp:*"]`), so their prompts come from `ToolError::SandboxDenied` in `finish_tool_application`, which never consulted the operator's allow rules at all. An "always allow" grant was written to permissions.toml and read by nothing on the path that re-prompts. Sandbox denials now ask `Governance::grant_covers` and re-run unconfined when a rule already covers the call, which is the same consent the prompt would collect. Denied hosts are excluded: a command-shaped rule must not silently open a network destination. `suggest_pattern` built its rule from the raw command while `PatternRule::matches` tested the normalized permission subject, so most real commands produced a grant that could not match the call it came from -- `cargo test --workspace 2>&1 | tail` suggested `bash(cargo test *)` and then never matched anything with a pipe, and `RUST_LOG=debug cargo test` suggested a rule with the env prefix baked in that matched nothing at all. It now derives the prefix from the same normalized subject, and returns None for a command carrying unquoted control syntax, which has no matchable rule by design. `pattern_allow_eligible` requires a suggestion, so those calls no longer offer a "remember this" row that writes a grant which can never fire. The rustdoc invariant is now true and asserted. `apply_hitl_decision` branched on `denied_host` before it read `decision`, so "Don't run" and Esc on a network prompt granted the host for the session and ran the command while the status line said "Action denied". Refusal is now settled first, failing closed on any non-approval. `suggest_pattern` had no case for the structured `git` tool, so it fell back to the bare tool name: approving `git reset --hard HEAD~1` for the session also permitted `git clean -fd`. A git branch keeps the subcommand and its flags, and the row's help line narrows with it. `retain_session_patterns_from` was dead code; `set_governance` now calls it, so a policy reload cannot silently revoke grants made at a prompt. Two further defects were found while verifying the above in a real PTY rather than in tests, and are fixed here too. The new auto-approve gate asked only whether an allow rule matched, letting a personal `allow = ["bash(cargo test *)"]` override a workspace `deny = ["bash"]`; `grant_covers` checks deny first, mirroring `authorize`'s own ordering. And the automatic unconfined retry was unbounded -- the rule that authorises the first retry authorises the next, so a tool reporting a denial even unconfined would re-run forever. `TurnState` caps it at one retry per call per turn. Verified in tmux against the release binary: a piped command offers no remember rows, a simple one offers a pattern that matches itself, a git prompt names its subcommand, refusing a network prompt neither runs the command nor grants the host, and allowing `**.example.com` for the session covers `www.example.com` with no second prompt. Claude-Session: https://claude.ai/code/session_01QxjMZfzyjBuq3m25CWkzXu
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
fix(hitl): make session and always approval grants actually stick
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
fix(hitl): make session and always approval grants actually stick
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Approving a command or a network host "for this session" or "always" did not stop the next matching call from prompting again. This fixes five distinct defects on the HITL approval path, plus two more found while verifying the fixes in a real PTY.
Why the grants did nothing
Shell commands are not governance-gated —
default_hitl_tools()is just["mcp:*"]. Their prompts come fromToolError::SandboxDeniedinfinish_tool_application, which never consulted the operator's allow rules at all. "Always allow" wrote a line topermissions.tomlthat nothing on the re-prompt path ever read. The grant and the gate were different mechanisms.Fixes
1. Sandbox denials honour existing grants (
session/tools.rs)finish_tool_applicationnow asksGovernance::grant_coversand re-runs unconfined when a rule already covers the call — the same consent the prompt would collect. Denied hosts are excluded: a command-shaped rule must not silently open a network destination.2. Suggested patterns match the calls they came from (
governance/pattern.rs)suggest_patternbuilt its rule from the raw command whilematchestested the normalized permission subject. 5 of 8 realistic commands produced a grant that could not match its own call:It now derives the prefix from the same normalized subject, and returns
Nonefor a command with unquoted control syntax — which has no matchable rule by design, sincematchesrefuses to letcargo test; rm -rf /inherit acargo test *grant.pattern_allow_eligiblerequires a suggestion, so those calls no longer offer a "remember this" row that writes a grant which can never fire. The rustdoc invariant onsuggest_patternclaimed this property and was false; it is now true and asserted.3. Denying a network prompt is a denial (
app/approvals.rs) — securityapply_hitl_decisionbranched ondenied_hostbefore it readdecision, so "Don't run" and Esc granted the host for the session and ran the command, while the status line said "Action denied". Refusal is now settled first, failing closed on any non-approval.4. A git approval no longer grants every git call (
governance/pattern.rs) — securitysuggest_patternhad no case for the structuredgittool, so it fell back to the bare tool name. Approvinggit reset --hard HEAD~1for the session also permittedgit clean -fd. Nowgit(reset --hard *), with the row's help line narrowed to match. This also makes hand-writtengit(push *)rules work, which previously matched nothing.5.
retain_session_patterns_fromis wired (session/create.rs)It was dead code.
set_governancenow calls it, so a policy reload cannot silently revoke grants made at a prompt.Found by PTY verification, not by tests
6.
denybeatsallowin the new gate. The auto-approve check asked only whether an allow rule matched, letting a personalallow = ["bash(cargo test *)"]override a workspacedeny = ["bash"]. Driving the real TUI showed "Action approved" on a command the deny rule existed to gate.grant_coversnow checks deny first, mirroringauthorize's own ordering. Every unit test had used allow-only or deny-only policies, so none caught it.7. The unconfined retry was unbounded. The rule authorising the first retry authorises the next, so a tool reporting a denial even unconfined would re-run forever.
TurnState::claim_auto_unconfined_retrycaps it at one retry per call per turn.Verification
18 new tests.
cargo fmt --check,cargo clippy --all-targets,cargo test --workspace(46/46 binaries) all green.Driven in tmux (120x40) against the release binary, real model and egress proxy:
cargo test --workspaceunderdeny=["bash"]+ personalallowbash(cargo test *)for session and alwayscargo test --workspace | head -5git status --shortgit(status --short), not baregitcurl https://example.compromptskipped · denied; command did not run; permissions file untouched; re-asking prompts again**.example.comfor the session, then hitwww.example.comhttps://claude.ai/code/session_01QxjMZfzyjBuq3m25CWkzXu