Skip to content

Search tools report malformed glob patterns as successful empty results #47474

Closed

Description

@sudoSwami

Description

Malformed glob syntax is reported as a successful empty search:

  • glob({ pattern: "[" }) returns No files found.
  • grep({ pattern: "needle", include: "[" }) returns No matches found.

Both return a completed tool result with empty output. Native ripgrep rejects the same patterns with exit code 2 and error parsing glob '[': unclosed character class; missing ']'.

Expected: report the parse failure so the caller can correct the pattern. Valid searches with no matches should still succeed.

The shared adapter in packages/core/src/ripgrep.ts accepts exit code 2 unless it recognizes a regex error; glob parse errors fall through. A fix should preserve legitimate partial results.

I can contribute a focused fix and regression tests if this is not already being addressed.

Plugins

Built-in glob and grep only, exercised through the core tool test harness.

OpenCode version

V2 source at 2960c61f9c5c86f23059d9da73e632951650edc7; Bun 1.4.2, ripgrep 15.2.0.

Steps to reproduce

  1. Create visible.ts containing needle in a temporary directory.
  2. Invoke the built-in glob tool with { "pattern": "[" }, or grep with { "pattern": "needle", "include": "[" }.
  3. Observe a completed tool result with empty output instead of a parse error.

Reproduced using the existing executeTool helper in packages/core/test/tool-search.test.ts with native ripgrep. Controls for a valid match, a valid empty search, and an invalid grep regex behave correctly.

Operating System

macOS arm64.

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I reproduced this on the latest dev (35a4a68), using the core search-tool test harness with native ripgrep:

    • glob with pattern: "[" returns a completed result: No files found.
    • grep with pattern: "needle", include: "[" returns a completed result: No matches found.
    • Native rg --glob '[' fails with error parsing glob '[': unclosed character class; missing ']' and exits with code 2.

    The controls behave correctly: a valid match, a valid empty search, and an invalid grep regex, which already comes back as an Invalid regex pattern error. In packages/core/src/ripgrep.ts, only regex parse errors are recognised on exit code 2, so glob parse errors end up as empty successes.

    The script below reproduces it. Related: #56518 is an open PR for this.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #47474 using packages/core's own search-tool test harness.
    # Usage: REPO=/path/to/opencode-checkout bash repro.sh   (after `bun install` in the checkout)
    set -euo pipefail
    REPO="${REPO:-/workspace/repo}"
    T="$REPO/packages/core/test/repro-47474.test.ts"
    # Reuse the harness (imports, withTools, call) from the existing search tool test.
    sed -n '1,/^describe("search tools"/p' "$REPO/packages/core/test/tool-search.test.ts" | sed '$d' > "$T"
    cat >> "$T" <<'TS'
    const show = (label: string, r: any) =>
      console.log(label, JSON.stringify({ status: r.status, output: r.output, error: r.error?.message, text: r.content?.[0]?.text }))
    
    describe("repro #47474", () => {
      it.live("malformed glob patterns", () =>
        Effect.acquireUseRelease(
          Effect.promise(() => tmpdir()),
          (tmp) =>
            Effect.gen(function* () {
              yield* Effect.promise(() => Bun.write(path.join(tmp.path, "visible.ts"), "needle\n"))
              yield* withTools(tmp.path, (registry) =>
                Effect.gen(function* () {
                  show("control glob '*.ts'           :", yield* executeTool(registry, call("glob", { pattern: "*.ts" })))
                  show("control glob '*.none'         :", yield* executeTool(registry, call("glob", { pattern: "*.none" })))
                  show("control grep regex '['        :", yield* executeTool(registry, call("grep", { pattern: "[" })))
                  const g = yield* executeTool(registry, call("glob", { pattern: "[" }))
                  const r = yield* executeTool(registry, call("grep", { pattern: "needle", include: "[" }))
                  show("BUG glob '['                  :", g)
                  show("BUG grep include '['          :", r)
                  expect(g.status).toBe("error")
                  expect(r.status).toBe("error")
                }),
              )
            }),
          (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
        ),
      )
    })
    TS
    echo "--- native ripgrep:"; (cd /tmp && rg --files --glob '[' . ; echo "rg exit $?") 2>&1 | tail -3 || true
    cd "$REPO/packages/core" && bun test test/repro-47474.test.ts || true
    rm -f "$T"

    Run it: bash repro.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions