Skip to content

read_file with offset beyond EOF reports "Note: File is empty" for non-empty files #1728

Closed

Description

@myk1yt

Summary

read_file with an offset beyond the end of a non-empty file returns "Note: File is empty" instead of an error. The model is told the file is empty and may regenerate/overwrite content from memory, destroying user data.

Mechanism

readWithSlice (src/integrations/misc/indentation-reader.ts:444-452) returns the error string Error: offset N is beyond file end (M lines) with returnedLines: 0, wasTruncated: false. In ReadFileTool.processTextFile (src/core/tools/ReadFileTool.ts:325-327), the else if (result.returnedLines === 0) branch discards that string and substitutes "Note: File is empty".

That branch is also dead code for its intended purpose: a genuinely empty file parses to one blank line ("".split("\n") === [""] → returnedLines: 1), so the branch can only ever fire for the out-of-range error.

Repro

  1. Create a 5-line file, let the model read it (so it has a stale line count).
  2. Shorten the file externally (or via edit), then the model calls read_file with offset: 100.
  3. Result: "Note: File is empty" — for a file with content.

Suggested fix

Gate the empty note on an actually-empty file: else if (result.returnedLines === 0 && result.totalLines === 0), letting the real beyond-EOF error propagate.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions