Skip to content

edit_block silently truncates file to pre-edit byte length when replacement grows the file #554

Description

@Haseeb-1698

Version: 0.2.43 (DXT, Claude Desktop) · OS: Windows 10/11 x64 · Node: 24.17.0 (Electron 42.5.1) · Client: local-agent-mode "Desktop Commander"

Summary

On a large text file (~148 KB, ~1,070 lines, UTF-8/ASCII, .tex), every edit_block call whose
new_string is longer than old_string writes a file whose byte length is EXACTLY the pre-edit
length. The replacement itself is applied correctly, but the file's tail is cut by exactly the
number of net bytes added. No error is returned; the call reports success.

Reproduced twice (byte-exact)

  1. File 147,308 bytes → 6 edit_block calls, net +4,684 bytes → file still 147,308 bytes,
    last 4,684 bytes gone (file ends mid-word, \end{document} lost).
  2. Same file later at 151,992 bytes → 3 edit_block calls, net +1,391 bytes → still 151,992 bytes,
    last 1,391 bytes gone.

Losses accumulate across sequential edits; shrinking edits did not visibly corrupt anything,
suggesting the file length is being pinned to a stale pre-edit size on the write path
(e.g. a truncate/allocation based on old fs.stat size rather than the new content length).

Steps to reproduce

  1. Create a text file of ~150 KB with > 1,000 lines (some lines ~2–3 K chars); note byte size and last line.
  2. Call edit_block replacing a short unique string in the middle with a string ~2 KB longer.
  3. Compare: file byte size is unchanged from step 1, and the last ~2 KB of the file are missing.

Expected

File length grows by the net replacement delta; tail preserved.

Impact

Silent data loss/corruption on any growing edit to a large file. Tool stats showed 77/77
edit_block calls "successful" while the file lost its tail twice.

Notes

  • Replacement target being past line 1,000 still matched fine, so fileReadLineLimit (1000)
    does not gate matching; the bug appears to be write-side.
  • config: fileReadLineLimit=1000, fileWriteLineLimit=50 (defaults).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions