Repository navigation
fix(agent): fail closed when a blocking hook chain is cancelled - #43
Merged
Merged
Conversation
A PreToolUse or UserPromptSubmit chain that stopped on cancel_event (an AsyncOutput async_timeout_ms expiring, or abort_inflight()) returned blocked=False, so a later deny guard was skipped and the tool ran. Report blocked=True when a hook with a block field stops early. Non-blocking hooks are unchanged. Also stop HooksManager.drain() from spinning forever when tracked tasks already finished before their cleanup callbacks could run.
Contributor
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
alexb-openrouter
marked this pull request as ready for review
November 30, 2026 17:03
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
execute_handler_chainstops whencontext.cancel_eventis set. That happens when anAsyncOutputhandler'sasync_timeout_msexpires (the manager'son_async_timeoutsets the event) or whenabort_inflight()is called. The chain then returnedblocked=False. The executor reads that as approval, so a later deny guard that never ran was skipped and the tool executed.UserPromptSubmithad the same problem withreject.This ports the upstream
@openrouter/agentfix (hooks-emit.ts):Hooks without a block field are unchanged. The executor's fallback reason is used (
"Blocked by PreToolUse hook"/"Prompt rejected by hook").HooksManager.drain()also changed. When a tracked task was already done,await asyncio.gather(...)returned without yielding to the event loop. The scheduled_cleanupcallbacks could not run, sodrain()looped forever at 100% CPU. This is exactly what happens when a detached timeout fires during the chain:call_modelhung in teardown.drain()now removes the tasks it awaited.Tests
tests/unit/test_hooks_abort_fail_closed.py:call_model: the guard and the tool do not run, and the model gets the block output. Onmain,call_modelhangs indrain(). With only the chain fix, the tool would run.abort_inflight()mid-chain reportsPreToolUseas blocked.UserPromptSubmitchain cut short by a timeout reports blocked.PostToolUsechain staysblocked=False.drain()returns after the timed-out detached work.The new emit-level tests fail on
main(blocked=False). The full unit suite, ruff and mypy pass.