Skip to content

read_file metadata path skips markFileSeen, forcing an extra read before edits #761

Closed

Description

@will-lamerton

Resolution note, added 2026-08-09. Resolved via the first of the two options in the Fix section below, not the one the title implies. Commit 638a0ea9 clarified the read-before-edit refusal messages in diff_edit, string_replace and write_file so they state that files over 300 lines need a ranged read_file call. The metadata path at source/tools/read-file.tsx:160 still returns early without calling markFileSeen, and that is deliberate: marking a file seen when the model has only received metadata would defeat the guard and permit a blind edit. Do not "fix" that early return. The remaining round-trip cost is tracked in #760, which is the right place to remove it, by having reads return content in the first place.

Problem

source/tools/read-file.tsx:159 returns the metadata response for large files and exits early, without calling markFileSeen. That call only happens on the content path at source/tools/read-file.tsx:173.

The read-before-edit guard in source/utils/read-tracker.ts is therefore never satisfied by a metadata read. A model that calls read_file on a file over 300 lines, gets metadata, and then tries to edit will be refused and forced to read again.

This stacks an extra round-trip on top of the forced metadata round-trip that read_file already imposes on files over 300 lines.

Reproduction

  1. Call read_file on any file longer than 300 lines with no start_line/end_line.
  2. Attempt a string_replace on that file.
  3. The edit is refused for not having read the file, despite read_file having been called on it.

Fix

Judgement call on which way to resolve it:

  • If the metadata response is kept, it should not mark the file seen, because the model genuinely has not seen the contents and a blind edit is exactly what the tracker exists to prevent. In that case the fix is to make the refusal message explicit that a ranged read is required, so the model recovers in one step rather than guessing.
  • If the linked read_file change lands and reads always return content, this resolves itself, and the early return should mark seen for whatever content was returned.

Worth deciding alongside the parent issue rather than in isolation.

Notes for a first-time contributor

The relevant files are small and self-contained: source/utils/read-tracker.ts is 39 lines and well commented on the intent. Tests live in source/tools/read-file.spec.tsx.

Activity

  1. added
    bug
    good first issue
    on Aug 3, 2026
  2. will-lamerton commented on Aug 3, 2026

    @will-lamerton
    MemberAuthor

    Part of #772.

  3. AryanNandanwar commented on Aug 3, 2026

    @AryanNandanwar
    Contributor

    Hi Will, I'd like to work on this.

  4. DeepamJha commented on Aug 4, 2026

    @DeepamJha
    Contributor

    Hi @will-lamerton happy to help if this is still open, on the two options: I'd lean toward keeping the metadata response as-is and making the refusal message explicit about needing a ranged read, since marking "seen" on metadata-only would undercut what the tracker's for.

  5. added a commit that references this issue on Aug 9, 2026
  6. added a commit that references this issue on Aug 9, 2026
    638a0ea
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

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions