Skip to content

read: small files bypass the default 2,000-line limit #60295

Closed

Description

@HeZ2z

Description

The Read tool's limit schema says it defaults to and is capped at 2,000 lines, but a file under 50 KiB bypasses the limit if limit and offset are omitted. Supplying limit: 2000 for the same file correctly truncates it. The default call can send more lines to the model than the advertised limit and provides no continuation hint.

Reproduction

From packages/core on dev commit 82666b6612cdb2ba13a7a26e150b21e897a80373:

bun -e 'import { Environment } from "@opencode/core/environment/index"; import { AbsolutePath } from "@opencode/core/schema"; import { ReadToolFileSystem } from "@opencode/core/tool/read-filesystem"; import { ReadTool } from "@opencode/core/tool/plugin/read"; import { CrossSpawnSpawner } from "@opencode/util/cross-spawn-spawner"; import { LayerNodePlatform } from "@opencode/util/effect/app-node-platform"; import { LayerNode } from "@opencode/util/effect/layer-node"; import { Effect } from "effect"; import { ChildProcessSpawner } from "effect/process"; const p="/tmp/opencode-many-lines.txt"; await Bun.write(p,"x\n".repeat(3000)); const run=Effect.gen(function*(){const spawner=yield* ChildProcessSpawner.ChildProcessSpawner; const files=Environment.makeFiles(Environment.makeLocalDriver(spawner)); for(const page of [{},{limit:2000}]){const result=yield* ReadToolFileSystem.read(files,AbsolutePath.make(p),"many.txt",page); const output=ReadTool.toModelContent("many.txt",undefined,result); console.log(JSON.stringify({page,type:result.type,header:output.split("\n")[0],truncated:result.truncated,tail:output.split("\n").at(-1)}));}}); await Effect.runPromise(run.pipe(Effect.provide(LayerNode.compile(LayerNode.group([CrossSpawnSpawner.node,LayerNodePlatform.filesystem])))));'

Actual:

{"page":{},"type":"file","header":"Read file many.txt, lines 1-3000","tail":"3000: x"}
{"page":{"limit":2000},"type":"text-page","header":"Read file many.txt, lines 1-2000","truncated":true,"tail":"[Output truncated. Continue reading with offset: 2001]"}

Expected: both calls honor the default 2,000-line limit and provide a continuation offset. The reproduction uses the real local filesystem driver and the real tool output formatter. read-filesystem.ts chooses the whole-file path based on file size and whether pagination arguments are supplied, without checking line count. The source matches the upstream dev blob.

Activity

  1. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    Thanks for the clear reproduction. I can confirm it: I ran your approach in packages/core with the local filesystem driver and the Read tool's formatter. On a 3,000-line file of about 6 KB, a call without offset/limit returns all 3,000 lines as a whole file result with no continuation hint. The same call with limit: 2000 stops at line 2,000 and says to continue from offset 2001. The script below reproduces it.

    This still happens on the latest dev (d3ad3da9). The relevant code is the same as at your commit: the whole-file shortcut in read-filesystem.ts checks only the 50 KiB size limit and whether pagination arguments were passed, not the 2,000-line limit.

    Reproduction script (repro.ts)
    // Run from /workspace/repo/packages/core: bun /workspace/repro/repro.ts
    import { Environment } from "@opencode/core/environment/index"
    import { AbsolutePath } from "@opencode/core/schema"
    import { ReadToolFileSystem } from "@opencode/core/tool/read-filesystem"
    import { ReadTool } from "@opencode/core/tool/plugin/read"
    import { CrossSpawnSpawner } from "@opencode/util/cross-spawn-spawner"
    import { LayerNodePlatform } from "@opencode/util/effect/app-node-platform"
    import { LayerNode } from "@opencode/util/effect/layer-node"
    import { Effect } from "effect"
    import { ChildProcessSpawner } from "effect/process"
    
    const p = "/tmp/opencode/many-lines.txt"
    await Bun.write(p, "x\n".repeat(3000)) // ~6 KB, well under the 50 KiB threshold
    const run = Effect.gen(function* () {
      const spawner = yield* ChildProcessSpawner.ChildProcessSpawner
      const files = Environment.makeFiles(Environment.makeLocalDriver(spawner))
      for (const page of [{}, { limit: 2000 }]) {
        const result = yield* ReadToolFileSystem.read(files, AbsolutePath.make(p), "many.txt", page)
        const output = ReadTool.toModelContent("many.txt", undefined, result)
        const lines = output.split("\n")
        console.log(JSON.stringify({ page, type: result.type, header: lines[0], outputLines: lines.length, tail: lines.at(-1) }))
      }
    })
    await Effect.runPromise(
      run.pipe(Effect.provide(LayerNode.compile(LayerNode.group([CrossSpawnSpawner.node, LayerNodePlatform.filesystem])))),
    )

    Run it: bun repro.ts

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions