Repository navigation
Description
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
With the ripgrep backend, GlobTool returns "No files found" for any relative pattern that contains "/", such as src/*.ts, src/**/*.ts or src/app.ts, whenever the process working directory is not the search path.
GlobExecutor._execute_with_ripgrep() runs rg --files <search_path> -g <pattern> without setting cwd. ripgrep resolves a -g glob that contains "/" against its own working directory, not against the directory it is asked to search, so the glob never matches a file under <search_path>.
Patterns without "/" (*.ts) and patterns starting with **/ are unaffected. That is why the existing tests pass: none of them uses a pattern that starts with a directory.
src/**/*.ts is the example given in the tool description and in the GlobAction.pattern field description.
The agent-server Dockerfile sets WORKDIR / while the workspace is /workspace/project, so this may be the default situation there. I read that from the Dockerfile and have not run the image.
Expected Behavior
GlobAction(pattern="src/**/*.ts") returns the .ts files under <search_path>/src, whatever the process working directory is. The Python fallback already does this.
Actual Behavior
The observation is not an error. It reports "No files found matching pattern 'src/**/*.ts' in directory '<search_path>'", so the agent is told the files do not exist.
Steps to Reproduce
-
Install ripgrep (tested with 15.2.0) and clone the SDK at main (3a893a1).
-
In a shell, create a folder with one file and search it from a different directory:
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-
Do the same through the tool: save the minimal code sample below as repro.py and run
uv run python repro.pyfrom the repo root. -
The ripgrep backend returns an empty list; the Python fallback returns the file.
Acceptance Criteria
- With ripgrep available and the process running outside the search path,
src/*.ts,src/**/*.tsandsrc/app.tsreturn the matching files. - The same holds when the search path comes from the
pathargument. - The process working directory is unchanged after the call.
- Patterns without "/" behave as before, and existing glob tests pass unchanged.
- A regression test fails on current main and passes with the fix.
Installation Method
git clone + uv sync --dev
If you selected "Other", please specify
No response
SDK Version
1.63.1 (main at 3a893a1)
Version Confirmation
- I have confirmed this bug exists on the LATEST version of OpenHands SDK
Python Version
3.13.5
Model Name (if applicable)
No response
Operating System
MacOS
Logs and Error Messages
SDK v1.63.1 (main at 3a893a1b2), ripgrep 15.2.0, Python 3.13.5, macOS:
ripgrep backend: []
python fallback: ['/private/var/folders/.../src/app.ts']
Regression test (4 cases): 4 failed on main, 67 passed with the fix.
Each failure: AssertionError: assert set() == {'src/app.ts'}
Also reproduces on ripgrep 14.1.0 on Linux.
Minimal Code Sample
import os, tempfile
from pathlib import Path
from openhands.tools.glob import GlobAction
from openhands.tools.glob.impl import GlobExecutor
project = Path(tempfile.mkdtemp())
(project / "src").mkdir()
(project / "src" / "app.ts").write_text("x")
os.chdir(tempfile.mkdtemp()) # any directory other than `project`
executor = GlobExecutor(working_dir=str(project))
print("ripgrep backend:", executor(GlobAction(pattern="src/*.ts")).files)
executor._ripgrep_available = False
print("python fallback:", executor(GlobAction(pattern="src/*.ts")).files)Evidence and Additional Context
Proposed fix: pass cwd=search_path to the subprocess.run call in _execute_with_ripgrep. One line, with no change to the command or the output parsing.
Duplicate check: not covered by #6348 (its glob items are brace expansion and the 100-file truncation), #4663 / PR #4707 (Python fallback chdir), PR #6680 (grep include) or PR #5971 (workspace containment).
I have the fix and a regression test ready and would like to open a PR once this is marked ready-for-dev.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Reproduced as reported: with ripgrep 15.1.0 on Linux, running the exact command GlobTool builds (rg --files <search_path> -g <pattern>) from a directory other than the search path, src/*.ts and src/app.ts return nothing while *.ts and **/src/*.ts match — matching the issue's claim that a -g glob containing / is resolved against ripgrep's working directory, not its search path. _execute_with_ripgrep() in openhands-tools/openhands/tools/glob/impl.py calls subprocess.run without cwd, so every relative pattern containing / misses unless the process runs inside the search path; the Python fallback resolves correctly because it chdirs to the search path. The agent-server Dockerfile (lines 450/709) sets WORKDIR / with the workspace at /workspace/project, making this reachable by default in server deployments. Existing tests use only patterns without a leading directory part, so they do not catch it, and none of the referenced issues/PRs (#6348, #4663/#4707, #6680, #5971) covers this case. Scope is the ripgrep backend in GlobExecutor; the proposed cwd=search_path matches the fallback's existing behavior and is the authoritative mechanism for this repo.
Non-goals: no change to the command shape, output parsing, truncation, or observation format; no change to the Python fallback; no workspace containment or permission changes; no documentation rewrite beyond tests confirming tool-description examples work.
Actual Behavior
With ripgrep available and the process working directory outside the search path, GlobAction(pattern="src/**/*.ts") reports "No files found matching pattern 'src/**/*.ts' in directory '<search_path>'" — no error, telling the agent the files do not exist.
Steps to Reproduce
- With ripgrep installed, create a tree with a file under a subdirectory and run
rg --files <search_path> -g 'src/*.ts'from a different working directory: no output, while the same command inside the search path prints the file. - Or via the tool: create
<tmp>/src/app.ts, chdir the process elsewhere, then callGlobExecutor(working_dir=str(tmp))(GlobAction(pattern="src/*.ts"))— ripgrep backend returns an empty list, the Python fallback (with_ripgrep_available = False) returns the file.
Desired Behavior
GlobAction(pattern="src/**/*.ts") returns the .ts files under <search_path>/src whatever the process working directory is, matching the tool-description example and the Python fallback's existing behavior.
Acceptance Criteria
- With ripgrep available and the process working directory outside the search path,
GlobAction(pattern="src/*.ts"),pattern="src/**/*.ts"andpattern="src/app.ts"return the matching files under the executor'sworking_dir, matching what the Python fallback returns for the same tree. - The same three patterns also return the matching files when they are passed with an absolute search path in the
pathargument, with the process working directory outside it. - After a call,
os.getcwd()is unchanged, including when the ripgrep backend or fallback path returns an error or no matches (the fallback's chdir/restore is preserved). - Patterns without
/(e.g.*.ts),**/-prefixed patterns, brace-expanded patterns, absolute-pattern extraction, and the 100-file truncation behave as before, and the existing glob tests pass unchanged. - A regression test for a directory-prefixed pattern with the process outside the search path fails on current main and passes with the fix.
Activity