Timeout middleware: per-tool deadline (kills a hung bash)#5
Merged
Conversation
TimeoutMiddleware runs the tool in a child coroutine and awaits it with Async\timeout(); on the deadline it cancels the coroutine (TrueAsync propagates the cancellation into a running bash subprocess and kills it) and returns an error result. Sits innermost, so a slow tool is capped but the user's approval prompt is not. Session adds an optional toolTimeoutMs (0 = off, so existing tests are unaffected); bin/claw wires it from CLAW_TURN_TIMEOUT_MS. 90 tests, PHPStan level 8, php-cs-fixer — all green.
The static-analysis job runs PHPStan without the true_async extension, so the ide-helper stub for Async\OperationCanceledException has no Throwable parent and 'catch (OperationCanceledException)' tripped catch.notThrowable. Catch \Throwable and compare $e::class instead (rethrowing anything that isn't the cancellation) — env-independent and also stops a genuine tool error being masked as a timeout.
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.
What
Adds
TimeoutMiddlewareto the executor chain — the second slice of the executor arc (after Permission + Audit in #4).Async\timeout().bashsubprocess and kills it — and returns an errortool_result(timed out after Ns).Sessiongains an optionaltoolTimeoutMs(0= off, so existing tests are unaffected);bin/clawwires it fromCLAW_TURN_TIMEOUT_MS.Why
Closes a real gap now that the bot is remotely reachable: a trusted user approving a command that hangs (e.g.
sleep 999) would otherwise wedge that chat forever.Still deferred
/stop(user-initiated turn cancellation) — that needs a turn-loop restructure to watch input mid-turn, not just a middleware.Tests
tests/Exec/TimeoutMiddlewareTest.php— error result when the tool exceeds the deadline; pass-through when fast enough.90 tests pass, PHPStan level 8 clean, php-cs-fixer clean.