GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [BUG]: auto formatting causes `apply_patch` verification to fail · Issue #31422 · anomalyco/opencode

[BUG]: auto formatting causes apply_patch verification to fail #31422

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
[BUG]: auto formatting causes apply_patch verification to fail#31422
Copy link
Assignees
rekram1-node

Description

@hesprs
hesprs
opened on Jun 8, 2026
Issue body actions

Description

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:

  1. Create aaa.ts, indent with spaces, with content:
export default function eat() {
    console.log('eat');
}
  1. Tell the model:
Patch file `aaa.ts`:
1. change `console.log('eat')` to `eaten`
2. change back
  1. Model reads the file, and respects the original indentation, uses space.

  2. Auto formatting triggers and formats it to tab. The model doesn't know.

  3. 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.

Screenshot and/or share link

Image

Operating System

NixOS 26.11

Terminal

Ghostty

Activity

  1. hesprs
    changed the title [-][BUG]: formatter causes `apply_patch` verification to fail[/-] [+][BUG]: auto formatting causes `apply_patch` verification to fail[/+] on Jun 8, 2026
  2. github-actions
    assigned
    rekram1-node
    on Jun 8, 2026
  3. rekram1-node commented on Jun 8, 2026

    @rekram1-node
    rekram1-node
    on Jun 8, 2026
    Member
    More actions

    auto formatting is off by default already.

  4. rekram1-node
    closed this as not plannedon Jun 8, 2026
  5. hesprs commented on Jun 9, 2026

    @hesprs
    hesprs
    on Jun 9, 2026
    Author
    More actions

    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:

    1. model applies a patch
    2. formatter formats the file
    3. formatter also formats the corresponding file in the model's context.

    Or even better:

    1. Establish a dedicated files section in model context partitioning.
    2. When model reads a file, instead of adding raw text to the context, we add the file path to the "tracked files" list.
    3. 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.

  6. ricatix commented on Sep 17, 2026

    @ricatix
    ricatix
    on Sep 17, 2026
    More actions

    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):

    Condition Accepted Rejected
    patch 1 → patch 2, no formatter 10 0
    patch 1 → Biome → identical patch 2 with pre-format context 0 10
    patch 1 → Biome → re-read → regenerated patch 2 10 0

    The patch-2 payload was byte-identical between the first two conditions. Biome 2.4.8 changed:

    const config={enabled:true,count:3};

    to:

    const config = { 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?

    1. Return the post-format file content/diff in the successful edit tool result so the model sees the canonical state.
    2. Mark the edited file/context stale after formatting and require/trigger a fresh read before another edit against that file.
    3. 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.

  7. hesprs commented on Sep 17, 2026

    @hesprs
    hesprs
    on Sep 17, 2026
    Author
    More actions

    True, my previous formatting the model's context suggestion is terrible. It destroys KV cache catastrophically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @rekram1-node
    rekram1-node

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.