fix(grep): add a subprocess timeout to ripgrep#36
Open
T0mSIlver wants to merge 1 commit into
Open
Conversation
run_rg called subprocess.run with no timeout. The outer asyncio.wait_for(MAX_TOOLRUN_TIMEOUT) in ToolSet can't interrupt it because run_rg is a blocking synchronous call that holds the event loop, so a pathological regex over a large tree could hang indefinitely. Add a 10s subprocess timeout mirroring the Glob tool, and add tests for the timeout reminder and that a timeout is passed.
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.
Problem
run_rginvokedsubprocess.run(...)with notimeout. The intended 10s guard (asyncio.wait_for(..., MAX_TOOLRUN_TIMEOUT)inToolSet.call) cannot interrupt it:run_rgis a blocking synchronous call that holds the event loop, sowait_fornever gets a chance to fire. A pathological regex or huge tree could hang the agent indefinitely. The Glob tool already guards its subprocess with a 10s timeout — Grep did not.Fix
Wrap the
subprocess.runcall withtimeout=10and return a<system-reminder>onTimeoutExpired, mirroringglob.py. Addstests/test_grep_timeout.pyasserting the reminder is returned on timeout and that a positivetimeoutis passed to the subprocess.Paper reference — judgment call
The paper's tool schema does not mention subprocess timeouts. This is defensive hardening (and mirrors the existing Glob timeout), not a paper-specified value.