Skip to content

edit tool: failed oldString match returns no context — models abandon the edit instead of retrying #42908

Closed as not planned

Description

@adaline-ankit

Problem

When every replacer strategy fails to match oldString, the edit tool throws:

"Could not find oldString in the file. It must match exactly, including whitespace, indentation, and line endings."

This error tells the model that it failed but shows it nothing to correct against. In practice (observed across SWE-bench runs with mid-tier models), the model's oldString is usually close-but-wrong — a reflowed comment line, drifted indentation — and after this error the model gives up after a single attempt: no re-read, no retry, a silent no-op on the task.

Concrete trace (SWE-bench django__django-10914): the model built an oldString whose comment wrapped onto different lines than the file; all replacer strategies missed; the model received the bare error and abandoned the edit — the session ended seconds later with no change made.

Proposal (two small changes)

  1. edit.ts — when no replacer matches, include the closest-matching region of the file (line-numbered) in the error, so the model can copy the real text verbatim into a corrected oldString:
Could not find oldString in the file. It must match exactly...
The closest matching region in the file is shown below with line numbers.
Re-read it, correct your oldString to match this text EXACTLY, and retry:
329: # The numeric mode to set newly-uploaded files to. ...
330: # you'd pass directly to os.chmod ...
331: FILE_UPLOAD_PERMISSIONS = None

The region finder is a simple trimmed-line window scorer (exact-line matches weighted over substantial partials, with a minimum-signal threshold so unrelated files produce no hint). No new dependencies.

  1. edit.txt (tool description) — tell the model the failure error includes the closest region, and to retry with corrected text rather than abandon after one failed edit.

Effect observed

A/B on the same tasks/model: a task where the model previously quit with an empty diff produced a real, on-target edit once the hint + retry guidance were in place (patch applied cleanly, zero regressions in the surrounding suite).

Patch

Fix + 3 unit tests (reproducing the near-miss above, asserting the hint fires, and asserting no false hint on unrelated content) are ready as a PR; all 27 existing edit tests pass unchanged.

Activity

  1. github-actions commented on Oct 16, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions