Skip to content

read: blank-only text pages are reported as zero lines #60608

Closed

Description

@Arieg419

Description

A read page containing one blank line is reported to the model as 0 lines. Both an empty file and a selected blank line produce an empty content string, so the serializer cannot distinguish them. This also loses the line number when the page has a continuation offset.

Plugins

None; reproduced with the built-in read filesystem and tool tests.

OpenCode version

Current dev, 2.2.3 source at 8f0fc21e718e8e1ea60aee6ca04875c35cb7a876.

Steps to reproduce

  1. Create a text file with alpha\n\n.
  2. Read it with offset: 2, limit: 1.
  3. The model content says Read file lines.txt, 0 lines.

Expected: Read file lines.txt, lines 2-2 followed by 2: , preserving the selected blank line. A genuinely empty file should still report zero lines.

Four real temporary-file regression cases reproduce this before the fix: an initial blank page, a middle blank page, a final blank page, and a file containing just one newline. No model API calls are needed.

Operating System

macOS arm64, Bun 1.4.4.

Activity

  1. opencodejr commented on Oct 30, 2026

    @opencodejr
    Contributor

    Thanks for the clear report. I reproduced this on 2.2.3 and it still happens on the latest dev (65c0d83).

    The script below uses a simulated model that calls the built-in read tool, then prints the tool results returned to the model:

    • alpha\n\nbeta\n with offset: 2, limit: 1 → Read file middle.txt, 0 lines followed by [Output truncated. Continue reading with offset: 3]
    • alpha\n\n with offset: 2, limit: 1 → Read file lines.txt, 0 lines
    • a file containing just \n with offset: 1, limit: 1 → Read file newline.txt, 0 lines
    • a truly empty file → Read file empty.txt, 0 lines (correct)

    The cause looks like what you describe. The text page joins the selected lines into a single string, so one blank line becomes "", and the serializer treats "" as zero lines. The selected line and its number are dropped, even though the continuation hint still points past that line.

    Reproduction script (drive.ts)
    // Reproduces anomalyco/opencode#60608: a read page selecting one blank line is reported as "0 lines".
    import { Effect, Stream } from "effect"
    import { Llm, OpenCodeDriver } from "opencode-drive"
    
    const cases = [
      { id: "call_middle", file: "middle.txt", offset: 2 }, // "alpha\n\nbeta\n", line 2 is blank
      { id: "call_final", file: "lines.txt", offset: 2 }, // "alpha\n\n", line 2 is blank
      { id: "call_newline", file: "newline.txt", offset: 1 }, // "\n", line 1 is blank
      { id: "call_empty", file: "empty.txt", offset: undefined }, // "", genuinely empty
    ]
    
    export default OpenCodeDriver.use(
      {
        ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
        project: {
          files: {
            "middle.txt": "alpha\n\nbeta\n",
            "lines.txt": "alpha\n\n",
            "newline.txt": "\n",
            "empty.txt": "",
          },
        },
        tui: { recording: true },
      },
      ({ ui, llm }) =>
        Effect.gen(function* () {
          yield* llm.serve((request) => {
            const messages = (request as any).body.messages as Array<{ role: string; content: unknown; tool_call_id?: string }>
            const tools = messages.filter((m) => m.role === "tool")
            if (tools.length > 0) {
              // Print every read result the model receives.
              for (const m of tools) console.log(`RESULT ${m.tool_call_id}: ${JSON.stringify(m.content)}`)
              return Stream.make(Llm.text("done reading"))
            }
            if (JSON.stringify(messages).includes("Reply with only the title")) return Stream.make(Llm.text("Read files"))
            return Stream.make(
              ...cases.map((c, i) =>
                Llm.toolCall({
                  index: i,
                  id: c.id,
                  name: "read",
                  input: { path: c.file, ...(c.offset ? { offset: c.offset, limit: 1 } : {}) },
                }),
              ),
              Llm.finish("tool-calls"),
            )
          })
          yield* ui.submit("Read the files")
          yield* Effect.sleep("8 seconds")
          yield* ui.screenshot("after")
        }),
    )

    Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.

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