Skip to content

[feature] Detect file changes between read_file ranges #268

Closed

Description

@AetherAI3

Problem

#248 makes each read_file call bounded and honest about continuation. A multi-range caller can still assemble bytes from different versions of a file. The current executor stats the file around one read, but a same-size rewrite, append/truncate, or atomic replacement between calls can change content before the next offset read. A sequence of individually valid ranges could then be presented to a model or patcher as one coherent file.

Proposed contract

Return an opaque file-revision token with each successful read_file result, and allow the caller to send it as expected_revision on the next range. Reject a continuation whose opened file does not match that revision, with a distinct stale-file error and no apparently successful content. Keep offset/max_bytes and the bounded default from #248 compatible for callers that do not opt in. Thread the optional argument and returned token through the canonical tool registry, protocol, local executor, and hosted consumers. Document what the token guarantees and any filesystem limits.

Choose a bounded-cost revision check: for example, opened-handle identity plus size and high-resolution change metadata where reliable, or a stronger platform-specific mechanism. Do not read or hash the entire file on each ranged call. If a platform cannot establish the promised guarantee, expose that limitation or fail closed for guarded continuation instead of claiming snapshot consistency. Keep all checks on the opened handle so path replacement and symlink races do not bypass the workspace boundary.

This is distinct from #250's targeted patch-edit interface: it protects read-side assembly and gives later write preconditions a usable source revision.

Acceptance

  • A caller can read a file over several ranges using the returned revision, with complete/next_offset still accurate and memory bounded by the requested range.
  • An intervening same-size rewrite is detected before a subsequent guarded range can be reported as part of the prior version. Append, truncate, and atomic replacement paths are covered.
  • A stale revision produces a documented, non-success result. No partial bytes from a changed version are silently appended to an earlier read.
  • Empty files, final-line continuation, UTF-8 multibyte boundaries, binary rejection, read errors, and large/sparse files preserve the behavior guaranteed by [bug] File reads load entire files before truncating and report partial data as complete #248.
  • Unmodified callers retain the bounded default and can still consume the existing fields. New local and hosted callers can pass expected_revision through the canonical schema without divergent names or meanings.
  • Tests exercise the mutation cases on supported platforms and record any platform-specific revision limitations.

Priority: P2. Follow-up to #248; complements #250.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementspec

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions