Skip to content

fix(agent): fail closed when a blocking hook's payload, handler, matcher or filter fails - #175

Open
alexb-openrouter wants to merge 2 commits into
mainfrom
devin/1796054493-hook-errors-fail-closed
Open

alexb-openrouter wants to merge 2 commits into
mainfrom
devin/1796054493-hook-errors-fail-closed

Conversation

@alexb-openrouter

@alexb-openrouter alexb-openrouter commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#160 made blocking hook chains (PreToolUse → block, UserPromptSubmit → reject) fail closed when the emit signal aborts. Two fail-open paths remained outside strict mode:

  1. HooksManager.emit returned blocked: false when payload validation failed, so no guard ran but the tool still executed.
  2. A throwing handler, matcher or filter (and a handler result that fails the result schema) was logged and skipped, so a crashing deny guard read as allow.

Both are confirmed by new tests that fail on main (expected false to be true on blocked).

Change, for hooks with a blockField only:

payload invalid            -> { blocked: true, blockReason: 'Blocked: <hook> hook payload failed validation' }
handler throws / bad result -> stop chain, { blocked: true, blockReason: 'Blocked: <hook> hook handler <i> failed' }
matcher/filter throws      -> stop chain, { blocked: true, blockReason: 'Blocked: <hook> hook matcher/filter for handler <i> threw' }
chain aborted (from #160)  -> blockReason: 'Blocked: <hook> hook chain was aborted before every handler ran'
  • New optional EmitResult.blockReason. Error details are only logged, not put in the reason, so handler error text doesn't reach the model.
  • ModelResult uses blockReason as the fallback reason, so a failed PreToolUse gives the existing hook_blocked output and the tool does not run; a failed UserPromptSubmit throws with that reason.
  • Non-blocking hooks keep log-and-continue. throwOnHandlerError: true still re-throws.
  • One existing test (hooks-manager.test.ts) pinned blocked: false for an invalid PreToolUse payload; updated to the new behavior.
  • README error-policy section documents this; changeset added (patch).
@devin-ai-integration

devin-ai-integration Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

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

None yet

1 participant