Skip to content

fix(agent): fail closed when a blocking hook chain is aborted - #160

Open
alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1794487918-pretooluse-fail-closed-on-abort
Open

alexb-openrouter wants to merge 1 commit into
mainfrom
devin/1794487918-pretooluse-fail-closed-on-abort

Conversation

@alexb-openrouter

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

Copy link
Copy Markdown
Contributor

Summary

Risk fixed: a PreToolUse deny guard could be silently skipped, and the tool ran anyway. If an earlier handler returned detached work ({ async: true, work, asyncTimeout }) and that work hit its timeout while a later handler was still running, the emit signal was aborted, executeHandlerChain stopped before the remaining handlers, and the emit returned blocked: false. The tool executor reads blocked: false as "allowed", so a guard that would have returned { block } never ran. abortInflight() mid-chain had the same effect.

Change: in executeHandlerChain, when the chain bails out on context.signal.aborted and the hook has a blockField (PreToolUse → block, UserPromptSubmit → reject), set blocked = true:

if (context.signal.aborted) {
  if (behavior?.blockField) blocked = true; // fail closed: unrun handlers may include the guard
  break;
}

The tool call then gets the existing hook_blocked result ("Blocked by PreToolUse hook"), and UserPromptSubmit throws "Prompt rejected by hook". Non-blocking hooks (PostToolUse, etc.) are unchanged: an aborted chain still just stops.

Tests: new cases in hooks-contract-fixes.test.ts. The detached-timeout-skips-guard case and the abortInflight()-mid-chain case both fail on main (blocked: false) and pass with this change. Controls check that a timeout that settles in time still runs every handler, and that non-blocking hooks are not marked blocked. Full unit suite, biome and typecheck pass.

Note: open PR #107 also touches hooks-emit.ts (handler return validation). These changes don't overlap, but one PR may need a small rebase after the other merges.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

devin-ai-integration Bot commented Nov 12, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant