anomalyco / anomalyco/opencode

read: directory listing returns an empty page for out-of-range offset instead of erroring

Open
#45,928 1 comment 0 reactions 1 assignee View on GitHub

@kitlangton is already working on this.

Since Aug 28, 2026.

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

Description

Describe the bug

Directory listing in the read tool silently returns an empty page when offset exceeds the number of visible entries (visible.slice(offset - 1, ...) yields [] with truncated: false). Reading a text file with the same out-of-range offset fails with OffsetOutOfRangeError.

The model can't distinguish "this directory really has this few entries" from "offset went past the end", and a truncated page's next can point to a page that is necessarily empty.

Steps to reproduce

{ path: "src", offset: 100 } on a directory with 5 entries → 200 with { entries: [], truncated: false }; the same offset on a text file → Offset 100 is out of range.

Affected code

packages/core/src/tool/read-filesystem.ts — directory listing slice, vs. the text read path's offset validation.

Suggested fix

Fail with OffsetOutOfRangeError for out-of-range directory offsets, consistent with text reads.

Environment
  • opencode version: latest dev

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.