Skip to content

Saves are never cancelled, and Don't Save always keeps discarded text off disk - #31655

Merged
nwparker merged 6 commits into
mainfrom
nwparker/editor-save-queue-settle
Oct 21, 2026
Merged

nwparker merged 6 commits into
mainfrom
nwparker/editor-save-queue-settle

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​537 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​523
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​463 $\color{#cf222e}{\Huge{\mathbf{−}}}$​251 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​212

ELI5

Editor saves used to be cancelled by an internal "generation" counter whenever something like rename, discard or restart touched a file, and every save request queued another write behind the last one. This makes saving simpler and safer: each tab has at most one save running and one waiting, nothing cancels a save in progress, and "Don't Save" reliably keeps discarded text off disk.

What Changed

  • Save queue: per tab, one running save plus at most one queued save. Further requests join the queued one (Overwrite outranks Cmd+S/restart, which outrank autosave), and the queued save reads the latest text when it runs. Several requests during a slow save now produce one more write, not one each.
  • No cancellation: rename, delete, owner migration, source-control discard and quit wait for pending saves to finish instead of cancelling them. Save generations and the unbounded save chain are deleted.
  • "Don't Save" / discard: marks the tab clean and drops its draft first, then waits for saves. A save requested before the discard writes nothing — checked right before the bytes are sent, including on remote and older hosts — even if a view republishes the text or the tab is marked dirty again. Autosave for the file stays paused until the tab closes. A write already on the wire still finishes.
  • One write at a time per file: an edit tab, its unstaged diff tab and the combined-diff section take turns on the same file; the second is refused by the existing changed-on-disk check instead of racing.
  • Autosave skips (quietly) a tab whose connection was replaced, instead of logging "Reopen the file".

Why

This is the save model a mature editor uses: never cancel a save, and make discard authoritative by clearing first. It replaces several cancellation paths with one rule, and it is the foundation for tabs of one file sharing one record of unsaved edits (next step).

Linked Issue

Follow-up to #31413.

Visual Proof

N/A: no visual change.

Testing

  • New tests: queue merging and latest-text writes, no cancellation on settle, per-file write turns, writer-view selection; Don't Save with running + queued saves (Cmd+S, autosave, Overwrite), with a deleted file, with a notebook republishing, with a remote snapshot marking dirty again, during a slow remote capability check (three host variants), and with a view republishing during the drain.

  • Full src/renderer test run passes; pnpm tc, check:code-quality:changed, oxfmt, oxlint pass.

  • Reviewed by GPT and Opus over several rounds; each "Don't Save" hole they found is covered by a test above.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Behaviour differences: queued saves now finish during quit, rename, delete and source-control discard (they used to be dropped); Cmd+S on an already-clean tab still writes, as before. No wire or persisted-state change.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

nwparker and others added 5 commits October 21, 2026 00:24
…ad of cancel

Saves now run one at a time per tab with at most one queued save behind
them; later requests join the queued save, which reads the latest text
when it runs and writes nothing if the tab is already clean. Writes to
one physical file (edit tab, unstaged diff, combined-diff section) share
one lock. Quiesce no longer cancels saves: it flushes pending text, drops
the autosave timer and waits for the running and queued saves. Autosave
and restart write through the first view whose owner is still current.

Removes save generations, bumpSaveGeneration, the exported
clearAutoSaveTimer, the model-URI queue key and the unbounded save chain.

Co-Authored-By: Claude <[email protected]>
Don't Save now marks the tab clean and clears its draft before waiting
on saves, and a save requested while the tab was dirty writes nothing
if the tab is clean when it reaches the write (Overwrite excepted). A
queued or not-yet-writing save can no longer put discarded text on disk
or recreate a deleted file. A Cmd+S on an already-clean tab still writes,
so a tab whose file was deleted can still recreate it.

Editor saves and combined-diff section saves share one lock key and
skip the lock when the file's host is unknown.

Co-Authored-By: Claude <[email protected]>
Don't Save bumps a per-buffer discard epoch alongside clearing the
draft. A save whose epoch is stale writes nothing, Overwrite included,
and skips the pending-edit flush that could republish the discarded
text. Dirty state alone wasn't enough: a notebook's retained cells or a
remote snapshot can re-dirty the tab after the discard.

Co-Authored-By: Claude <[email protected]>
…gh Don't Save

A save that passed the discard check could still send discarded content
after a remote host's status/capability round trip or an older host's
compare read. The writer now takes a last-moment check, run just before
the bytes are sent on every path (local, unguarded, guarded, older-host
fallback, retry); a discard in that window aborts the send.

Don't Save's drain no longer flushes pending editor text, and it holds
autosave for the file until the tab is closed, so a view that
republishes the dropped text mid-drain can't schedule a fresh autosave.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8262784e-6c2c-45ba-ac77-5c018f0e4497
📥 Commits

Reviewing files that changed from the base of the PR and between c35c05d and 99088be.

📒 Files selected for processing: 23
  • src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.ts
  • src/renderer/src/components/editor/discard-editor-file-changes.save-race.test.ts
  • src/renderer/src/components/editor/discard-editor-file-changes.ts
  • src/renderer/src/components/editor/editor-autosave-controller.ts
  • src/renderer/src/components/editor/editor-autosave-holds.ts
  • src/renderer/src/components/editor/editor-autosave.ts
  • src/renderer/src/components/editor/editor-buffer-entry-points.parity.test.ts
  • src/renderer/src/components/editor/editor-discard-epoch.ts
  • src/renderer/src/components/editor/editor-external-change-tab-reset.ts
  • src/renderer/src/components/editor/editor-file-write-lock.ts
  • src/renderer/src/components/editor/editor-restart-save-handlers.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/editor-save-queue.test.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/editor-save-slots.ts
  • src/renderer/src/components/editor/editor-save-writer-view.test.ts
  • src/renderer/src/components/editor/editor-save-writer-view.ts
  • src/renderer/src/components/use-terminal-editor-close-queue.reveal.test.tsx
  • src/renderer/src/lib/rename-user-named-tab-access.test.ts
  • src/renderer/src/runtime/runtime-file-mutation-client.ts
  • src/renderer/src/runtime/runtime-file-mutation-rpc.ts
  • src/renderer/src/runtime/runtime-file-write-disk-precondition.test.ts
  • src/renderer/src/runtime/runtime-file-write-disk-precondition.ts
📝 Walkthrough

The editor save queue now uses keyed save slots, selects eligible writer views, and serializes writes that share a physical file path. Runtime write APIs accept a callback that can stop a write before transmission. Discard handling advances a per-record epoch, clears dirty and draft state, and settles saves under autosave holds. The change also updates restart and external-change wiring and adds tests for queue behavior, discard races, writer selection, and pre-send cancellation.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to c35c0

An explicit save or overwrite can fail with an owner error when it joins a queued autosave that came from an older view of the same file. The window is narrow and a retry should succeed. Copy the joining view's file id for explicit saves before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 23 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main changes: saves are not cancelled, and discarded text is prevented from reaching disk.
Description check Passed The description is detailed, on-topic, and covers the user impact, implementation, rationale, issue reference, visual proof, testing, and compatibility considerations. Manual testing and the full chec…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed, on-topic, and covers the user impact, implementation, rationale, issue reference, visual proof, testing, and compatibility considerations. Manual testing and the full checklist commands remain unchecked, but the description is mostly complete.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch nwparker/editor-save-queue-settle
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d111a34-1279-4894-9108-b189ae416445
📥 Commits

Reviewing files that changed from the base of the PR and between 524fa00 and c35c05d.

📒 Files selected for processing: 23
  • src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.ts
  • src/renderer/src/components/editor/discard-editor-file-changes.save-race.test.ts
  • src/renderer/src/components/editor/discard-editor-file-changes.ts
  • src/renderer/src/components/editor/editor-autosave-controller.ts
  • src/renderer/src/components/editor/editor-autosave-holds.ts
  • src/renderer/src/components/editor/editor-autosave.ts
  • src/renderer/src/components/editor/editor-buffer-entry-points.parity.test.ts
  • src/renderer/src/components/editor/editor-discard-epoch.ts
  • src/renderer/src/components/editor/editor-external-change-tab-reset.ts
  • src/renderer/src/components/editor/editor-file-write-lock.ts
  • src/renderer/src/components/editor/editor-restart-save-handlers.ts
  • src/renderer/src/components/editor/editor-save-disk-precondition.ts
  • src/renderer/src/components/editor/editor-save-queue.test.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/editor-save-slots.ts
  • src/renderer/src/components/editor/editor-save-writer-view.test.ts
  • src/renderer/src/components/editor/editor-save-writer-view.ts
  • src/renderer/src/components/use-terminal-editor-close-queue.reveal.test.tsx
  • src/renderer/src/lib/rename-user-named-tab-access.test.ts
  • src/renderer/src/runtime/runtime-file-mutation-client.ts
  • src/renderer/src/runtime/runtime-file-mutation-rpc.ts
  • src/renderer/src/runtime/runtime-file-write-disk-precondition.test.ts
  • src/renderer/src/runtime/runtime-file-write-disk-precondition.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Comment on lines +48 to +52
request.fallbackContent = incoming.fallbackContent
request.requestedDirty ||= incoming.requestedDirty
if (TRIGGER_RANK[incoming.trigger] > TRIGGER_RANK[request.trigger]) {
request.trigger = incoming.trigger
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use the joining view's fileId when a merge upgrades the queued save to an explicit trigger.

When a later request joins a queued save, the merge keeps the first requester's fileId. It can still upgrade trigger to user or overwrite. For user and overwrite, editorSaveWriterView returns the view named by request.fileId. It does not select an eligible sibling.

Trigger sequence:

  1. Two views share one record. old predates a reconnect and has stale operationProvenance. fresh is current.
  2. A save is running. The autosave timer for old queues an autosave.
  3. The user presses Cmd/Ctrl+S in fresh. That request joins the queued autosave, and the merge upgrades trigger to user.
  4. The writer view is old. getEditorFileOperationContext throws the owner-changed error.

Result: the user saved from a current view, but the save fails with an owner error. The same problem affects an Overwrite from the fresh banner. An explicit trigger names the view that asked. Copy fileId with the trigger when the incoming request is explicit.

Proposed fix
--- "a/src/renderer/src/components/editor/editor-save-slots.ts"
+++ "b/src/renderer/src/components/editor/editor-save-slots.ts"
@@ -45,12 +45,16 @@
         Object.assign(request, incoming)
         return slot.queued.promise
       }
       request.fallbackContent = incoming.fallbackContent
       request.requestedDirty ||= incoming.requestedDirty
       if (TRIGGER_RANK[incoming.trigger] > TRIGGER_RANK[request.trigger]) {
         request.trigger = incoming.trigger
       }
+      // Why: an explicit save writes through the view that asked, not the first requester.
+      if (incoming.trigger === 'user' || incoming.trigger === 'overwrite') {
+        request.fileId = incoming.fileId
+      }
       return slot.queued.promise
     }
     const request = { ...incoming }
     const promise = (slot?.running ?? Promise.resolve()).then(() => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
request.fallbackContent = incoming.fallbackContent
request.requestedDirty ||= incoming.requestedDirty
if (TRIGGER_RANK[incoming.trigger] > TRIGGER_RANK[request.trigger]) {
request.trigger = incoming.trigger
}
request.fallbackContent = incoming.fallbackContent
request.requestedDirty ||= incoming.requestedDirty
if (TRIGGER_RANK[incoming.trigger] > TRIGGER_RANK[request.trigger]) {
request.trigger = incoming.trigger
}
// Why: an explicit save writes through the view that asked, not the first requester.
if (incoming.trigger === 'user' || incoming.trigger === 'overwrite') {
request.fileId = incoming.fileId
}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant