Skip to content

fix(hooks): isolate each PostToolUse side effect so one failure can't cancel enforcement - #209

Merged
CryptoJones merged 1 commit into
mainfrom
fix/posttooluse-side-effect-isolation
Aug 2, 2026
Merged

fix(hooks): isolate each PostToolUse side effect so one failure can't cancel enforcement#209
CryptoJones merged 1 commit into
mainfrom
fix/posttooluse-side-effect-isolation

Conversation

@CryptoJones

Copy link
Copy Markdown
Owner

Closes #204. First PR of the v7.0.0 batch (see Versioning below).

The defect

hooks.run_hook's PostToolUse branch ran four independent subsystems in sequence inside one try/except:

loopguard.reset(...)                    # spin counter
ai_usage.record_mcp_response(...)       # token accounting
compliance.record_post_tool(event)      # Layer E: the violation detector
verify.verify_consult(event, omi_dir)   # Layer C: consult relevance

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.md invariant 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.log can now distinguish "it ran and failed" from "it never ran", which is precisely the distinction whose absence made this invisible.

The Stop branch had the same shape and is isolated too — there, an unparseable transcript meant loopguard.register_block was 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_guard

Versioning

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

… 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 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@CryptoJones, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 328bb897-99c9-4fc9-8927-0c24f455ecb2

📥 Commits

Reviewing files that changed from the base of the PR and between 32d2c9e and ba3c745.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • BACKLOG.md
  • CHANGELOG.md
  • pyproject.toml
  • src/omind/__init__.py
  • src/omind/hooks.py
  • tests/test_hooks.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CryptoJones
CryptoJones merged commit 2338ef5 into main Aug 2, 2026
16 checks passed
@CryptoJones
CryptoJones deleted the fix/posttooluse-side-effect-isolation branch August 2, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hardening: one failing PostToolUse side effect silently cancels the rest (enforcement stops, exit code stays 0)

1 participant