Skip to content

fix: stop echoing full file contents back after write_file - #776

Merged
will-lamerton merged 2 commits into
Nano-Collective:mainfrom
MsfPablo:fix/write-file-echo
Aug 9, 2026
Merged

will-lamerton merged 2 commits into
Nano-Collective:mainfrom
MsfPablo:fix/write-file-echo

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #762. executeWriteFile read the file back after writing and appended every line, number-prefixed, to the tool result. That's pure duplication: the model just sent that exact content as the tool call arguments, so returning it again costs tokens (with an extra ~6 chars/line for the prefix) without adding information the model didn't already have. There's no cap, so it scales linearly with file size — the issue measured ~8,500 tokens on source/app/App.tsx (791 lines) in this repo — and since tool results stay in the conversation, that cost is re-sent on every subsequent agent step.

Kept the read-back itself (per the issue: it verifies the write succeeded, and its line/char/token counts already feed the existing confirmation message), just stopped appending the line-numbered content dump.

Test plan

  • pnpm run test:format, test:lint, test:types — all clean
  • pnpm run test:ava source/tools/file-ops/write-file.spec.tsx — 43 tests pass
  • Updated the three existing tests that asserted the echoed content:
    • write_file: create new file / write_file: overwrite existing file — dropped the 'File contents after write:' assertion
    • write_file: returns file contents after write → renamed to write_file: reports accurate stats without echoing content back, now asserts the line count is still accurate while the raw content and the 'File contents after write:' marker are absent

executeWriteFile read the file back after writing and returned every
line, number-prefixed, appended to the result. That's pure duplication
— the model just sent that exact content as the tool call arguments,
so paying for it again (with an extra ~6 chars/line for the prefix)
adds nothing, and since tool results stay in the conversation, the
cost is re-sent on every later step too. No cap, so it scales linearly
with file size (~8,500 tokens on a 791-line file in this repo).

Kept the read-back itself, since it verifies the write succeeded and
its line/char/token counts feed the existing confirmation message.
Just stopped appending the line-numbered content dump.

Updated the three existing tests that asserted the echoed content
(write-file.spec.tsx) to assert its absence instead, and repurposed
the read-back verification test to check the reported stats are
accurate rather than that content is echoed.

Fixes Nano-Collective#762

@akramcodez akramcodez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM great work @MsfPablo

@will-lamerton

Copy link
Copy Markdown
Member

Nice work @MsfPablo :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write_file echoes back the entire file the model just wrote

3 participants