Repository navigation
Description
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
- Open a synthetic Markdown file containing
Beforefollowed by a newline in the visual editor. - Append
intermediateto the paragraph. - Switch to source mode through the toolbar while the earlier visual edit is still pending in the host queue.
- Immediately append
LATESTto the source textarea. - Invoke VS Code's native File > Save command immediately, before the earlier host edit finishes.
- 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