Skip to content

fix(search): close stdin on search subprocesses to prevent hang in agent contexts#2871

Open
shareefhadid wants to merge 1 commit into
rtk-ai:developfrom
shareefhadid:fix/search-stdin-hang
Open

fix(search): close stdin on search subprocesses to prevent hang in agent contexts#2871
shareefhadid wants to merge 1 commit into
rtk-ai:developfrom
shareefhadid:fix/search-stdin-hang

Conversation

@shareefhadid

Copy link
Copy Markdown

Summary

rtk rg and rtk grep search subprocesses inherit stdin from the parent
process. 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 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 #897 / PR #979 for grep_cmd.rs, but
that fix was never applied to the search.rs path used by rtk rg.

Fix

Change exec_capture_stdin in src/core/stream.rs from Stdio::inherit() to
Stdio::null(). Search commands should never read from stdin — they always
receive explicit file/directory paths via their argument list.

Test plan

  • Confirmed hang with current release: rg subprocess blocks in
    StdinLock::read when stdin is an open pipe
  • Confirmed fix: search completes immediately with Stdio::null()
  • Normal file search still returns correct results
  • Non-search fallback commands still inherit stdin
  • All existing search (76) and stream (51) tests pass

Related

Made with Cursor

…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>
@CLAassistant

CLAassistant commented Jul 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

2 participants