Repository navigation
Saves are never cancelled, and Don't Save always keeps discarded text off disk - #31655
Conversation
…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]>
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]>
|
Warning Review limit reachedYou'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. View limit details
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
5d111a34-1279-4894-9108-b189ae416445
📒 Files selected for processing: 23
src/renderer/src/components/editor/combined-diff/review-controls/use-combined-diff-section-actions.tssrc/renderer/src/components/editor/discard-editor-file-changes.save-race.test.tssrc/renderer/src/components/editor/discard-editor-file-changes.tssrc/renderer/src/components/editor/editor-autosave-controller.tssrc/renderer/src/components/editor/editor-autosave-holds.tssrc/renderer/src/components/editor/editor-autosave.tssrc/renderer/src/components/editor/editor-buffer-entry-points.parity.test.tssrc/renderer/src/components/editor/editor-discard-epoch.tssrc/renderer/src/components/editor/editor-external-change-tab-reset.tssrc/renderer/src/components/editor/editor-file-write-lock.tssrc/renderer/src/components/editor/editor-restart-save-handlers.tssrc/renderer/src/components/editor/editor-save-disk-precondition.tssrc/renderer/src/components/editor/editor-save-queue.test.tssrc/renderer/src/components/editor/editor-save-queue.tssrc/renderer/src/components/editor/editor-save-slots.tssrc/renderer/src/components/editor/editor-save-writer-view.test.tssrc/renderer/src/components/editor/editor-save-writer-view.tssrc/renderer/src/components/use-terminal-editor-close-queue.reveal.test.tsxsrc/renderer/src/lib/rename-user-named-tab-access.test.tssrc/renderer/src/runtime/runtime-file-mutation-client.tssrc/renderer/src/runtime/runtime-file-mutation-rpc.tssrc/renderer/src/runtime/runtime-file-write-disk-precondition.test.tssrc/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.
| request.fallbackContent = incoming.fallbackContent | ||
| request.requestedDirty ||= incoming.requestedDirty | ||
| if (TRIGGER_RANK[incoming.trigger] > TRIGGER_RANK[request.trigger]) { | ||
| request.trigger = incoming.trigger | ||
| } |
There was a problem hiding this comment.
🎯 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:
- Two views share one record.
oldpredates a reconnect and has staleoperationProvenance.freshis current. - A save is running. The autosave timer for
oldqueues an autosave. - The user presses Cmd/Ctrl+S in
fresh. That request joins the queued autosave, and the merge upgradestriggertouser. - The writer view is
old.getEditorFileOperationContextthrows 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.
| 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 | |
| } |
Co-Authored-By: Claude <[email protected]>
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
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/renderertest 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)