Skip to content

Close prompt, Discard, save flush and restart save each decided in one place per buffer record (phase 1b-2, no behaviour change) - #31313

Merged
nwparker merged 9 commits into
mainfrom
nwparker/editor-buffer-phase-1b-2
Oct 21, 2026
Merged

nwparker merged 9 commits into
mainfrom
nwparker/editor-buffer-phase-1b-2

Conversation

@nwparker

@nwparker nwparker commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​433 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​411
Prod 22 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​410 $\color{#cf222e}{\Huge{\mathbf{−}}}$​125 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​285

ELI5

Today each editor tab decides on its own whether closing it should ask "save changes?", what Discard clears, which unsaved text gets flushed before a save, and which tabs get saved on restart. The next steps let tabs that show the same file share one record of unsaved edits, and then those decisions have to be made per file, not per tab. This PR routes all of them through one place each, keyed by the tab's record. Every tab still has its own record, so nothing changes for users.

What Changed

  • Record → tabs lookup (buffers/editor-buffer-views.ts): editorBufferIdOf (tab → record) and editorBufferViews (record → tabs), kept in the store and updated in the same write as openFiles. Rebuilt only when a tab joins, leaves or moves record.
  • Single entry points:
    • Close prompt: needsSavePromptOnClose — "the record is dirty and this is its last open tab", asked against current state as each tab closes (close queue, single and bulk closes, workspace tab close).
    • Discard: discardEditorBuffer.
    • Pending flush: flushPendingEditorBuffer / hasPendingEditorBufferChange (save queue, autosave, restart save, mobile bridge, artifact upload). The per-tab flush functions are removed.
    • Restart save: restartSaveTargets (one dirty tab per record).
  • Broader dev/e2e check: the lookup matches the open tabs, every record has a tab, mirror fields equal their record, and all tabs of a record hold the same draft. Draft-only writes check only the draft part, so typing stays cheap.

Why

Step 1b-2 of moving to one editor buffer per file. Landing these entry points first, with today's answers, means the later switch to shared records changes one function per decision instead of ~10 scattered per-tab loops. The lookup is stored rather than derived because in the switch a record's id will also depend on route data and on which side had unsaved edits when two tabs joined, which can't be rebuilt from the tab list.

Linked Issue

Follow-up to #31272.

Visual Proof

N/A: no behaviour change.

Testing

  • Existing editor, store, hooks, runtime and lib suites pass unchanged: 4,978 files / 44,385 tests.

  • New tests: the lookup across open/re-key/close; per-tab answers for the close prompt, restart targets, queue keys and flush on main's sharing cases (same file in two workspaces, clean tab, diff tab); closing a record's tabs in either order prompts only on the last; the dev check throws on a draft-only write that splits a record.

  • pnpm tc, check:e2e-typecheck-ratchet, check:code-quality:changed, oxfmt --check pass.

  • Reviewed by GPT and Opus; their fixes (required lookup, close-order handling, cheaper keystroke checks, artifact upload, simplifications) are applied, and a GPT re-review found nothing further.

  • 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

No wire or persisted-state change. Window close and beforeunload paths are untouched.

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 9 commits October 20, 2026 16:27
Adds `editorBufferIdentityOf`, not consumed yet: [environment, host, pairing root, path key] with
exact case, normalized Windows separators and drive letter, WSL alias folding only for a local
Windows client, SSH keyed with its runtime environment, and a detached record id for retired hosts.
Splits `resolveEditorModelOwner` out of the owner-key function; the owner key is unchanged.

Co-Authored-By: Claude <[email protected]>
…hase 1b-1 review)

- A folded WSL alias is a tagged tuple, so a real `\\wsl\<distro>` share can't collide with it.
- `//` is ambiguous between POSIX and UNC, so it folds only for a known-Windows (local) host;
  drive and `\\` paths still fold separators and the drive letter on any host.
- A proven UNC path folds its server name, matching the Monaco URI authority today.
- SSH identity includes the target's endpoint incarnation: a target id edited to point at another
  machine gets a new key, a reconnect keeps it; an unknown endpoint never shares.
- Documents the live pairing resolution and per-event retirement ids.

Co-Authored-By: Claude <[email protected]>
…ified host path flavor

- The SSH endpoint is the one the tab captured at open, passed in by the caller; a live lookup
  would match an old tab to whatever machine the target id names now. Missing means never share.
- Remote hosts accept a verified path flavor (`windows` | `posix` | `unknown`), so a Windows host's
  `//SERVER/share` folds like `\\SERVER\share`, as the Monaco URI authority does today.

Co-Authored-By: Claude <[email protected]>
…nd save keys through the buffer view index (phase 1b-2)

No behaviour change. Each tab still has its own record; this adds the indirection the sharing
switch will change instead of call sites:

- editorBufferIdOf / editorBufferViews, maintained by the record middleware with openFiles
- the invariant now covers the index, records without views, and drafts across a record's views
- writeEditorBuffer, setEditorDraft and clearEditorDraft(s) write every view of the record
- needsSavePromptOnClose at every close site, discardEditorBuffer, record-wide pending flush,
  restartSaveTargets, and injected save-queue keys (queue = model URI, timer/generation = record)

Parity tests check each entry point against the old per-tab expression across a fixture matrix.

Co-Authored-By: Claude <[email protected]>
…order, cheaper draft checks (phase 1b-2 review)

- Lookups take a required EditorBufferViewIndex; tests pass an explicit empty index.
- needsSavePromptOnClose drops the batch set: every site asks against current state as it
  processes each view, so a record's last open view prompts once in any order.
- Drafts-only writes check draft agreement only; the index rebuild is skipped when no tab
  joined, left or moved record.
- Artifact upload flushes through the record; the per-tab flush/has functions are gone.
- Membership and adoption read record ids from the index; drop the save-key injection and
  the test-only useTerminalSaveDialog migration.

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

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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 7 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: 38611adb-2a64-4171-8ecf-7d409d0c393a
📥 Commits

Reviewing files that changed from the base of the PR and between 70b2197 and d30f3a7.

📒 Files selected for processing: 32
  • src/renderer/src/components/editor/csv/CsvViewer.editing.test.tsx
  • src/renderer/src/components/editor/discard-editor-file-changes.ts
  • src/renderer/src/components/editor/editor-artifact-upload.test.ts
  • src/renderer/src/components/editor/editor-artifact-upload.ts
  • src/renderer/src/components/editor/editor-autosave-controller.ts
  • src/renderer/src/components/editor/editor-autosave-state-projections.ts
  • src/renderer/src/components/editor/editor-buffer-entry-points.parity.test.ts
  • src/renderer/src/components/editor/editor-pending-flush.test.ts
  • src/renderer/src/components/editor/editor-pending-flush.ts
  • src/renderer/src/components/editor/editor-restart-save-handlers.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/useIpynbDocumentEditing.test.tsx
  • src/renderer/src/components/floating-terminal/floating-terminal-panel-test-fixtures.ts
  • src/renderer/src/components/floating-terminal/floating-terminal-panel-test-harness.ts
  • src/renderer/src/components/tab-group/workspace-tab-close-commands.ts
  • src/renderer/src/components/terminal-workspace-keydown.test.ts
  • src/renderer/src/components/use-terminal-bulk-close-actions.ts
  • src/renderer/src/components/use-terminal-editor-close-queue.reveal.test.tsx
  • src/renderer/src/components/use-terminal-editor-close-queue.ts
  • src/renderer/src/runtime/mobile-markdown-bridge.ts
  • src/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.test.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.ts
  • src/renderer/src/store/react-commit-cascade-write-probe.test.ts
  • src/renderer/src/store/slices/editor/actions/editor-draft-state.ts
  • src/renderer/src/store/slices/editor/actions/hydrated-editor-session-state.ts
  • src/renderer/src/store/slices/editor/actions/open-file-state.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-close-rule.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-views.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-views.ts
  • src/renderer/src/store/slices/editor/types/editor-files-slice.ts
  • 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.

@nwparker
nwparker merged commit e2fe034 into main Oct 21, 2026
44 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 21, 2026
#31313 renamed a flush call inside the removed renderer Markdown bridge; the bridge stays deleted.
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