Skip to content

edit.ts: oldString not found error does not include file content, causing AI to guess blindly #30863

Description

Description

File: packages/core/src/tool/edit.ts:141,146-151

const source = decodeUtf8(yield* unableToEdit(fs.readFile(readable.canonical)))
// ...
if (replacements === 0) {
  return yield* new ToolFailure({
    message: "Could not find oldString in the file. It must match exactly...",
  })
}

source (L141) already holds the full file content, but the error at L146-151 discards it. AI gets "oldString not found" with no file-state information → must guess the correct text → wastes turns → hits MAX_STEPS.

Fix: Include a snippet of source.text in the error message.

OpenCode version

v1.16.0 (commit 3cf1cef)

Activity

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