Skip to content

Phase 1b: tabs showing the same file share one buffer - #30927

Draft
nwparker wants to merge 15 commits into
mainfrom
nwparker/editor-buffer-1b-share
Draft

nwparker wants to merge 15 commits into
mainfrom
nwparker/editor-buffer-1b-share

Conversation

@nwparker

@nwparker nwparker commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1826 $\color{#cf222e}{\Huge{\mathbf{−}}}$​29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1797
Prod 71 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2287 $\color{#cf222e}{\Huge{\mathbf{−}}}$​452 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1835

ELI5

When the same file is open in two workspaces (or twice in one), Orca now keeps one shared copy of its unsaved state. Typing in one tab shows up as unsaved in the other. Saving from either one saves the file once and clears both. Closing one of them doesn't ask you to save or throw the edits away while another tab still shows them.

This is Phase 1b, part one, of moving to one editor buffer per file: tabs showing the same file share one buffer.

What Changed

Before: two tabs showing the same file already shared one text model, but each tab kept its own unsaved draft, dirty flag, disk version, changed-on-disk mark, autosave pauses, save queue and autosave timer. So:

  • Typing in workspace A changed the text in B, but B still looked clean.
  • A clean B could autosave, or restore old text, on top of A's edits.
  • If a read-only tab opened beside a dirty one, it pushed the disk text into the shared model and wiped the edits.
  • Each tab ran its own autosave timer, so the same file was written twice.
  • Closing any dirty tab asked to save, and choosing "Don't Save" threw away edits another tab was still showing.

After:

  • One record per file. Every edit tab maps to a buffer record. Tabs showing the same physical file share one record, including read-only tabs, where read-only is now only a permission on that tab. The record id is separate from the text model's address, and it never leaves the renderer. A tab joins a record when it opens, when it is renamed or moved, and when its host resolves after a restore. All of this happens in the same store update that changes the tabs. Each tab's dirty flag, disk version and pause flags still mirror the record, as in 1a. A tab opened later picks up the unsaved draft.
  • What "same file" means. The host, plus the path:
    • The host is local, an SSH target keyed by its runtime namespace and target id, or a runtime environment.
    • The path is normalized for separators, drive letter and the two WSL spellings (\\wsl$ and \\wsl.localhost). Case is kept exactly, so paths that differ only in case stay apart.
    • A runtime environment that was re-paired is shared only if Orca proved it is the same machine. A retired environment's tabs keep their own record and their own model, even when the replacement shows the same path with the same text.
  • One file, one draft. When a tab joins a file, the side with unsaved edits wins, and any autosave pause from either side carries over. Only a session saved by an older Orca can hold two different drafts of one file. On restore (or when a host resolves late, or after a rename onto an edited file):
    • The most recently active tab's draft becomes the file's draft.
    • The other draft is kept in the session as a recovered draft. That works the same on desktop and web, and no file is written.
    • One toast, "Recovered N unsaved draft(s) from an earlier session", offers Compare (the recovered draft beside the file as it is now), Copy and Dismiss for each draft.
    • Recovered drafts stay until dismissed, so the toast comes back on the next launch. At most 20 drafts and 2 MB are kept; older ones are dropped and logged.
    • The new session field is optional, so an older build loads the session and ignores it.
  • One save queue and one autosave timer per record. A save from any tab first flushes delayed edits from every tab of the file, then clears dirty for all of them.
  • Closing. Only the last tab that can save the file asks to save. "Don't Save" on any other tab just closes it. When quitting with several tabs of one file queued, the first one asks, and the others close only after you decide. So Cancel keeps them all open. Restart-time saving writes each file once.
  • Preview tabs. A preview tab is promoted to a normal tab when its shared file becomes dirty, and a preview opened onto a file that already has unsaved edits opens as a normal tab. A single click never replaces a tab whose file is dirty.
  • Save results. Saves report written, blocked-stale (kept for guarded saves) or skipped. Save-and-close, Cmd+S and restart-save close a tab or report it saved only when the text was written. A save superseded mid-write still records the disk version it wrote.
  • Closing during a delay. Closing (or tearing down) a tab first flushes its delayed rich-markdown, notebook or CSV text into the shared draft. Code editor edits already arrive immediately.
  • Reads. A queued save doesn't write its older fallback text once a newer write has covered it. Each record has one read-freshness counter. A disk read applies only if no newer read, write or invalidation started after it. Its result reaches every panel showing the file, through any tab still open, even if the tab that started it has closed. A tab whose read was superseded and that still shows nothing reads again, up to 3 times, then shows the retryable load error. Keep My Edits' baseline read never supersedes content reads. Reload from Disk works as on main.
  • Read-only first tab. Clearing dirty works from any tab, and a save finishes through a tab that can write. So a read-only tab opened first no longer leaves the file stuck as dirty.
  • Late save completion. A save that finishes after the tab that started it has closed uses a tab still showing the file. It clears the draft only if the text is unchanged since the write, so newer typing in a sibling tab is kept.
  • Text model addresses. The model address now puts a remote host's owner in a leading /.orca-owner/<hash>/ folder instead of the URL fragment. This keeps the file name last, so the TypeScript service still recognises .tsx files and resolves imports between files on the same host. Both WSL spellings now give one address.
  • Panel caches. When one panel loads, reloads or saves a file, other panels showing the same record update their cached disk text. This stops a panel that mounts later from pushing old text into the shared model.

Dirty state is still main's content compare. That changes in 1c.

Why

The shared-model bug kept coming back across several review rounds because each tab held its own copy of the file's state. One record per file removes the duplication, so there's nothing left to fall out of sync. Sharing ships together with the per-record save queue, the single autosave timer and the last-view close rule. Without them, one workspace's autosave or "Don't Save" could still overwrite or discard another workspace's edits.

Alternatives considered:

Part two should follow soon (Phase 1b part two):

  • The interim model-writing adapter: applyText with delayed commits fenced by version, the pending-text slot, and flushing a sibling's pending text before another tab writes.
  • Limiting a mobile failed-save rollback to its own version.
  • Merging paths that differ only in case once the host proves they are the same file.

Linked Issue

N/A (internal refactor, Phase 1b of the editor buffer plan)

Visual Proof

N/A: no new UI. The behaviour change is which tabs share unsaved state and which close prompts appear. Automated tests cover it.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New tests:

  • Two workspaces share one record, model, draft and dirty flag, and a tab opened later joins.
  • A save from either tab clears both, with one write at a time.
  • A delayed edit pending in the other tab is flushed before a save.
  • One autosave timer per record, so one write.
  • The changed-on-disk mark is shared.
  • The session stores the draft for every tab.
  • The last-view close prompt, and "Don't Save" on a tab that isn't the last.
  • Autosave pauses are shared with a tab that joins later.
  • Another host with the same path stays separate.
  • Case-only path differences stay separate.
  • A read-only tab mounting beside a dirty one keeps the edits.
  • A provisional owner joins its file once the owner resolves, and its edits win.
  • When both sides are dirty, records stay separate for owner resolution, restored legacy drafts that differ (and merge when they match), and a rename onto a dirty file.
  • Identity keys: WSL aliases, exact case, the runtime namespace plus target id for SSH, a proven re-pair joining, and a retired host quarantined against a replacement with the same path and baseline.
  • TypeScript language service on the new model URIs.
  • Regression tests:
    • A save that finishes after the tab that started it closed keeps the sibling's newer draft.
    • A shared dirty preview tab is promoted and never replaced, through the real open path.
    • A tab queued to close behind its sibling leaves the prompt to the sibling.
    • Different restored drafts: one record, the active tab's draft wins, the other is recovered.
    • Recovered drafts persist, an older session still loads, the cap applies, and the toast appears.
    • Save-and-close superseded before writing keeps the tab, and a save superseded mid-write rebaselines.
    • A read started by a tab that closed reaches the surviving tab.
    • A superseded first read reads again, then gives up with a retryable error.
    • Keep My Edits' read doesn't supersede content reads.
    • 2,000 tabs reconcile in under 50 ms.

The 1a store invariant (records equal the open tabs, and every mirror equals its record) is updated for shared records and still runs after every store write in dev and test builds. Ran the renderer store, editor, lib, runtime, terminal, tab-group, right-sidebar, app-shell and hooks suites, plus pnpm tc, oxlint and oxfmt on the changed files.

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

  • Cross-platform: path identity reuses the shared Windows, UNC and WSL helpers, and never folds case.
  • SSH and remote: the host key includes the runtime namespace, and a retired runtime's records are never merged with its replacement's.
  • Mobile: still one projection per tab. The draft is mirrored onto every tab, so the wire format is unchanged.
  • Performance: record membership is stored, not recomputed per keystroke. Same-file lookups are indexed, so one update over 2,000 tabs takes under 50 ms (guarded by a test). Identity is only recomputed for tabs that changed, or when the store fields that decide a tab's host 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)

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Editor tabs now share indexed buffer records for matching files. Save queues, autosave, file reads, and close decisions use the shared records and account for other open views. Buffer freshness checks coordinate content updates across panels and retry superseded reads. The change also adds recovered-draft reconciliation, session persistence, and a notice that offers compare, copy, and dismiss actions.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 9250f

This change makes tabs that show the same file share one buffer. Several paths can still lose or misreport unsaved work. Save-and-close can close a tab while newer edits remain unsaved. Large or concurrently recovered drafts can be discarded or dismissed together. Two panels opening the same file at once can both show a "kept changing" error. Saves can remain blocked or stay marked dirty in some shared-tab arrangements. These issues should be fixed before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 38.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 124 functions across 88 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 and concisely identifies the main change: tabs showing the same file share one editor buffer.
Description check Passed The description is complete and directly aligned with the template. It explains the user impact, implementation, rationale, testing, compatibility considerations, and checklist status. It also explain…
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 complete and directly aligned with the template. It explains the user impact, implementation, rationale, testing, compatibility considerations, and checklist status. It also explains why the linked issue is N/A for this internal refactor and reports that manual testing and full lint, typecheck, test, and build commands were not completed.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • 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: 0b158f52-f095-4779-a014-f28844958bd4
📥 Commits

Reviewing files that changed from the base of the PR and between ad5ef0d and 24dc595.

📒 Files selected for processing: 36
  • src/renderer/src/components/editor/MonacoEditor.tsx
  • src/renderer/src/components/editor/closed-editor-tab-controller.ts
  • src/renderer/src/components/editor/discard-editor-file-changes.ts
  • src/renderer/src/components/editor/editor-autosave-controller-test-fixture.ts
  • src/renderer/src/components/editor/editor-autosave-controller.test.ts
  • src/renderer/src/components/editor/editor-autosave-state-projections.ts
  • src/renderer/src/components/editor/editor-model-host-isolation.test.ts
  • src/renderer/src/components/editor/editor-model-owner.ts
  • src/renderer/src/components/editor/editor-model-uri-language-service.test.ts
  • src/renderer/src/components/editor/editor-model-uri.test.ts
  • src/renderer/src/components/editor/editor-model-uri.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/use-editor-buffer-content-sync.test.tsx
  • src/renderer/src/components/editor/use-editor-buffer-content-sync.ts
  • src/renderer/src/components/editor/useEditorPanelContentState.ts
  • src/renderer/src/components/tab-group/workspace-tab-close-commands.ts
  • src/renderer/src/components/terminal/useTerminalSaveDialog.ts
  • src/renderer/src/components/use-terminal-bulk-close-actions.ts
  • src/renderer/src/components/use-terminal-editor-close-queue.ts
  • src/renderer/src/runtime/web-session-tabs-sync/apply-preparation-browser.ts
  • src/renderer/src/runtime/web-session-tabs-sync/state.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.test.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.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/actions/rekey-open-files-action.ts
  • src/renderer/src/store/slices/editor/actions/restored-editor-owner-transition.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-close-rule.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-identity.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-identity.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.ts
  • src/renderer/src/store/slices/editor/types/editor-files-slice.ts

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

Comment on lines +165 to +172
if (patch && shared) {
recordId = newId
for (let n = 1; recordId in editorBuffers; n += 1) {
recordId = `${newId}#${n}`
}
}
recordIdByFileId[newId] = recordId
editorBuffers[recordId] = { ...record, ...editorBuffers[recordId], ...patch }

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C8 'setRestoredEditorOwnerMigrationPending\s*[:=(]' src/renderer/src/store
rg -nP -C3 'pendingOwnerMigration' src/renderer/src/store/slices/editor/actions

Repository: stablyai/orca

Length of output: 22219


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- editor-buffer-record.ts ---'
cat src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
printf '%s\n' '--- transition caller ---'
sed -n '170,250p' src/renderer/src/store/slices/editor/actions/restored-editor-owner-transition.ts
printf '%s\n' '--- rekey callers and reconciliation references ---'
rg -n -C 12 -F -e 'rekeyEditorBuffers(' -e 'findSharedRecord' -e 'joinPauses' src/renderer/src/store/slices/editor
printf '%s\n' '--- owner migration and shared-buffer tests ---'
rg -n -C 15 -F -e 'shared' -e 'pendingOwnerMigration' src/renderer/src/store/slices/editor/actions/restored-editor-owner* src/renderer/src/store/editor-buffer-record-lifecycle.test.ts

Repository: stablyai/orca

Length of output: 42028


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- editor-buffer-sharing.ts ---'
nl -ba src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.ts | sed -n '1,280p'
printf '%s\n' '--- owner action after transition construction ---'
nl -ba src/renderer/src/store/slices/editor/actions/restored-editor-owner.ts | sed -n '1,180p'
printf '%s\n' '--- transition application and buffer-sharing reconciliation callers ---'
rg -n -C 14 -F -e 'withEditorBufferRecords' -e 'reconcileEditorBuffers' -e 'reconcileEditorBuffer' -e 'editorBufferSharing' src/renderer/src/store/slices/editor src/renderer/src/store

Repository: stablyai/orca

Length of output: 41761


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- pending-owner save and autosave checks ---'
rg -n -C 12 -F -e 'This file is still restoring its workspace owner' -e 'isAutosaveSuspendedForFile' -e 'pendingOwnerMigration' src/renderer/src/store --glob '*.ts'

Repository: stablyai/orca

Length of output: 34824


Clear pendingOwnerMigration on the shared record.

When two tabs share a record, pendingOwnerMigration is mirrored to both tabs. During owner reparenting, the clear is passed as a patch to rekeyEditorBuffers. That function splits the migrated tab from the shared record and applies the clear only to the new record. The sibling record keeps pendingOwnerMigration: true.

Reconciliation can then rejoin the tabs and restore the flag because joinPauses merges pendingOwnerMigration with logical OR. If the tabs remain separate, the sibling still retains the save-blocking flag.

Update rekeyEditorBuffers so a patch that clears pendingOwnerMigration updates the shared record instead of splitting it. Keep the split for patches that add a per-tab pause. Add a sharing test that opens two shared tabs, sets the migration flag, reparents one tab, and asserts that both tabs can save.

@nwparker
nwparker force-pushed the nwparker/editor-buffer-1b-share branch from 24dc595 to bc9fec2 Compare October 20, 2026 01:04

@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: b6bf1500-22c4-4e00-b570-0b7215942137
📥 Commits

Reviewing files that changed from the base of the PR and between 24dc595 and bc9fec2.

📒 Files selected for processing: 10
  • src/renderer/src/components/editor/discard-editor-file-changes.ts
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/use-terminal-editor-close-dialog-actions.ts
  • src/renderer/src/components/use-terminal-editor-close-queue.ts
  • src/renderer/src/store/slices/editor/actions/open-file-mutations.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-sharing.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.ts
  • src/renderer/src/store/slices/editor/tabs/workspace-editor-item.ts

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

Comment on lines +164 to +166
const view = nextState.openFiles.find(
(openFile) => editorBufferIdOf(nextState, openFile.id) === recordId
)

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 | 🟠 Major | ⚡ Quick win

Pick a view that can save when a save finishes.

When a save finishes, view is the first open tab in openFiles that uses the record. Read-only tabs share the record. The test "a read-only tab mounting beside a dirty writable tab shows the edits" covers this case.

Suppose a read-only tab of the file opened before the writable tab. Then view is the read-only tab. nextState.markFileDirty(view.id, false) does nothing, because markFileDirty returns early for readOnly/csvPreviewOnly tabs (open-file-mutations.ts lines 77-80). The record keeps isDirty: true, even though disk now holds contentToSave and the draft is cleared. The writable tab still shows unsaved changes. Closing it asks to save again. Saving again ends the same way, so the flag never clears.

Use the tab that started the save if it is still open. Otherwise, use a tab that can save.

🐛 Proposed fix
--- "a/src/renderer/src/components/editor/editor-save-queue.ts"
+++ "b/src/renderer/src/components/editor/editor-save-queue.ts"
@@ -161,9 +161,16 @@
 
         // Why the record: the tab that started the save may have closed while another still shows the file.
         const nextState = store.getState()
-        const view = nextState.openFiles.find(
-          (openFile) => editorBufferIdOf(nextState, openFile.id) === recordId
-        )
+        const sameRecord = (openFile: OpenFile): boolean =>
+          editorBufferIdOf(nextState, openFile.id) === recordId
+        const view =
+          nextState.openFiles.find((openFile) => openFile.id === file.id && sameRecord(openFile)) ??
+          nextState.openFiles.find(
+            (openFile) =>
+              sameRecord(openFile) &&
+              openFile.readOnly !== true &&
+              openFile.csvPreviewOnly !== true
+          )
         if (!view) {
           return
         }
📝 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
const view = nextState.openFiles.find(
(openFile) => editorBufferIdOf(nextState, openFile.id) === recordId
)
const sameRecord = (openFile: OpenFile): boolean =>
editorBufferIdOf(nextState, openFile.id) === recordId
const view =
nextState.openFiles.find((openFile) => openFile.id === file.id && sameRecord(openFile)) ??
nextState.openFiles.find(
(openFile) =>
sameRecord(openFile) &&
openFile.readOnly !== true &&
openFile.csvPreviewOnly !== true
)

@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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c7be69b0-7f06-4194-94e9-f80db0a13fe1
📥 Commits

Reviewing files that changed from the base of the PR and between bc9fec2 and 0270b5c.

📒 Files selected for processing: 11
  • src/renderer/src/components/editor/editor-save-queue.ts
  • src/renderer/src/components/editor/use-editor-buffer-content-sync.test.tsx
  • src/renderer/src/components/editor/use-editor-buffer-content-sync.ts
  • src/renderer/src/components/editor/useEditorPanelContentState.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.ts
  • src/renderer/src/store/slices/editor/actions/open-file-action.ts
  • src/renderer/src/store/slices/editor/actions/open-file-mutations.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-preview.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.ts
  • src/renderer/src/store/slices/tabs/tabs-create-actions.ts

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

Phase 1b part one: edit tabs of one physical file (host + normalized,
exact-case path; retired runtime pairings quarantined) map to one record
with one save queue and autosave timer. Only the last tab that can save
prompts on close. Dirty+dirty joins stay separate with their own model.
Reuses the URI shape, close rule and cache sync from #30714.
…ce a dirty shared preview

- Save completion reconciles through the captured record and a surviving
  tab, so a closed initiating tab can't clear a sibling's newer draft.
- A preview tab sharing unsaved edits is promoted, and preview
  replacement skips dirty tabs.
- Quit prompts the first queued tab of a file and closes its queued
  siblings only after that decision, so Cancel keeps them open.
…reads safe

- A preview opening onto a dirty file opens as a kept tab; preview
  replacement never drops a tab whose file is dirty.
- Records of one file kept apart for differing drafts never autosave.
- A queued save whose fallback a newer write covered doesn't write it.
- Newer text for a record supersedes other panels' in-flight reads.
- Clearing dirty works from any tab, and save completion prefers a
  writable tab; the sharing reconcile no longer writes tab layout.
…ush delayed edits on close

- Newer text fills a tab whose superseded first read would leave it loading.
- Drafts kept apart only block autosave while they start from the same disk
  version; a save marks the other records changed-on-disk instead.
- Closing or tearing down a tab that shares its file flushes its delayed
  editor text into the shared draft first.
… kept-apart records

- One read-freshness counter per buffer record: a read publishes only if no
  newer read, save or reload of the file started since it began.
- Saves queue per physical file; a record whose disk version predates
  another record's write is marked changed-on-disk instead of writing.
- A clean kept-apart record rejoins its file when both start from the same
  disk version.
- Close flushes delayed editor text before the close rule decides.
@nwparker
nwparker force-pushed the nwparker/editor-buffer-1b-share branch from bb0ae79 to 1192553 Compare October 20, 2026 01:59
…esult, clean-only rejoin

- Delete the renderer write ledger. A record kept apart from another
  record of its file saves through the guarded write with its disk
  baseline; a refusal (or an older host that can't compare) returns
  blocked-stale and shows the banner. Other records keep today's path.
- queueSave resolves written | blocked-stale | skipped; save-and-close,
  Cmd+S and restart-save act on it, closing or reporting saved only when
  written.
- A save during Keep My Edits' baseline read waits for it.
- Kept-apart records rejoin only when both are clean, keeping the newest
  disk version; a clean side never adopts another side's draft.
…-first reload, O(n) sharing

- Overwrite consent is captured when a save is requested; a conflict raised
  while it waited never drops its host precondition.
- Disk reads publish to the file's record, so a closed panel's read still
  reaches the others; freshness is keyed by physical file and bumped by
  reads, writes, Keep and rejoin.
- Reload on a kept-apart tab reads first, then drops the draft; a read
  older than the other side's write is dropped.
- Save-and-close, Cmd+S and restart-save treat anything but written as
  not saved; a save superseded mid-write still rebaselines.
- Same-file lookups are indexed by identity key (2000 tabs < 50 ms).
…y drafts

- Remove kept-apart records, their guarded writes, conflict grouping and
  rejoin. Two different drafts of one file (only from an older session)
  keep the most recently active tab's; the other is kept in the session
  as a recovered draft with a Compare / Copy / Dismiss toast (capped at
  20 drafts and 2 MB; optional field older builds ignore).
- Reads: one freshness counter per record, results publish through any
  surviving tab of the record, a superseded read with nothing shown
  retries up to 3 times then shows the load error, and Keep's baseline
  read never supersedes content reads.
- Reload from Disk is main's again.

@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: 5


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f4b9d36-71df-485d-8f56-4c1cba4ca391
📥 Commits

Reviewing files that changed from the base of the PR and between 85053f1 and 9250fe6.

📒 Files selected for processing: 48
  • src/main/orca-profiles/profile-project-session-field-disposition.ts
  • src/main/persistence/restoring-sessions/session-worktree-ownership.ts
  • src/renderer/src/App.tsx
  • src/renderer/src/components/editor/ExternalFileChangeBanner.test.tsx
  • src/renderer/src/components/editor/ExternalFileChangeBanner.tsx
  • src/renderer/src/components/editor/RecoveredEditorDraftCompareDialog.tsx
  • src/renderer/src/components/editor/RecoveredEditorDraftsNotice.test.tsx
  • src/renderer/src/components/editor/RecoveredEditorDraftsNotice.tsx
  • src/renderer/src/components/editor/editor-autosave-controller-test-fixture.ts
  • src/renderer/src/components/editor/editor-autosave-controller.ts
  • src/renderer/src/components/editor/editor-clean-tab-disk-baseline.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/editor-tab-disk-read.ts
  • src/renderer/src/components/editor/use-editor-buffer-content-sync.test.tsx
  • src/renderer/src/components/editor/use-editor-buffer-content-sync.ts
  • src/renderer/src/components/editor/use-superseded-file-read-retry.ts
  • src/renderer/src/components/editor/useEditorPanelContentState.ts
  • src/renderer/src/components/editor/useEditorPanelFileContentLoader.ts
  • src/renderer/src/components/editor/useEditorPanelVisibilityContentState.test.tsx
  • src/renderer/src/lib/workspace-session-browser-history.test.ts
  • src/renderer/src/lib/workspace-session-editor-drafts.test.ts
  • src/renderer/src/lib/workspace-session-editor-files.ts
  • src/renderer/src/lib/workspace-session-liveness.test.ts
  • src/renderer/src/lib/workspace-session-patch.ts
  • src/renderer/src/lib/workspace-session-relevant-fields.test.ts
  • src/renderer/src/lib/workspace-session.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.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-identity.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-read-freshness.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-read-freshness.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing-scale.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.test.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.ts
  • src/renderer/src/store/slices/editor/buffers/recovered-editor-drafts.test.ts
  • src/renderer/src/store/slices/editor/buffers/recovered-editor-drafts.ts
  • src/renderer/src/store/slices/editor/types/editor-files-slice.ts
  • src/shared/workspace-layout/workspace-layout-beside.ts
  • src/shared/workspace-layout/workspace-layout-fact-locations.test.ts
  • src/shared/workspace-session-editor-schema.ts
  • src/shared/workspace-session-host-field-ownership.ts
  • src/shared/workspace-session-schema-field-coverage.test.ts
  • src/shared/workspace-session-schema.ts
  • src/shared/workspace-session-state-types.ts
  • src/shared/wsl-move/wsl-move-dispositions.ts

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

Comment on lines +257 to +258
if (!isCurrentRead()) {
retryIfSuperseded()

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.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- changed file diff ---'
git diff --unified=80 bfdf16b2530adf8e90939f5374eed4dc47ba1ad1 9250fe67b951394cb09a19164c64c959b6154873 -- src/renderer/src/components/editor/useEditorPanelFileContentLoader.ts
printf '%s\n' '--- target file ---'
nl -ba src/renderer/src/components/editor/useEditorPanelFileContentLoader.ts | sed -n '1,380p'
printf '%s\n' '--- freshness/read symbol references ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'beginEditorBufferFileRead' -e 'isEditorBufferReadCurrent' -e 'inFlightFileReads' -e 'tracksFileRead' -e 'publishEditorBufferContent' -e 'retryIfSuperseded' src/renderer/src
printf '%s\n' '--- relevant freshness files ---'
rg --files src/renderer/src | rg 'editor-buffer-read-freshness|editor-buffer|file-content|FileContent'

Repository: stablyai/orca

Length of output: 39505


🏁 Script executed:

git diff --unified=60 bfdf16b2530adf8e90939f5374eed4dc47ba1ad1 9250fe67b951394cb09a19164c64c959b6154873 -- src/renderer/src/components/editor/useEditorPanelFileContentLoader.ts; nl -ba src/renderer/src/components/editor/useEditorPanelFileContentLoader.ts | sed -n '1,360p'; rg -n -F --glob '*.ts' --glob '*.tsx' -e 'beginEditorBufferFileRead' -e 'isEditorBufferReadCurrent' -e 'inFlightFileReads' -e 'tracksFileRead' -e 'publishEditorBufferContent' -e 'retryIfSuperseded' src/renderer/src; rg --files src/renderer/src | rg 'editor-buffer-read-freshness|editor-buffer|file-content|FileContent'

Repository: stablyai/orca

Length of output: 37466


🏁 Script executed:

git diff --unified=60 bfdf16b2530adf8e90939f5374eed4dc47ba1ad1 9250fe67b951394cb09a19164c64c959b6154873 -- src/renderer/src/components/editor/useEditorPanelFileContentLoader.ts
nl -ba src/renderer/src/components/editor/useEditorPanelFileContentLoader.ts | sed -n '1,360p'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'beginEditorBufferFileRead' -e 'isEditorBufferReadCurrent' -e 'inFlightFileReads' -e 'tracksFileRead' -e 'publishEditorBufferContent' -e 'retryIfSuperseded' src/renderer/src
rg --files src/renderer/src | rg 'editor-buffer-read-freshness|editor-buffer|file-content|FileContent'

Repository: stablyai/orca

Length of output: 37466


🏁 Script executed:

set -eu
for f in \
  src/renderer/src/store/slices/editor/buffers/editor-buffer-read-freshness.ts \
  src/renderer/src/components/editor/use-superseded-file-read-retry.ts \
  src/renderer/src/components/editor/use-editor-buffer-content-sync.ts \
  src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts \
  src/renderer/src/store/slices/editor/buffers/editor-buffer-identity.ts \
  src/renderer/src/components/editor/editor-tab-disk-read.ts
do
  printf '\n--- %s ---\n' "$f"
  nl -ba "$f"
done
printf '\n--- focused retry/sync/loader tests ---\n'
rg -n -F --glob '*.test.ts' --glob '*.test.tsx' \
  -e 'supersed' -e 'same file' -e 'same record' -e 'simult' -e 'read' \
  src/renderer/src/components/editor src/renderer/src/store/slices/editor/buffers \
  | head -240
printf '\n--- loader hook call sites and content ref wiring ---\n'
rg -n -F --glob '*.ts' --glob '*.tsx' \
  -e 'useEditorPanelFileContentLoader(' \
  -e 'fileContentsRef:' \
  -e 'fileContentsRef' \
  src/renderer/src/components/editor src/renderer/src

Repository: stablyai/orca

Length of output: 41596


🏁 Script executed:

set -eu
for f in src/renderer/src/store/slices/editor/buffers/editor-buffer-read-freshness.ts src/renderer/src/components/editor/use-superseded-file-read-retry.ts src/renderer/src/components/editor/use-editor-buffer-content-sync.ts src/renderer/src/store/slices/editor/buffers/editor-buffer-record.ts src/renderer/src/store/slices/editor/buffers/editor-buffer-identity.ts src/renderer/src/components/editor/editor-tab-disk-read.ts; do
  printf '\n--- %s ---\n' "$f"
  nl -ba "$f"
done
printf '\n--- focused tests and call sites ---\n'
rg -n -F --glob '*.test.ts' --glob '*.test.tsx' -e 'supersed' -e 'same file' -e 'same record' -e 'simult' -e 'read' src/renderer/src/components/editor src/renderer/src/store/slices/editor/buffers | head -240
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'useEditorPanelFileContentLoader(' -e 'fileContentsRef:' -e 'fileContentsRef' src/renderer/src/components/editor src/renderer/src

Repository: stablyai/orca

Length of output: 41708


Prevent superseded shared reads from cancelling each other.

When two panels start the same record read together, the first continuation can retry synchronously and invalidate the second continuation before it publishes. Both continuations can then retry in turn until the retry cap reports The file kept changing while it was loading.

Coordinate retries at the record level. A superseded continuation must not start a new read while another subscriber to the shared read can still publish its result. Preserve retries for invalidations or failed newer reads. Add a regression test with two panels that start the same read together and assert that both receive the content without exhausting the retry cap.

Comment on lines +28 to +35
export function isSameRecoveredEditorDraft(
a: RecoveredEditorDraft,
b: RecoveredEditorDraft
): boolean {
return (
a.filePath === b.filePath && a.worktreeId === b.worktreeId && a.recoveredAt === b.recoveredAt
)
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Confirm how dismissal uses the predicate.
rg -nP -C6 'isSameRecoveredEditorDraft|dismissRecoveredEditorDraft' src/renderer/src/store

Repository: stablyai/orca

Length of output: 6976


🏁 Script executed:

#!/bin/bash
set -o pipefail
printf '%s\n' '--- declarations and references ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'RecoveredEditorDraft' -e 'reconcileEditorBufferSharing' -e 'recoveredAt' -e 'modelKey' -e 'key=' src/renderer/src | head -n 240
printf '%s\n' '--- relevant file excerpts ---'
for f in \
  src/renderer/src/store/slices/editor/buffers/recovered-editor-drafts.ts \
  src/renderer/src/store/slices/editor/types/editor-files-slice.ts \
  src/renderer/src/store/slices/editor/actions/open-file-state.ts \
  src/renderer/src/store/slices/editor/actions/reconcile-editor-buffer-sharing.ts \
  src/renderer/src/components/editor/RecoveredEditorDraftsNotice.tsx \
  src/renderer/src/components/editor/RecoveredEditorDraftCompareDialog.tsx; do
  if [ -f "$f" ]; then
    echo "### $f"
    nl -ba "$f" | sed -n '1,240p'
  fi
done
printf '%s\n' '--- schema/session references ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'recoveredEditorDrafts' -e 'recovered-editor-drafts' src | head -n 180

Repository: stablyai/orca

Length of output: 41763


🏁 Script executed:

#!/bin/bash
set -o pipefail
for f in \
  src/renderer/src/store/slices/editor/buffers/editor-buffer-sharing.ts \
  src/renderer/src/store/editor-buffer-record-lifecycle.ts \
  src/shared/workspace-session-state-types.ts \
  src/shared/workspace-session-editor-schema.ts; do
  echo "### $f"
  nl -ba "$f" | sed -n '1,290p'
done
printf '%s\n' '--- now bindings and relevant tests ---'
rg -n -C5 -F --glob '*.ts' -e 'now: Date.now' -e 'now: () => Date.now' -e 'now:' -e 'recoveredAt:' src/renderer/src/store src/shared | head -n 260

Repository: stablyai/orca

Length of output: 42199


Give each recovered draft a stable identity.

When multiple divergent tabs join in one reconciliation pass, reconcileEditorBufferSharing can create multiple recovered drafts for the same file. Each draft receives Date.now(), so consecutive calls can return the same millisecond value. isSameRecoveredEditorDraft and the UI keys then treat those drafts as identical. One Dismiss action can remove both drafts, and the losing draft is no longer available after reconciliation.

Add a stable id to RecoveredEditorDraft, persist it in the schema, and mint it for each recovered draft. Assign IDs to legacy drafts during hydration. Use the ID for isSameRecoveredEditorDraft, the React key in RecoveredEditorDraftsNotice.tsx, and the modelKey in RecoveredEditorDraftCompareDialog.tsx. Comparing draft text is not sufficient because identical drafts can still collide.

…clears, panel-owned read invalidation, recovered-draft notice fixes

- Save-and-close rechecks the record after writing and keeps the tab if
  a sibling typed while it saved.
- A rekey patch applies to the whole record, so clearing an owner
  migration pause clears it for every tab of the file.
- Invalidating a tab supersedes only the panel's own read, and only
  while it is still the file's newest.
- Compare reads SSH files through their connection.
- Recovered drafts: always persisted (empty included) and not copied
  into host partitions; over-cap drafts stay for this launch and say so;
  the newest-visited workspace's draft wins; unique ids with the
  workspace shown; drafts recovered later show the notice again.
…es supersede older reads, stamp the surviving tab, keep live tails apart

- Joins track which tab's draft a record carries, and each recovered
  draft gets a unique id, so three different drafts are all kept and
  credited to their own workspace.
- An external change supersedes every read of the file that started
  before it, so an older read can't clear the reload it caused.
- A read landing after its tab closed publishes to, and stamps the
  baseline of, a surviving tab.
- Live log tails are excluded from the shared read broadcast.
- Save-and-close reports its outcome; a save that landed while a
  sibling kept the tab dirty closes the dialog without an error.
- Dismissing a recovered draft re-applies the size cap.
…its, notebook cells rebase, failed reads reach every panel

- A record's draft owner is carried with it, so a losing draft is credited
  to the workspace it came from even when the first tab had none.
- Quitting flushes every queued tab's delayed edits before the first
  prompt; a save that a sibling keeps dirty asks again while quitting,
  and never runs the tab's close reaction.
- Notebook cell edits apply onto the file's shared text by cell, and
  focus leaving the notebook commits them.
- The newest read of a file failing reaches every panel showing it.
- Id-less recovered drafts (an older build rewrote the session) are told
  apart by their text.
…eral tabs flush

- Flushing a file's tabs applies whole-document serializers (rich
  markdown) in edit order; the newest wins and the text any earlier one
  produced is kept as a recovered draft for its own workspace.
- A CSV tab's pending cell applies onto the file's shared text by cell
  when another tab committed first, instead of over it.
- Every flush path (save, quiesce, hot exit, quit, close, teardown)
  goes through the one record flush.
@nwparker
nwparker marked this pull request as draft October 20, 2026 05:30
@nwparker

Copy link
Copy Markdown
Contributor Author

Parking this as a draft. The safety it was building toward (a save never silently overwrites a disk change it hasn't seen) will land first as host-checked saves per tab (#30417), which doesn't need tabs to share a buffer. This branch stays as the starting point for sharing one buffer per file once rich markdown, notebook and CSV views move onto the shared record, so they stop keeping their own whole-document copies.

This branch has not been deployed

No deployments
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