anomalyco / anomalyco/opencode
`edit`: not-found error claims exact whitespace matching, but matching normalizes whitespace
@jlongster is already working on this.
Since Aug 25, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Summary
When oldString is not found, the tool reports:
Could not find oldString in the file. It must match exactly, including whitespace, indentation, and line endings.
This contract is false. Matching actually runs a fuzzy replacer chain that normalizes whitespace/indentation before concluding "not found". The error message and the real behavior contradict each other. This is independent of any opinion about whether fuzzy matching is desirable — the message simply misstates what the tool does.
Reproduction
File:
alpha
beta_line
gamma
oldString = " beta_line"(4 spaces, file has 3) → edit succeeds (whitespace normalized), so the "must match exactly" contract is already violated here.oldString = "nonexistent_text_xyz"→ rejected with the error text above, which claims exactness including whitespace — the same whitespace that was just normalized in case 1.
Minimal evidence: leading indentation (4sp vs 3sp), internal spacing (foo bar vs foo bar), and tab↔spaces all match via non-exact replacers (LineTrimmedReplacer / WhitespaceNormalizedReplacer in packages/opencode/src/tool/edit.ts).
Why it's a problem
Callers (models and automation) rely on the error text to decide how to correct oldString. Telling them matching is exact-when-it-isn't sends them down the wrong path (e.g. re-checking whitespace that the tool would have tolerated anyway), and misleads spec-driven tooling about when matching will fail.
Proposed fix
Rewrite the message to reflect reality:
throw new Error(
"Could not find oldString in the file. Exact match and all fuzzy fallbacks " +
"(whitespace/indentation/escape-tolerant) were attempted. Re-read the file and " +
"copy the exact text (whitespace included) into oldString."
)
Related
- Companion feature request: surface which match strategy (exact vs fuzzy) was used on success.
- Fuzzy-chain family: #41872, #32559, #31785, #42908.
Environment
- opencode: 1.18.21
- OS: Windows (win32)
- Tool: built-in
edit - Confirmed via controlled probes.
Plugins
No response
OpenCode version
1.18.21
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
Windows 10
Terminal
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.