Skip to content

apply_patch: parallel calls on the same file silently drop one change #53512

Description

@hooop

Description

When a model sends two apply_patch calls for the same file in one response, both calls can read the original file. Both report success, but the last write overwrites the first change.

I reproduced this with GPT-6.1 Sol and "permission": { "edit": "ask" }: both approval prompts showed the original file, I approved both, and only the second change was kept.

The edit tool already serializes same-file edits with a per-file lock (#23483), but apply_patch does not. Related but different: #31776 and PR #47956 concern a file changed outside OpenCode during approval.

Plugins

None

OpenCode version

1.18.34

Steps to reproduce

  1. Create settings.txt with:

    top = 0
    middle = keep
    bottom = 0
    
  2. Create opencode.json with:

    {
      "$schema": "https://opencode.ai/config.json",
      "permission": {
        "edit": "ask"
      }
    }
  3. Start OpenCode 1.18.34 and select GPT-6.1 Sol.

  4. Send this prompt:

    In settings.txt, change top = 0 to top = 1 and bottom = 0 to bottom = 2. Use two separate apply_patch calls, sent in parallel in the same response.
    
  5. Confirm that both apply_patch calls appear in the same assistant response and that both approval requests show the original file.

  6. Approve both requests.

Expected result

top = 1
middle = keep
bottom = 2

Actual result

Both calls report success, but the final file contains:

top = 0
middle = keep
bottom = 2

Screenshot and/or share link

No response

Operating System

macOS 26.3

Terminal

Terminal.app

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