Skip to content

[BUG]: Edit tool error messages create guess-and-check loop -- AI can succeed without ever reading the file #30781

Closed

Description

Description

When the V1 edit tool (packages/opencode/src/tool/edit.ts) fails to find oldString in the target file, its error messages create a guess-and-check loop that encourages the AI to keep trying without reading the file.

Error message 1: not found (line 706-709)

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

This error does NOT tell the AI to re-read the file. It only says "must match exactly" — which the AI can try to satisfy by tweaking whitespace, escaping, or indentation in its guessed oldString. The AI can loop through many attempts without ever calling Read.

Error message 2: multiple matches (line 710)

"Found multiple matches for oldString. Provide more surrounding context to make the match unique."

This error does NOT tell the AI to re-read the file either. It only says "provide more context" — which the AI can do by guessing what's around the match.

V2 core edit tool has the same issue

packages/core/src/tool/edit.ts lines 162-165:

"Found multiple exact matches for oldString. Provide more surrounding context or set replaceAll to true."

Same problem — no instruction to re-read the file.

Related: #30376 (broad read-before-edit failure), #21850 (hallucinated oldString retry loop — same symptom)

Plugins

N/A (source code analysis)

OpenCode version

main

Steps to reproduce

  1. Have the AI try to edit a file it has never read
  2. AI guesses oldString incorrectly
  3. Error says "must match exactly" or "provide more context"
  4. AI adjusts guess and retries without ever calling Read
  5. Repeat until success

Screenshot and/or share link

N/A (we read the source code)

Operating System

N/A (code analysis, not environment-specific)

Terminal

N/A

Activity

  1. github-actions commented on Jun 4, 2026

    @github-actions
    Contributor

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

    If this issue is specifically about the error message wording (not the missing runtime enforcement), it may still be distinct from the above. Please review those issues and consider whether this should be closed as a duplicate or linked as a follow-on.

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