Skip to content

Bug Model enters infinite loop due to hallucinated oldString in edit tool calls #21850

@stevensli

Description

@stevensli

Description

While using the edit tool to fix a simple syntax error in a Rust file, the model (gemma4-31b) entered a repetitive failure loop.
Steps to Reproduce:

  1. The model calls read to get the content of a file.
  2. The read tool returns the actual content (e.g., if guess << secret secret_number {).
  3. The model attempts to call edit, but instead of using the string returned by read, it hallucinates a different string for oldString (e.g., if guess <<< secret secret secret_number {).
  4. The edit tool correctly returns an error: "Could not find oldString in the file."
  5. The model ignores this error and repeats the exact same incorrect edit call multiple times (10+ times) without updating the oldString to match the actual file content.
    Expected Behavior:
    The model should prioritize the output of the read tool and, upon receiving a "not found" error from the edit tool, it should re-examine the file content and correct the oldString parameter.
    Actual Behavior:
    The model ignores the tool's error message and persists in using a hallucinated string, resulting in an infinite loop of failed tool calls.
    Environment:
  • Model: gemma4-31b (local-vllm/gemma4-31b)
  • Tool: edit

Plugins

No response

OpenCode version

1.3.14, 1.3.17, 1.4.0, 1.4.3

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions