Skip to content

fix(tools): expand brace patterns in the glob Python fallback - #6615

Merged
VascoSch92 merged 2 commits into
mainfrom
vasco/glob-fallback-braces
Nov 7, 2026
Merged

VascoSch92 merged 2 commits into
mainfrom
vasco/glob-fallback-braces

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

just fixing a bug


AGENT:

Why

The glob tool's description suggests patterns such as **/*.{json,yaml,yml,toml}. The ripgrep backend handles them (rg --files -g supports braces), but when ripgrep is not installed the tool falls back to Python's glob.glob, which has no brace expansion and treats {json,yaml} literally. The same call then returns "No files found" on machines without ripgrep.

Summary

  • Add a small _expand_braces that turns {a,b} groups into separate patterns: it splits the first group on its top-level commas and recurses, so several groups and nested groups ({a,b{c,d}} → a, bc, bd) expand like in bash; an unbalanced { is left as is. The fallback globs each one and merges the matches into a set, so overlapping alternatives don't produce duplicates. Patterns without braces go through unchanged.
  • Adds the pinned test from [Bug]: Edge-case tests expose ~70 bugs across the SDK, agent server, tools and workspaces #6348 for the Python backend, calling _execute_with_glob directly the way the existing ripgrep-path tests call _execute_with_ripgrep.

Issue Number

Part of #6348 (item: "Python glob fallback has no brace expansion, so '*.{json,yaml}' matches nothing").

How to Test

uv run pytest tests/tools/glob

test_python_fallback_expands_brace_patterns fails on main (no matches) and passes here; tests/tools/glob passes (63, including a test_expand_braces table for nested and unbalanced groups), including the backend consistency tests. _expand_braces("{a,b}/{c,d}") gives ['a/c', 'a/d', 'b/c', 'b/d'].

Type

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

🐳 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:7aca3c8-python

Run

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

All tags pushed for this build

ghcr.io/openhands/agent-server:7aca3c8-golang-amd64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-golang-amd64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-golang-amd64
ghcr.io/openhands/agent-server:7aca3c8-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:7aca3c8-golang-arm64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-golang-arm64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-golang-arm64
ghcr.io/openhands/agent-server:7aca3c8-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:7aca3c8-java-amd64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-java-amd64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-java-amd64
ghcr.io/openhands/agent-server:7aca3c8-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:7aca3c8-java-arm64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-java-arm64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-java-arm64
ghcr.io/openhands/agent-server:7aca3c8-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:7aca3c8-python-amd64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python-amd64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python-amd64
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime-amd64
ghcr.io/openhands/agent-server:7aca3c8-python-arm64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python-arm64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python-arm64
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime-arm64
ghcr.io/openhands/agent-server:7aca3c8-python-minimal-amd64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python-minimal-amd64
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:7aca3c8-python-minimal-arm64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python-minimal-arm64
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:7aca3c8-python-slim-amd64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python-slim-amd64
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:7aca3c8-python-slim-arm64
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python-slim-arm64
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:7aca3c8-golang
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-golang
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-golang
ghcr.io/openhands/agent-server:7aca3c8-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:7aca3c8-java
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-java
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-java
ghcr.io/openhands/agent-server:7aca3c8-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:7aca3c8-python-minimal
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python-minimal
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python-minimal
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime-minimal
ghcr.io/openhands/agent-server:7aca3c8-python-slim
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python-slim
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python-slim
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime-slim
ghcr.io/openhands/agent-server:7aca3c8-python
ghcr.io/openhands/agent-server:7aca3c8269c0689de2cbabaebf9cabbfb8ccc0a2-python
ghcr.io/openhands/agent-server:vasco-glob-fallback-braces-python
ghcr.io/openhands/agent-server:7aca3c8-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 7aca3c8-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., 7aca3c8-python-amd64) are also available if needed

The glob tool advertises patterns like "**/*.{json,yaml,yml,toml}", which
ripgrep's -g supports, but Python's glob has no brace expansion, so the
fallback used without ripgrep matched nothing. Expand {a,b} groups into
separate globs and merge the matches.
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-tools/openhands/tools/glob
   impl.py1139516%25–27, 30–40, 42–45, 67–70, 78, 93–94, 96–98, 100, 103, 107–108, 116–117, 119, 122–123, 128–129, 133–134, 139, 147, 149–151, 153–155, 157, 178, 181, 191, 201–203, 206–207, 209, 224, 227–229, 233, 236, 239, 247–251, 254–255, 257, 259, 261, 293–294, 297, 299, 303, 305, 308, 311–315, 317, 319–320, 322, 324–325, 327
TOTAL543912068162% 

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@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).

Scope — In-scope for this repository: a tool-behavior fix in openhands-tools, linked to #6348 ("Python glob fallback has no brace expansion, so '*.{json,yaml}' matches nothing"), which is open with labels bug, priority:medium, ready-for-dev. No product/architecture decision needed.

Verified on head 15f37788

  • The core fix works: _expand_braces("**/*.{json,yaml}") → ['**/*.json', '**/*.yaml']; {a,b}/{c,d} and {a,b}{c,d} expand correctly; the set merge dedupes overlapping alternatives before the existing mtime sort.
  • The new regression test fails on main and passes on this head. uv run pytest tests/tools/glob is green here (42 passed, 15 skipped — the backend-consistency tests skip where ripgrep isn't installed; they run in CI, where the author reports 57 passing).
  • The direct private-method test style matches the existing ripgrep-path tests in the same file. Brace-free patterns take the identical code path as before, and the pre-existing absolute-path/has_magic quirk with brace-only patterns is unchanged and not part of this diff.

Finding — One material issue, inline below: nested brace groups expand incorrectly even though the PR claims nested support ("including several, or nested"). That is the same fallback-vs-advertised-behavior mismatch class this PR fixes, so it affects the merge decision. Either make the group split nesting-aware or narrow the claim and behavior to top-level groups, with a pinned test for whichever contract is chosen.

CI — At review time the head's checks were mixed: tools-tests (the suite covering this change), pre-commit, integration-test, and cross-tests still pending; windows-tests, smoke-test, sdk-tests, agent-server-tests, and acp-live-tests passing. The focused suite was run in the workspace as reported above.

🔄 CHANGES REQUESTED

head, tail = pattern[: match.start()], pattern[match.end() :]
return [
expanded
for option in match.group(1).split(",")

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.

_expand_braces splits every group on all commas, ignoring nesting, so nested groups expand incorrectly. Verified by running the changed code on this head:

  • _expand_braces("{a,b{c,d}}") → ['a', 'bc', 'a', 'bd'] (bash gives a bc bd)
  • _expand_braces("{{a,b},{c,d}}") → ['a', 'c', 'a', 'd', 'b', 'c', 'b', 'd'] (bash gives a b c d)

Inner alternatives are dropped and cross-products appear as false match targets: with the fallback backend, **/{a,b{c,d}}.log matches a.log/bc.log and never ac.log/ad.log, so the tool reports wrong results for a pattern the PR claims to support. The regex \{([^{}]*)\} only finds the innermost group, and the split here cuts it at nested commas. Fix by finding the outermost group (depth-aware), splitting its top-level alternatives, and recursing per option as the sequential-group case already does — or narrow the PR to top-level groups only and document the limitation. No current test covers nesting, so please pin whichever contract is chosen.

The regex picked the innermost group and split it on every comma, so
{a,b{c,d}} expanded to a, bc, a, bd. Split the first group on its
top-level commas and let the recursion expand nested groups.

@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).

Scope — In-scope for this repository: tool-behavior fix in openhands-tools, linked to #6348 ("Python glob fallback has no brace expansion, so '*.{json,yaml}' matches nothing"), re-verified open with labels bug, priority:medium, ready-for-dev.

Nested-brace finding from the earlier review thread is addressed on this head. The regex-based innermost-group matching was replaced with a depth-aware parser that splits the first group on top-level commas and recurses per option. Verified by running the changed code on head 7aca3c82:

  • {a,b{c,d}} → ['a', 'bc', 'bd'] — matches bash; the previous head's wrong ['a', 'bc', 'a', 'bd'] is fixed
  • {{a,b},{c,d}} → ['a', 'b', 'c', 'd'] — matches bash; the previous head's duplicated cross-products are fixed
  • {a,b}{c,d} → ['ac', 'ad', 'bc', 'bd']; {a,b}/x{c,d} → ['a/xc', 'a/xd', 'b/xc', 'b/xd'] — correct cartesian expansion
  • {a,b, foo{bar → left as-is (unbalanced), matching bash; stray } before a group (x}y{a,b}) also matches bash

The new parametrized test_expand_braces table pins all of these, including both previously broken nested cases and the unbalanced case; it fails on main and on the previous head, so the fix is properly pinned. The removed import re has no remaining usages. Brace-free patterns take the identical code path as base, and the set merge still dedupes overlapping alternatives before the existing mtime sort.

Tests — uv run pytest tests/tools/glob is green on this head: 48 passed, 15 skipped (backend-consistency tests skip where ripgrep isn't installed locally; they run in CI).

CI — At review time the head's checks were mostly still pending (tools-tests, pre-commit, integration-test, cross-tests, windows-tests); sdk-tests, acp-live-tests, and agent-server-stress-tests pass. The focused suite covering the change was run in the workspace as reported above.

No material findings remain. The PR body's claims (nested groups expand like bash, unbalanced { left as is) now match observed behavior.

✅ APPROVED

@VascoSch92
VascoSch92 merged commit 18f6390 into main Nov 7, 2026
42 of 44 checks passed
@VascoSch92
VascoSch92 deleted the vasco/glob-fallback-braces branch November 7, 2026 22:46
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