fix(hooks): isolate each PostToolUse side effect so one failure can't cancel enforcement - #209
Conversation
… cancel enforcement `run_hook` ran four independent subsystems inside a single try/except: the loop guard, token accounting, the Layer E violation detector, and the Layer C consult verifier. A failure in the first — accounting, the most fragile and least important of the four — silently skipped the detector and the verifier behind it. The hook still returned 0, by design, so nothing was visible: an enforcement path failing open, quietly, which is the property this codebase designs against everywhere else. Each now runs through `_best_effort`, which absorbs the failure and records a breadcrumb naming *which* one failed, so `hook-failures.log` distinguishes "it ran and failed" from "it never ran" — the distinction that made this invisible. The `Stop` branch had the same shape: an unparseable transcript meant `loopguard.register_block` was never consulted, so an armed autonomous loop would let the stop through. Isolated too. Version goes to 7.0.0: the remaining backlog items ship as one release rather than another run of point versions. Closes #204. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Warning Review limit reached
Next review available in: 50 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #204. First PR of the v7.0.0 batch (see Versioning below).
The defect
hooks.run_hook'sPostToolUsebranch ran four independent subsystems in sequence inside onetry/except:A failure in the first one skipped every later one. Token accounting — the most fragile of the four (it parses transcripts) and the least important — could silently disable the enforcement detector. The hook returned 0, as it must, so the only evidence was an unlabelled breadcrumb in
hook-failures.log.That is an enforcement path failing open, silently.
AGENTS.mdinvariant 2 makes fail-open a deliberate per-layer choice for retrieval; nobody chose it here.The fix
Each side effect runs through
_best_effort(label, call), which absorbs the failure and records a breadcrumb naming which one failed. That label is the part that matters:hook-failures.logcan now distinguish "it ran and failed" from "it never ran", which is precisely the distinction whose absence made this invisible.The
Stopbranch had the same shape and is isolated too — there, an unparseable transcript meantloopguard.register_blockwas never consulted, so an armed autonomous loop would let the stop through. That's a second, quieter instance of the same bug.Tests
The
KNOWN:test added with #189 asserted the broken behavior (seen == []) and pointed here. It now fails — which is what it was for — and is replaced by:test_one_failing_post_tool_use_side_effect_does_not_cancel_the_others— accounting raises; asserts the detector and verifier still ran, and that the breadcrumb names the failing subsystem.test_a_failing_stop_transcript_still_consults_the_loop_guardVersioning
Bumps to 7.0.0. The remaining backlog items land under this one version rather than continuing one release per item — seven tags in a day is accurate history but poor release notes. Subsequent PRs in this batch add to the same
## [7.0.0]changelog section; one GitHub release is cut when the batch closes.Gates
ruff check .·mypy src(strict) ·pytest(867 passed, 1 skipped) ·pip-audit— green locally.🤖 Generated with Claude Code