fix(ingest): bind an inferred approval to the action that was approved#19
Merged
Conversation
The matcher compared tool names only. It even unpacked the executed call's input_hash and then never used it, so an approval for `Bash(rm -rf /tmp/x)` was silently consumed by a later `Bash(ls)`, and the trail asserted a human had approved an action they never saw. For a tool whose whole claim is "what the human approved", that is the wrong thing to be wrong about. Match on the most specific identity both sides carry, the same precedence rule_approval_denied_then_executed already uses for denials: when both know the argument hash they must agree, otherwise fall back to the tool name for pre-hash adapters. An approval recorded with no tool name still matches anything, as before. A mismatch now leaves the approval pending, so it resolves as inferred:session_ended_pending (denied) at session end rather than vanishing. The trail therefore shows both halves of the gap: an approval that was never satisfied, and a successful call that carries no approval. That is the proposed-versus-executed diff, recorded honestly, and it lets autonomous-unapproved-write fire on the call that actually ran. Tests cover exact-hash bind, mismatch on the same tool, name fallback when a hash is absent, cross-tool isolation, and finding the right approval past a queued mismatched one. Verified they fail against the old matcher. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The bug
infer_approval_payloadsmatched a pending approval to an executed call by tool name only. It even unpacked the executed hash and then discarded it:So an approval for
Bash(rm -rf /tmp/x)was silently consumed by a laterBash(ls), and the trail then asserted a human had approved an action they never saw. For a tool whose central claim is recording what the human approved, that is the wrong thing to be wrong about.This is the "diff between what the agent proposed and what actually ran" gap raised in the r/ClaudeAI feedback. The denial path already bound by hash (
rules.py:350-374); the approval path did not.The fix
Match on the most specific identity both sides carry, mirroring the precedence
rule_approval_denied_then_executedalready uses:input_hash, they must be equalAn approval recorded with no tool name still matches anything, as before.
What a mismatch now produces
The approval is not consumed, so it stays pending and resolves as
inferred:session_ended_pending(denied) at session end. The trail then shows both halves of the gap:input_hashThat is the proposed-versus-executed diff recorded honestly, and it means
autonomous-unapproved-writecan fire on the call that actually ran instead of being masked by a bogus approval.Tests
Five cases in
test_external_ingest.py: exact-hash bind, mismatch on the same tool, name fallback when a hash is absent, cross-tool isolation, and finding the correct approval past a queued mismatched one.Verified they catch the regression: restoring the old name-only matcher fails exactly the two tests that pin the new behaviour, while the other twelve still pass (so existing semantics are preserved).
319 passed, ruff clean.