Skip to content

Native Save can write stale content when queued host edits overlap save preparation #11

Closed

Description

@BinaryOutlook

Native Save can write an earlier document revision when an already queued visual edit is applied during save preparation. The editor supplied a newer snapshot, but the saved file omitted its last edit.

This was found while validating PR #9 and reproduced on the unmodified main commit 4d16748e9079b2679014e0d5ee45a052da759bfc, using its clean CI VSIX from run 35093853277. The baseline reproduction uses plain text only; code blocks and the PR's production changes are not required.

Reproduction

  1. Open a synthetic Markdown file containing Before followed by a newline in the visual editor.
  2. Append intermediate to the paragraph.
  3. Switch to source mode through the toolbar while the earlier visual edit is still pending in the host queue.
  4. Immediately append LATEST to the source textarea.
  5. Invoke VS Code's native File > Save command immediately, before the earlier host edit finishes.
  6. Compare the save snapshot, file on disk, and document buffer.

The automated reproduction uses real editor text insertion and the native workbench.action.files.save command. Because this is a timing issue, performing the steps slowly can miss it.

Observed results

Case Snapshot supplied for Save File written Result
Pending earlier edit, trial 1 Before intermediate\nLATEST Before intermediate\n Latest edit omitted
Pending earlier edit, trial 2 Before intermediate\nLATEST Before intermediate\n Latest edit omitted
Earlier host edit acknowledged before step 4 Before intermediate\nLATEST Before intermediate\nLATEST Correct

At Save completion in the two failing trials, the host buffer also contained the earlier revision and reported clean. In the original code-block CI failure, the latest edit subsequently returned to the buffer as an unsaved change. A successful native Save should persist the captured current text without requiring another Save.

Verified with VS Code 1.85.0 on macOS 26.5.2, arm64. The original failure occurred in the minimum-supported-VS-Code lane of PR validation run 35094940103. No claim is made yet about other VS Code versions.

Investigation direction

The native onWillSaveTextDocument listener first awaits editQueue.flush(), which can apply a pending WorkspaceEdit, and then returns snapshot replacement edits through event.waitUntil. See the listener and EditQueue.

The VS Code save-event API contract says returned edits can be ignored when the document changes concurrently. The observed revision change is consistent with that mechanism; a fix should confirm the precise ordering with a deterministic native regression.

Coordinate queued host mutations with native-save snapshot application so the document revision stays stable while save edits are prepared. Preserve keyboard Save, native Save, TOC refresh, equation commits, and export barriers. Avoid timing sleeps or simply removing the queue flush without replacing its synchronization guarantee.

PR #9 keeps this issue separate from code-block preservation: its native test explicitly completes the source round trip before beginning the quoted-code save scenario, then still saves immediately after that scenario's new edit. This report does not claim that the save overlap is fixed.

All reproduction content is synthetic. Local paths, private document contents, identifying machine details, and raw local logs are omitted.

Activity

  1. added
    bug
    on Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions