Skip to content

fix(tools): pass the ripgrep pattern with -e so it cannot be read as a flag - #6537

Merged
VascoSch92 merged 2 commits into
mainfrom
vasco/ripgrep-dash-pattern
Nov 7, 2026
Merged

VascoSch92 merged 2 commits into
mainfrom
vasco/ripgrep-dash-pattern

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

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"), and pattern="--files" makes ripgrep list every file under the search path instead of searching for that text.

Summary

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

uv run pytest tests/tools/grep/test_grep_executor.py -k "dash or inject_flags"

Both tests fail on main and pass here. ripgrep 15.1.0 directly, on a directory with flags.txt (contains -foo), other.txt, and doc.txt (contains --files):

rg -l -i -foo DIR       -> rg: oo: No such file or directory (os error 2)
rg -l -i -e -foo DIR    -> flags.txt
rg -l -i --files DIR    -> other.txt flags.txt doc.txt
rg -l -i -e --files DIR -> doc.txt

uv run pytest tests/tools/grep passes (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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:e379960-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-e379960-python \
  ghcr.io/openhands/agent-server:e379960-python

All tags pushed for this build

ghcr.io/openhands/agent-server:e379960-golang-amd64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-golang-amd64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-golang-amd64
ghcr.io/openhands/agent-server:e379960-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:e379960-golang-arm64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-golang-arm64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-golang-arm64
ghcr.io/openhands/agent-server:e379960-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:e379960-java-amd64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-java-amd64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-java-amd64
ghcr.io/openhands/agent-server:e379960-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:e379960-java-arm64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-java-arm64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-java-arm64
ghcr.io/openhands/agent-server:e379960-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:e379960-python-amd64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python-amd64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python-amd64
ghcr.io/openhands/agent-server:e379960-python-node-runtime-amd64
ghcr.io/openhands/agent-server:e379960-python-arm64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python-arm64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python-arm64
ghcr.io/openhands/agent-server:e379960-python-node-runtime-arm64
ghcr.io/openhands/agent-server:e379960-python-minimal-amd64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python-minimal-amd64
ghcr.io/openhands/agent-server:e379960-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:e379960-python-minimal-arm64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python-minimal-arm64
ghcr.io/openhands/agent-server:e379960-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:e379960-python-slim-amd64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python-slim-amd64
ghcr.io/openhands/agent-server:e379960-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:e379960-python-slim-arm64
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python-slim-arm64
ghcr.io/openhands/agent-server:e379960-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:e379960-golang
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-golang
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-golang
ghcr.io/openhands/agent-server:e379960-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:e379960-java
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-java
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-java
ghcr.io/openhands/agent-server:e379960-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:e379960-python-minimal
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python-minimal
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python-minimal
ghcr.io/openhands/agent-server:e379960-python-node-runtime-minimal
ghcr.io/openhands/agent-server:e379960-python-slim
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python-slim
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python-slim
ghcr.io/openhands/agent-server:e379960-python-node-runtime-slim
ghcr.io/openhands/agent-server:e379960-python
ghcr.io/openhands/agent-server:e3799602a40cefc51a9e85f89fc145c34863dbfd-python
ghcr.io/openhands/agent-server:vasco-ripgrep-dash-pattern-python
ghcr.io/openhands/agent-server:e379960-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., e379960-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., e379960-python-amd64) are also available if needed

…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.
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-tools/openhands/tools/grep
   impl.py12810320%44–45, 47–50, 53–57, 65–69, 78, 80–83, 92–96, 98–101, 103–105, 107, 125–126, 129, 134–136, 140–141, 145, 154–157, 159–160, 162–165, 169–172, 181–189, 191, 196–197, 205, 210, 217, 230, 240–241, 243, 252–254, 256, 262, 270–271, 275, 277–279, 281, 290–296, 299, 301–306, 308
TOTAL539352061062% 

@VascoSch92
VascoSch92 marked this pull request as ready for review November 6, 2026 13:28

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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's impl.py checked 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 GrepExecutor with a temp fixture: the fix no longer regresses the earlier -e flag-injection class — patterns like "-i", "--files-with-matches", "-w" now return zero matches as literal text rather than being parsed as flags; "foo" and include="o*.txt" behave unchanged; "--files" correctly returns doc.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

@VascoSch92
VascoSch92 merged commit 2886d92 into main Nov 7, 2026
50 checks passed
@VascoSch92
VascoSch92 deleted the vasco/ripgrep-dash-pattern branch November 7, 2026 11:59
teknium1 pushed a commit to NousResearch/hermes-agent that referenced this pull request Nov 12, 2026
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.
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