Skip to content

fix(grep): add a subprocess timeout to ripgrep#36

Open
T0mSIlver wants to merge 1 commit into
microsoft:mainfrom
T0mSIlver:fix/grep-subprocess-timeout
Open

fix(grep): add a subprocess timeout to ripgrep#36
T0mSIlver wants to merge 1 commit into
microsoft:mainfrom
T0mSIlver:fix/grep-subprocess-timeout

Conversation

@T0mSIlver

Copy link
Copy Markdown

Problem

run_rg invoked subprocess.run(...) with no timeout. The intended 10s guard (asyncio.wait_for(..., MAX_TOOLRUN_TIMEOUT) in ToolSet.call) cannot interrupt it: run_rg is a blocking synchronous call that holds the event loop, so wait_for never 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.run call with timeout=10 and return a <system-reminder> on TimeoutExpired, mirroring glob.py. Adds tests/test_grep_timeout.py asserting the reminder is returned on timeout and that a positive timeout is 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.

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.
@T0mSIlver T0mSIlver closed this Jun 27, 2026
@T0mSIlver T0mSIlver deleted the fix/grep-subprocess-timeout branch June 27, 2026 11:32
@T0mSIlver T0mSIlver restored the fix/grep-subprocess-timeout branch June 27, 2026 11:56
@T0mSIlver T0mSIlver reopened this Jun 27, 2026
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