You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG]: auto formatting causes apply_patch verification to fail #31422
Automatically triggered formatter after model edit is the culprit of most apply_patch failures.
Formatting can happen unexpectedly, for example, change indentation, sort imports, create newlines due to print width limit. Models don't know the formatting. They still patch the stale format next time, causing the patch verification it to fail.
Suggestion: turn auto formatting off by default and warn users about the risk of turning on.
Plugins
None
OpenCode version
1.15.13
Steps to reproduce
I did an experiment:
Create aaa.ts, indent with spaces, with content:
exportdefaultfunctioneat(){console.log('eat');}
Tell the model:
Patch file `aaa.ts`:
1. change `console.log('eat')` to `eaten`2. change back
Model reads the file, and respects the original indentation, uses space.
Auto formatting triggers and formats it to tab. The model doesn't know.
When next time it tries to edit, it still uses space indentation in the string to replace. Since real indentation drifts, the verification fails, as shown in the image. Model re-reads, re-patches, wastes tokens.
changed the title [-][BUG]: formatter causes `apply_patch` verification to fail[/-][+][BUG]: auto formatting causes `apply_patch` verification to fail[/+]on Jun 8, 2026
Sorry for ignorance, I remember formatting was on by default for a period in the past.
By the way, maybe when formatting enabled, OpenCode also needs to format the model's context? For example:
model applies a patch
formatter formats the file
formatter also formats the corresponding file in the model's context.
Or even better:
Establish a dedicated files section in model context partitioning.
When model reads a file, instead of adding raw text to the context, we add the file path to the "tracked files" list.
The content of files in the files section is automatically refreshed when real file changes.
This can ensure that whenever file changes, the model can always obtain the correct context. Otherwise, formatting / manual code edit midway the model's work would be catastrophic.
I reproduced this deterministically on OpenCode 1.18.31 with an enabled Biome formatter, using the upstream oh-my-opencode-slim 2.2.21 pre-native rewritePatch verifier.
Controlled A/B/C matrix (10 fresh fixture resets per condition):
The patch-2 payload was byte-identical between the first two conditions. Biome 2.4.8 changed:
constconfig={enabled:true,count:3};
to:
constconfig={enabled: true,count: 3};
The second condition then failed with verification_failed: Failed to find expected lines. Re-reading and regenerating against the actual post-format file restored acceptance in every run.
I agree that leaving formatting disabled by default avoids the default-path regression, but users who intentionally enable a formatter still get deterministic stale model context after a successful edit. Could this issue be reconsidered for one of these narrower fixes?
Return the post-format file content/diff in the successful edit tool result so the model sees the canonical state.
Mark the edited file/context stale after formatting and require/trigger a fresh read before another edit against that file.
At minimum, document or warn that enabling automatic formatting can invalidate subsequent patch context.
Automatically rewriting historical conversation context seems riskier than exposing the post-format state through the tool result. The experiment only establishes this formatter-induced stale-context path; it does not claim all apply_patch failures have this cause.
Activity
[-][BUG]: formatter causes `apply_patch` verification to fail[/-][+][BUG]: auto formatting causes `apply_patch` verification to fail[/+]rekram1-node commentedon Jun 8, 2026
auto formatting is off by default already.
hesprs commentedon Jun 9, 2026
Sorry for ignorance, I remember formatting was on by default for a period in the past.
By the way, maybe when formatting enabled, OpenCode also needs to format the model's context? For example:
Or even better:
This can ensure that whenever file changes, the model can always obtain the correct context. Otherwise, formatting / manual code edit midway the model's work would be catastrophic.
ricatix commentedon Sep 17, 2026
I reproduced this deterministically on OpenCode 1.18.31 with an enabled Biome formatter, using the upstream
oh-my-opencode-slim2.2.21 pre-nativerewritePatchverifier.Controlled A/B/C matrix (10 fresh fixture resets per condition):
The patch-2 payload was byte-identical between the first two conditions. Biome 2.4.8 changed:
to:
The second condition then failed with
verification_failed: Failed to find expected lines. Re-reading and regenerating against the actual post-format file restored acceptance in every run.I agree that leaving formatting disabled by default avoids the default-path regression, but users who intentionally enable a formatter still get deterministic stale model context after a successful edit. Could this issue be reconsidered for one of these narrower fixes?
Automatically rewriting historical conversation context seems riskier than exposing the post-format state through the tool result. The experiment only establishes this formatter-induced stale-context path; it does not claim all
apply_patchfailures have this cause.hesprs commentedon Sep 17, 2026
True, my previous formatting the model's context suggestion is terrible. It destroys KV cache catastrophically.