Skip to content

fix(tools): isolate grep subprocess stdin - #1661

Merged
Tomas2D merged 1 commit into
i-am-bee:mainfrom
baba9811:codex/beeai-grep-stdin
Sep 17, 2026
Merged

Tomas2D merged 1 commit into
i-am-bee:mainfrom
baba9811:codex/beeai-grep-stdin

Conversation

@baba9811

Copy link
Copy Markdown
Contributor

Which issue(s) does this pull-request address?

Follow-up to #1660, implementing the stdin isolation suggested in this review.

GrepTool searches files and exposes no stdin input, but its ripgrep subprocess inherits the host's stdin. The input schema accepts root="-", which ripgrep interprets as stdin even after the option separator added in #1660. A public-API reproduction consumed the host's input; with that input stream held open, the tool waited for more data.

Description

Pass stdin=asyncio.subprocess.DEVNULL when starting ripgrep so it cannot consume or wait on the host's inherited stdin. Argument construction, result parsing and the Python fallback are unchanged.

Add a unit regression that runs the public GrepTool.run API with real ripgrep in a child Python process. The test supplies known input to that process and verifies it remains available after the tool completes.

Testing

  • The regression fails before the change because ripgrep consumes the supplied input, and passes afterward.
  • Full unit suite with Python 3.11 and the locked all-extras dependencies on Linux: 369 passed (pytest -m unit -n auto, four workers).
  • Filesystem suite: 20 passed. Also verified completion while the host input pipe remains open, ordinary and ./- directory searches, leading-hyphen patterns, case/glob options, result limits and the Python fallback.
  • Ruff check, Ruff format check, pyrefly, the repository license check and Poetry build passed.

Prevent ripgrep from consuming or waiting on the host input stream. Add a public-API regression with real ripgrep that verifies parent stdin remains available.

Follow-up to i-am-bee#1660.

Signed-off-by: baba9811 <bany981111@gmail.com>
@baba9811
baba9811 requested a review from a team as a code owner September 17, 2026 13:03
@github-actions github-actions Bot added the python Python related functionality label Sep 17, 2026

@Tomas2D Tomas2D left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes further than what I suggested, and the extra bit is the important part.

I framed the stall in #1660 as reachable through a crafted pattern, which the -- separator then closed. You found that it wasn't actually closed. root is also caller-controlled, the schema accepts root="-", and ripgrep treats a bare - as stdin after the separator as well. Confirmed against ripgrep 15.2.0:

$ echo "needle from stdin" | rg --json --line-number --max-count=50 -- "needle" -
"text":"needle from stdin\n"

So the option separator never addressed that path, and my review of #1660 was incomplete in implying it did. stdin=DEVNULL is the right fix precisely because it doesn't depend on argument parsing at all — it removes the capability rather than trying to block every route to it.

The regression test is the part I'd single out. Asserting "the tool didn't hang" is awkward and usually ends up as a timeout that passes vacuously. Running GrepTool.run inside a child Python process, feeding that process known stdin, and then asserting the input is still readable afterwards tests the actual property — that the subprocess didn't consume the parent's stream. It fails before the change and passes after, which is what makes it worth having. check=True plus timeout=30 also means a regression shows up as a failure rather than a hung suite.

Everything else checks out: the shutil.which("rg") guard matches the surrounding tests, @pytest.mark.unit means it runs under pytest -m unit, and the modified call is ~115 characters against ruff's line-length = 120. Argument construction, result parsing and the stdlib fallback are untouched.

One note for the record, not a change request: with DEVNULL in place, root="-" now returns no matches instead of stalling, which is a sane failure mode. Explicitly rejecting - in the input schema would be clearer still, but it's cosmetic now that the capability is gone.

CI green. Merging.

@Tomas2D
Tomas2D merged commit 50bb05b into i-am-bee:main Sep 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Python related functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants