Repository navigation
Tabs of the same file share one record of unsaved edits - #31974
Conversation
…oved tabs Delete the pendingDiskBaselineVerification and pendingLiveDiskVerification pause flags. Every editor save is already a guarded write; a refusal raises the changed-on-disk banner, which is what stops autosave until an explicit save. A guarded write now succeeds when disk changed but already holds exactly the text being saved (local/host compare is byte-exact; client-side fallbacks compare decoded text and refuse when it holds U+FFFD), so a restored draft that matches disk goes clean instead of showing a banner. The restore scan only raises the banner early for tabs that arrive dirty; a watch resync no longer re-checks dirty tabs. Co-Authored-By: Claude <[email protected]>
Return a compatible optional no-op result from hosts and client fallbacks, clean the tab, and clear its provisional self-write stamp without rewriting identical bytes. Co-Authored-By: Claude <[email protected]>
…er hosts, flag dirty tabs on resync - Autosave and pre-restart saves refuse when disk text can't be decoded losslessly, so a baseline that decoded to U+FFFD can't authorize overwriting different bytes. - New files.write.identical-noop.v1 capability; for hosts with only the v1 guarded write the client compares first, skips identical saves, then delegates to the host's guarded write. - Watch resync compares dirty tabs against disk and shows the changed-on-disk banner. - Local guarded writes check for identical content before the write-only regular-file probe. Co-Authored-By: Claude <[email protected]>
…false resync banners - Local guarded writes judge losslessness by bytes, so a valid UTF-8 file containing U+FFFD autosaves again. A file that really isn't UTF-8 is refused with its own reason, 'not-utf8' (older clients read it as 'changed'), which pauses autosave for that file with one notice until an explicit save converts it. - A watch resync whose disk read fails leaves dirty tabs alone; the guarded save still catches a real conflict. - Resync and restored-tab checks treat disk holding the tab's own just-written save as an echo. - On hosts with only the v1 guarded write, only automatic saves read the file first; explicit saves go straight to the host's guard. Co-Authored-By: Claude <[email protected]>
…d report disk changes first - The pause is released once no dirty tab of the file remains (close, reload from disk, discard), so a reopened or reloaded file's next autosave asks the host again and notifies. - Client-side precondition checks compare the signature before looking for U+FFFD, so an external rewrite shows the changed-on-disk banner rather than the non-UTF-8 notice. Co-Authored-By: Claude <[email protected]>
…e sharing switch uses First of the stacked sharing-switch PRs (G1). Inert while every record has one view, which is all main produces today; tests drive the shared shape through hand-built view indexes. - Autosave timers are decided per record by its first view that may autosave, so a read-only or preview view of a record no longer cancels the record's timer, and a timer survives the view that scheduled it closing (it resolves a live view of the record when it fires). - A view of a detached record gets its own model owner key, so divergent dirty drafts never share text with the file's other record. - Pure join and rejoin rules: rekey / attach / adopt (dirty wins) / merge (identical dirty) / detach (divergent dirty); a detached pair rejoins only once one side is clean. - Mirrored host tabs: a record's dirty flag is the OR of its host-owned views, since an older host publishes it per tab; the dev invariant tolerates exactly that disagreement. Co-Authored-By: Claude <[email protected]>
…e view for autosave - A merge needs equal drafts, baselines, conflict and owner-migration state; anything else detaches, so a paused record never resumes autosave by joining. A side whose text is still pending (no draft) never counts as identical. - A clean-flagged view that still holds a draft counts as dirty in joins. - The invariant tolerates a clean host-owned view on a dirty record only when another host-owned view of that record reads dirty. - Autosave and restart skip CSV-preview and read-only views when picking the view a record writes through. Co-Authored-By: Claude <[email protected]>
…r-switch-g1-fixes # Conflicts: # src/renderer/src/components/editor/editor-save-queue.ts
Co-Authored-By: Claude <[email protected]>
A dirty view with no draft no longer pushes disk text into the shared model; merge and deleted-banner joins mirror the record; web-session sync honours detached views. Co-Authored-By: Claude <[email protected]>
…ompt closes, restore merges - Rich Markdown, notebook and CSV commits also edit the record's models no editor shows, as one undoable edit; a save moves every loaded view's panel text to the written disk text, so a stale dirty check can't mark the record clean over unsaved edits. - A detached pair rejoins once one side is clean (save, Discard, reload) or the partner closes: the clean side attaches, a dirty side wins with its own baseline, so its next save is refused and the banner shows on every view. Rejoin runs on the next microtask, after the caller has finished settling the record; doing it mid-settle let the settle clear the adopted draft. - A dirty record whose last view a no-prompt removal closed is kept with its draft and model; reopening the file joins it, it never autosaves, and dismissing the removal notice drops it. - Restored identical drafts merge; divergent ones detach with their own models and timers. Co-Authored-By: Claude <[email protected]>
…e a record through its writable view Adds save-queue and store tests for rename and owner-resolution re-keys carrying a conflict, a read-only sibling joining a dirty record, retired-runtime quarantine, runtime-in-SSH identity, the reconnect writer, restart once per record, and a 200-tab index. Fix: restart picked a record's first dirty view, so a read-only view listed first refused the whole restart; it now picks the record's first view that may autosave. Co-Authored-By: Claude <[email protected]>
… save events - A no-prompt removal's keep request rides in the write that closes the tabs (editorBufferKeepRequest, consumed by the record middleware), so a removal closing tabs over several writes keeps every dirty record it closes. - Kept records carry their removal notice's token; dismissing a notice, or failing to show it, releases only that notice's records. - A divergent dirty view reopening a kept record stays detached on its own model; a rename onto a kept record's path drops the kept record. - Each rich/notebook/CSV commit into a retained model is its own undo step. - The saved event names the record's views, so the panel updates them even when the saving tab closed mid-save. - A queued save compares the discard epoch of the record it was queued under. - Typing no longer runs the rejoin check; only clearing a side's draft does. Co-Authored-By: Claude <[email protected]>
…r-switch-g3 # Conflicts: # src/renderer/src/components/editor/editor-model-owner.test.ts # src/renderer/src/components/editor/editor-model-owner.ts # src/renderer/src/components/editor/editor-save-queue-records.test.ts # src/renderer/src/store/editor-buffer-record-lifecycle.ts # src/renderer/src/store/slices/editor/buffers/editor-buffer-join.ts # src/renderer/src/store/slices/editor/buffers/editor-buffer-mirrored-dirty.test.ts # src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts # src/renderer/src/store/slices/editor/buffers/editor-buffer-views.ts
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟠 High · up to
|
…tchet The record middleware now applies reconcile's per-view mirror fields as a membership-preserving map over openFiles, and the mirrored-dirty adoption returns its views for the session-sync patch to write, as it did before. Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Update every view that follows a joined record. · editor-buffer-reconcile.ts:98-104
src/renderer/src/store/slices/editor/buffers/editor-buffer-reconcile.ts:98-104
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winUpdate every view that follows a joined record.
When two clean views move together into an existing dirty record,
joinViewupdates the first view. This branch only indexes the second view. The second view retains its clean flag and old draft, so it disagrees with the shared record and can fail the store invariant. Apply the destination record and draft to each following view before placing it.
ℹ️ Review info
⚙️ Run configuration
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
8e1d5d0d-7117-462b-9398-7ce949e445ce
📒 Files selected for processing: 7
src/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.tssrc/renderer/src/store/editor-buffer-record-lifecycle.test.tssrc/renderer/src/store/editor-buffer-record-lifecycle.tssrc/renderer/src/store/slices/editor/buffers/editor-buffer-mirrored-dirty.test.tssrc/renderer/src/store/slices/editor/buffers/editor-buffer-reconcile-write.tssrc/renderer/src/store/slices/editor/buffers/editor-buffer-reconcile.tssrc/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| mirrored = true | ||
| return { ...file, isDirty: record.isDirty } | ||
| }) | ||
| return { editorBuffers, views: mirrored ? nextOpenFiles : openFiles } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Do not publish a record with mismatched view fields.
If two mirrored views resolve to one record but have different lastKnownDiskSignature values, adoption takes the first signature for the record and changes only isDirty on the views. The returned second view then disagrees with its record. For existing indexed views, reconciliation keeps both views without rewriting those fields, and the invariant rejects the patch. Reconcile every shared field, or keep views with incompatible baselines separate.
…orkspace (read-only) (stablyai#31990)" This reverts commit 8556d11 for the release ad hoc build only. stablyai#31990 builds on stablyai#31974, which is reverted next.
…lyai#31974)" This reverts commit 885cd6f for the release ad hoc build only: release scan blocker STA-11786 (closing a tab mid-save can silently drop a later revert in the same file's other tab).
ELI5
Today, when the same file is open in two workspaces (or a source and a rich-Markdown view), each tab keeps its own copy of your unsaved edits, and they can drift apart — that is where several "my edits were overwritten / lost" bugs came from. Now every tab of a file shares one record of unsaved edits: type in one, the others show it; it's saved once; you're only asked "save changes?" when you close the file's last tab.
What Changed
Why
This is the core of moving to one editor buffer per file. These two parts (shared records, and rich/notebook/CSV writing through them) must ship together: sharing records while those views still wrote per tab would let them overwrite each other. Conflicts are still caught by the existing "refuse if the file changed on disk" save.
Linked Issue
Follow-up to #31970.
Visual Proof
Same file in two workspaces. Typing in A (autosave off):
…shows in B with the unsaved dot:
Closing B asks nothing; closing A, the last tab, asks to save:
Rich view in B, source view in A, stays in sync:
An outside edit while A has unsaved changes: the changed-on-disk banner shows in both workspaces, and the file isn't overwritten:
Testing
Every known scenario has a test: two workspaces typing within the autosave delay (one write, newest text); restored tabs with different unsaved text (in both mount orders); rename with a pending conflict; a phone save while edits are pending; rich text still pending during a save; pause/conflict state visible in every tab; read-only views; reconnect; retired remote environments; nested SSH; restart once per file; 200 tabs across 20 files.
Real app (hidden window, throwaway profile): shared unsaved text, close prompt only on last tab, single autosave write, rich/source sync, conflict banner in both workspaces. The banner was raised by the save-time check; live file-change events weren't arriving on the test machine, so the instant banner with autosave off wasn't exercised there.
pnpm tc,check:code-quality:changed, oxfmt, oxlint; editor/store/hooks/runtime/sidebar/web suites pass.Reviewed by Opus and Sonnet over several rounds; their findings are applied.
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
No wire or persisted-session format change. Tabs mirrored from older paired hosts show unsaved if any of them is. SSH files are keyed by connection; a connection repointed to another machine is caught by the guarded save.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)