OpenHands / OpenHands/software-agent-sdk

[Bug]: Python glob fallback mutates the process-wide working directory

Open
#4,663 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority:medium ready-for-dev tools
Dominant language
Python
Stars
1.1k
Forks
542
Avg merge
1d 19h
Merged PRs (30d)
137

Description

Bug Description

The Python fallback in openhands-tools/openhands/tools/glob/impl.py:185-231 implements relative matching by calling os.chdir(search_path) and restoring it afterward.

cwd is process-global, so concurrent executor use can race with unrelated threads or any code using relative paths. The tool consequently declares the fallback unsafe for parallel execution and forces tool-wide serialization (glob/definition.py:68-82). Direct executor callers are still exposed to the race.

Expected Behavior

Glob searches should be independent of process-global state and safe to run concurrently regardless of whether ripgrep is installed.

Actual Behavior

An independent, self-contained reproducer is posted in the issue comments. Save
it as /tmp/repro_4663.py, then run:

uv run python /tmp/repro_4663.py

On SDK commit bc5dfc50d, it exercises the real Python glob fallback over 20,000 files; a process signal samples CWD without replacing or delaying glob and prints:

fallback_selected=True
process_cwd_changed=True
process_cwd_restored=True
result_count=100
Suggested Implementation

Use Python's supported glob(..., root_dir=search_path, recursive=True) and join returned relative paths to search_path without resolving symlinks. Both backends can then declare no exclusive resource.

Acceptance Criteria
  • Forced-fallback searches across two roots can run concurrently.
  • Process cwd never changes during fallback execution.
  • Ripgrep/fallback parity remains for **, hidden paths, absolute patterns, symlinks, modification-time ordering, and truncation.
  • Tool action/observation schemas remain unchanged.
Version

Current main at 6d3881035. Existing issue search found no duplicate.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python fallback in openhands-tools/openhands/tools/glob/impl.py:185-231 and the serialization logic in glob/definition.py:68-82. Run /tmp/repro_4663.py with uv run python to observe the process-wide CWD change. Done means concurrent forced-fallback searches leave CWD unchanged while preserving backend parity and existing schemas.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.