Repository navigation
fix(tools): pass the ripgrep pattern with -e so it cannot be read as a flag - #6537
Conversation
…a flag The ripgrep backend put the search pattern straight into argv, so a pattern starting with "-" was parsed as options: "-foo" failed as "-f oo" and "--files" listed every file instead of searching. Passing it as the value of -e makes ripgrep always treat it as a pattern. Ports the pinned tests test_pattern_starting_with_dash (ripgrep case) and test_ripgrep_pattern_cannot_inject_flags from #6348 without their xfail markers.
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Review of PR #6537
Scope gate: In scope. The change touches openhands-tools/openhands/tools/grep/impl.py, which this repository owns (tool behavior). The linked issue #6348 is open, labeled bug, priority:medium, and ready-for-dev, and this PR addresses two of its pinned items ("ripgrep backend passes a leading-dash pattern as a CLI flag" and "ripgrep backend treats '--files' pattern as a flag and lists every file"). No product or architecture decision is needed.
Verification performed on head e3799602a40cefc51a9e85f89fc145c34863dbfd:
uv run pytest tests/tools/grep/test_grep_executor.py -k "dash or inject_flags"— both new tests pass (2 passed).uv run pytest tests/tools/grep— full suite passes (50 passed), with ripgrep 13.0.0 present on PATH so the ripgrep backend and both new tests really execute (no silent skipping).- Base-revision check: with
main'simpl.pychecked out, the same two tests fail (2 failed), confirming the tests genuinely pin the bug and the fix resolves it. - Regression probe through the real
GrepExecutorwith a temp fixture: the fix no longer regresses the earlier-eflag-injection class — patterns like"-i","--files-with-matches","-w"now return zero matches as literal text rather than being parsed as flags;"foo"andinclude="o*.txt"behave unchanged;"--files"correctly returnsdoc.txt.
Assessment: The fix is minimal and correct — adding -e before action.pattern makes ripgrep treat the pattern as text even when it starts with a dash, which is exactly what ripgrep documents for this case. The system-grep backend is intentionally left unchanged here, as noted in the PR description (#4984 covers that line), and grep parity between backends is out of this PR's scope. No material correctness, security, or compatibility findings.
CI: GitHub Actions checks for this head are green (test suites, pre-commit/check, OpenAPI, persisted settings, security, etc. all pass).
✅ APPROVED
Port from OpenHands/software-agent-sdk#6537 (salvage of #110715). `pytest.mark.linux_only` is not a registered marker, so the file errored at collection under --strict-markers; use platforms("linux"). Fold the option-shaped and alternation cases into one parametrized invariant and keep the zero-match probe invariant.
HUMAN:
Fixing another bug
AGENT:
Why
The ripgrep backend of the grep tool puts the search pattern straight into argv, so a pattern that starts with
-is parsed as options.pattern="-foo"fails as-f oo("No such file or directory"), andpattern="--files"makes ripgrep list every file under the search path instead of searching for that text.Summary
-e, which ripgrep documents for patterns that start with a dash. One argv token, no other behavior change.xfailmarkers.The system grep backend's command is left alone here; #4984 is already changing that line.
Issue Number
Part of #6348 (items: "ripgrep backend passes a leading-dash pattern as a CLI flag" and "ripgrep backend treats '--files' pattern as a flag and lists every file").
How to Test
Both tests fail on
mainand pass here. ripgrep 15.1.0 directly, on a directory withflags.txt(contains-foo),other.txt, anddoc.txt(contains--files):uv run pytest tests/tools/greppasses (50) and pre-commit is clean on the changed files.🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:e379960-pythonRun
All tags pushed for this build
About Multi-Architecture Support
e379960-python) is a multi-arch manifest supporting both amd64 and arm64e379960-python-amd64) are also available if needed