fix(search): close stdin on search subprocesses to prevent hang in agent contexts#2871
Open
shareefhadid wants to merge 1 commit into
Open
fix(search): close stdin on search subprocesses to prevent hang in agent contexts#2871shareefhadid wants to merge 1 commit into
shareefhadid wants to merge 1 commit into
Conversation
…ent contexts `rtk rg` and `rtk grep` search subprocesses inherit stdin from the parent process. When RTK is invoked by an AI coding agent, the parent stdin is typically a long-lived IPC socket or pipe that never sends EOF. Because `rg` enters "read from stdin" mode when it receives no terminal stdin and the search module uses `Stdio::inherit()`, the subprocess blocks indefinitely on `read()`. This is the same class of bug fixed in rtk-ai#897 / PR rtk-ai#979 for `grep_cmd.rs`, but that fix was never applied to the `search.rs` path used by `rtk rg`. Change `exec_capture_stdin` from `Stdio::inherit()` to `Stdio::null()`. Search commands should never read from stdin — they always receive explicit file/directory paths via their argument list. Fixes rtk-ai#897 (for the rtk rg path). Related: rtk-ai#2301, PR rtk-ai#979. Co-authored-by: Cursor <cursoragent@cursor.com>
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
rtk rgandrtk grepsearch subprocesses inherit stdin from the parentprocess. When RTK is invoked by an AI coding agent (Cursor, Claude Code, etc.),
the parent stdin is typically a long-lived IPC socket or pipe that never sends
EOF. Because
rgenters "read from stdin" mode when it receives no terminalstdin and the search module uses
Stdio::inherit(), the subprocess blocksindefinitely on
read().This is the same class of bug fixed in #897 / PR #979 for
grep_cmd.rs, butthat fix was never applied to the
search.rspath used byrtk rg.Fix
Change
exec_capture_stdininsrc/core/stream.rsfromStdio::inherit()toStdio::null(). Search commands should never read from stdin — they alwaysreceive explicit file/directory paths via their argument list.
Test plan
rgsubprocess blocks inStdinLock::readwhen stdin is an open pipeStdio::null()Related
Stdio::null()fix forgrep_cmd.rs(merged, shipped in v0.35.0)rtk hook clauderewritesrg→rtk grep(BSD grep) instead ofrtk rg, so path-less ripgrep searches silently return 0 matches / hang on stdin #2301 —rtk hook clauderewrites causing hangs on path-less searchesMade with Cursor