anomalyco / anomalyco/opencode

glob tool reports truncation when the match count is exactly the limit

Open
#45,186 0 comments 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Aug 26, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

The glob tool reports its results as truncated whenever the match count lands exactly on the limit, even though nothing was dropped.

packages/opencode/src/tool/glob.ts:

const limit = 100
const files = yield* ripgrep.glob({ cwd: search, pattern: params.pattern, limit })
const truncated = files.length === limit

ripgrep.glob never returns more than limit items, so files.length === limit cannot distinguish "there were exactly 100 files" from "there were more than 100 and we cut it". A directory with precisely 100 matches gets:

(Results are truncated: showing first 100 results. Consider using a more specific path or pattern.)

which is false, and pushes the model into re-running a narrower search for results that do not exist.

What makes this avoidable is that the correct answer is already computed and then discarded. run() in packages/core/src/ripgrep.ts deliberately over-fetches by one to get an exact signal:

Stream.take(input.limit + 1),
...
const truncated = rows.length > input.limit
if (truncated) return { items: rows.slice(0, input.limit), truncated, partial: false }

but every method on the service maps that away before returning:

glob: (input) => run<string>({ … }).pipe(
  Effect.map((result) => result.items.map(…)),   // result.truncated dropped
)

Interface exposes readonly glob: (input: GlobInput) => Effect.Effect<readonly Entry[], Error>, so callers have no way to see it and re-derive it with the === limit heuristic instead.

packages/opencode/src/tool/grep.ts:75-79 has the same heuristic.

Two ways to fix it: widen the Ripgrep.Interface return type so the flag that run() already computes reaches callers, or have the callers request limit + 1 and slice locally. The second is contained to the tool and does not disturb the other glob/grep/find consumers.

Steps to reproduce
  1. Pick a directory where a glob pattern matches exactly 100 files.
  2. Run the glob tool with that pattern.
  3. The output claims the results were truncated.
Operating System

Windows 11 (platform independent)

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.