Skip to content

string_replace returns the entire file after every edit, uncapped #763

Closed

Description

@will-lamerton

Problem

source/tools/file-ops/string-replace.tsx:83-89 appends the entire post-edit file, line-number prefixed, to the tool result:

const newLines = newContent.split('\n');
let fileContext = '\n\nUpdated file contents:\n';
for (let i = 0; i < newLines.length; i++) {
    const lineNumStr = String(i + 1).padStart(4, ' ');
    const line = newLines[i] || '';
    fileContext += `${lineNumStr}: ${line}\n`;
}

There is no cap. A three-line edit to a large file returns the whole file.

Impact

Measured on files in this repo, per edit:

  • source/app/App.tsx (791 lines): ~8,500 tokens
  • source/hooks/useAppState.tsx (447 lines): ~4,500 tokens
  • source/tools/tool-manager.ts (414 lines): ~3,650 tokens

Every edit, every time. Tool results persist in the conversation, so each edit's copy is re-sent on all subsequent steps of the agent loop. A task with several edits to a large file compounds badly.

Fix

Return a window around the edit rather than the whole file. The tool already computes startLine and newEndLine (source/tools/file-ops/string-replace.tsx:68-81), so the range is available.

Suggested: 20 lines either side of the changed range, with a marker showing it is a window. That preserves the genuinely useful part (letting the model confirm surrounding context survived the edit) while dropping the rest.

Open question worth discussing on the issue: whether even the window is needed, or whether the confirmation line alone is enough. string_replace already fails loudly on a non-unique or absent match, so the model has strong feedback without the echo.

Related

Same pattern as the write_file echo, but this one is less trivially removable, since unlike write_file the model did not author the full resulting file.

Activity

  1. added
    enhancement
    performance
    on Aug 3, 2026
  2. will-lamerton commented on Aug 3, 2026

    @will-lamerton
    MemberAuthor

    Part of #772.

  3. RealBhupesh commented on Aug 4, 2026

    @RealBhupesh
    Contributor

    Hi @will-lamerton, I’d like to take #763. I’ll replace the unbounded post-edit file echo with a bounded context window around the changed range, include a clear elision marker when surrounding content is omitted, and preserve the replacement/range summary and read-before-edit guard. I’ll add focused coverage for edits near the start, middle, and end of a file, including multiline size changes, then open a ready-for-review PR after validation.

  4. RealBhupesh commented on Aug 4, 2026

    @RealBhupesh
    Contributor

    Implemented in ready-for-review PR #784: #784

    The fix bounds successful string_replace output to a 20-line context window on each side of the edited range, includes omitted-range markers, and preserves line-number orientation for inline and multi-line edits. I added regression coverage for large files and file boundaries, plus a patch changeset.

    Validation passed: focused 42-test suite, formatting, lint, type-checking, unused-code analysis, and dependency audit. The full AVA suite still has one unrelated existing failure in source/app/components/settings-tabs.spec.tsx:109 where the test expects Display but the rendered output does not include it.

  5. added
    area:providers
    on Oct 7, 2026
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

    area:providersenhancementperformance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions