Skip to content

fix(tools): run ripgrep from the search path so directory globs match - #7053

Open
JefferyLiu6 wants to merge 4 commits into
OpenHands:mainfrom
JefferyLiu6:fix/glob-ripgrep-directory-patterns
Open

JefferyLiu6 wants to merge 4 commits into
OpenHands:mainfrom
JefferyLiu6:fix/glob-ripgrep-directory-patterns

Conversation

@JefferyLiu6

Copy link
Copy Markdown

HUMAN:

GlobExecutor._execute_with_ripgrep() now runs rg with cwd=search_path. Previously, ripgrep evaluated -g patterns containing / (like src/**/*.ts) against the process working directory rather than the target path, returning nothing whenever they differed.

Added a parametrized regression test in tests/tools/glob covering src/*.ts, src/**/*.ts, literal paths, custom path args, and verifying the caller's cwd stays untouched. Leaving the Python fallback's **/ prefix discrepancy for a separate issue.


AGENT:

Why

With the ripgrep backend, GlobTool returns "No files found" for any relative pattern that contains / (src/*.ts, src/**/*.ts, src/app.ts) whenever the process working directory is not the search path. ripgrep resolves a -g glob that contains / against its own working directory, and _execute_with_ripgrep() never set one. src/**/*.ts is the example in the tool description.

Summary

  • Run ripgrep with cwd=search_path in GlobExecutor._execute_with_ripgrep(). The command and the output parsing are unchanged.
  • Add a parametrized regression test that runs from a different working directory and covers src/*.ts, src/**/*.ts, a literal src/app.ts, and the path argument. It also asserts the process working directory is unchanged.

Issue Number

Fixes #7052

How to Test

uv run pytest tests/tools/glob -q

With ripgrep on PATH: 67 passed. Reverting only openhands-tools/openhands/tools/glob/impl.py while keeping the new test gives 4 failed, 63 passed, each failure being assert set() == {'src/app.ts', ...}. Without ripgrep the four new cases skip.

Verified on macOS (Apple Silicon) with ripgrep 15.2.0 and Python 3.13.5, and on Linux with ripgrep 14.1.0.

The underlying ripgrep behavior, without the SDK:

D=$(cd "$(mktemp -d)" && pwd -P); mkdir -p $D/src; touch $D/src/app.ts
rg --files $D -g 'src/*.ts'             # prints nothing
(cd $D && rg --files $D -g 'src/*.ts')  # prints $D/src/app.ts

Video/Screenshots

N/A. Before and after, from the reproducer in #7052:

before: ripgrep backend: []
after:  ripgrep backend: ['/private/var/folders/.../src/app.ts']

Design Doc

N/A.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

@enyst enyst mentioned this pull request Nov 22, 2026
1 of 5 tasks
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.

[Bug]: Glob tool finds nothing for patterns with a directory part (src/**/*.ts) unless the process runs in the search path

1 participant