Skip to content

tool/edit: stale-content error mentions "permission approval" though any concurrent write triggers it #48707

Closed as not planned

Description

@m4niacjp

Summary

edit reports File changed after permission approval. Read it again before editing. whenever FileMutation.StaleContentError fires, but that error is raised whenever the file's bytes differ from what the tool read — for example when another session or process writes the file during the edit's read→write window. The message misattributes the cause to the permission flow, which is confusing when debugging concurrent edits.

Environment

  • opencode version: 2.0.2
  • OS: Windows 11 (10.0.26220.9343, win32 x64)
  • Terminal: Unavailable: reproduced against the background service
  • Shell: cmd.exe
  • Install/channel: latest (2.0.2)
  • Active plugins: 4 local entries auto-discovered from ~/.config/opencode/plugins/

Reproduction

  1. Start an edit on a file whose content another writer changes concurrently (same path, any session or process).
  2. The store's compare-and-swap detects the mismatch and edit fails with: File changed after permission approval. Read it again before editing.
  3. No permission approval was involved in the failing mutation.

Expected Behavior

A message that names the actual condition, e.g. File changed since it was read. Read it again before editing.

Actual Behavior

File changed after permission approval. Read it again before editing.

Additional Context

  • Source: packages/core/src/tool/edit.ts maps FileMutation.StaleContentError to this message; packages/core/src/file-mutation.ts raises it when the expected bytes differ from the current bytes under the per-path lock.
  • Impact is low — the message still tells the reader to re-read — but the stated reason is misleading in the common concurrent-write case.

Activity

  1. rareboe commented on Sep 14, 2026

    @rareboe

    Taking this one.

    Confirmed both ends in the source:

    • packages/core/src/file-mutation.ts raises StaleContentError from writeIfUnchanged, purely on a byte comparison under the per-path lock:

      const current = yield* fs.readFile(input.target.canonical)
      if (!sameBytes(current, input.expected)) {
        return yield* new StaleContentError({ path: input.target.canonical })
      }
    • packages/core/src/tool/edit.ts is the only place that maps it, and it's the mapping that introduces the permission wording — the error itself carries just a path.

    So the message names a cause the error has no knowledge of. Any writer touching the file inside the read→write window produces it, permission flow or not.

    I'll switch it to the wording you suggested, File changed since it was read. Read it again before editing., which describes the actual condition and keeps the same remedy. packages/core/test/tool-edit.test.ts pins the current string, so that assertion gets updated in the same PR — which also keeps the change provably scoped to this one message.

    PR shortly.

  2. opencodejr commented on Oct 28, 2026

    @opencodejr

    Thanks for the detailed report!

    I couldn't find the message File changed after permission approval. Read it again before editing. or FileMutation.StaleContentError in v2.0.2 or in the current dev branch. In those versions the edit tool is packages/core/src/tool/plugin/edit.ts, and file-mutation.ts no longer has that stale-content check (writes to the same path are serialized by a lock instead). The code you mention was in older source that has since been replaced, which may also be why #48904 was closed.

    Could you share:

    • The exact output of opencode --version from the install where you saw this error.
    • The actual tool output or log lines showing the message, if you saw it in a real session rather than in the source.

    If you can still get this message on a current v2 release (latest is v2.2.0), please include the output. You can reply here with the details, or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know you're done.

    Related items, ordered by how closely they relate:

  3. opencodejr commented on Oct 31, 2026

    @opencodejr

    Closing this as not planned since we haven't heard back. We were waiting for the exact opencode --version and the actual tool output showing File changed after permission approval. Read it again before editing. That message and FileMutation.StaleContentError are in older source but not in v2.0.2 or the current dev branch, so there was nothing we could reproduce on the version you reported.

    If you still see this message on a current v2 release, please open a new issue with the version and the output, and link back to #48707. Thanks for taking the time to report it!

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions