Skip to content

[BUG]: Edit error messages encourage guess-and-check loop without telling AI to re-read #30798

Closed

Description

Description

When the edit tool fails to find oldString, its error messages create a guess-and-check loop that never tells the AI to re-read the file.

V1 edit (packages/opencode/src/tool/edit.ts:706-710):

  • "Could not find oldString. It must match exactly, including whitespace, indentation, and line endings." — AI adjusts guess, retries, never reads.
  • "Found multiple matches. Provide more surrounding context to make the match unique." — AI guesses context, retries, never reads.

V2 core edit (packages/core/src/tool/edit.ts:162-165): Same pattern — "Provide more surrounding context or set replaceAll to true."

The AI can loop indefinitely by guessing, without ever calling Read. With replaceAll, a short common string matched multiple times can corrupt the file.

Focused follow-on to #30376 and #21850 — #21850 describes the symptom (infinite retry loop); this identifies the root cause (error messages that never tell AI to re-read). Different from enforcement gaps: error messages can be fixed independently.
Suggested fix: change the "not found" and "multiple matches" error messages to include "Use the Read tool to re-read the file first."

Steps to reproduce

  1. AI tries to edit a file it has never read
  2. Guesses oldString wrong → error says "must match exactly"
  3. Adjusts guess → still wrong → "provide more context"
  4. Repeats without ever calling Read

Activity

  1. github-actions commented on Jun 4, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If you believe these are distinct enough to remain separate, please clarify how this issue differs. Otherwise, consider adding context to the existing issue.

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