Skip to content

Editor tabs main-first: the window asks main for every editor tab change and draws only main's update (dark, layout-owner build only) - #31438

Merged
Jinwoo-H merged 5 commits into
mainfrom
fd/d3a2-editor-frame-draw
Oct 21, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
fd/d3a2-editor-frame-draw

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 68 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4819 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1312 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3507
Prod 72 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3309 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1235 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2074

ELI5

Orca is moving the job of deciding the tab layout from the window to the app's background process ("main"). This is behind a build switch that is off in every shipped build, so users see no change. With the switch on, editor tabs now work the way the plan wants: when you open, close, pin, reopen, move or rename a file tab, the window asks main, and the tab appears, changes or goes away only when main's update arrives. The window no longer draws the change first and reports it afterwards.

What Changed

Everything below happens only with ORCA_LAYOUT_OWNER=main:

  • Open (including preview replace and open to the side): the window proposes the tab id and sends openEditorTab.
    • The command carries the file's saved record, or for a diff, conflict, check or markdown-preview tab its view (what it shows, plus the file facts needed to rebuild it).
    • The file's content (open-file record, buffer, draft) is written at once. The tab is drawn from main's update, and selecting, focusing or revealing it waits for that update.
    • Main stamps the tab's time (L186) and decides preview replacement.
  • Reopen at its old position: one command carrying the position, where it used to be an open followed by a move (L136).
  • Close and close-all: the tab leaves with main's update.
    • Content cleanup runs after that, and is skipped if main refuses.
    • A close already in flight is never sent twice; a second close joins it.
  • Promote (pin, activate, edit) and the resolved deleted-side conflict placeholder are now just commands to main (L135, L182).
  • Restored-editor move to the file's workspace (L157, L158) and disk rename (L180) are commands to main.
    • The window's drafts, buffers and autosave guard switch to the new id in the same store update as main's update, so no frame ever shows a tab without its content.
    • A refused rename undoes the disk move.
    • A rename that spans several workspaces is one command, written all-or-nothing per main's save.
  • Main side:
    • publishes each non-edit tab's view and keeps views in memory beside the saved session. They are never on disk; they follow a tab across a partition change and drop with a removed workspace (L183);
    • folds a same-file duplicate into the tab the group already shows, instead of refusing;
    • drops the "the window's save got there first" skip (L160).
  • Deleted: the five draw-first editor recorders and their before/after store captures; the editor cases in the drawn-tab holds; and the rule that kept window-only editor tabs through main's updates (L183).
  • Test-only: the record-key fields are declared once, next to editorFileKey, so the fact-locations test reads them from there.

Not changed: the openInNewGroup tolerances and the window's empty-group split derivation (L139, L140, L141) stay, because terminal, browser, simulator and chat creates still use them. They go when those move to main-first.

Why

The plan's target is one owner for the layout, with or without a window. Draw-first editor tabs were the largest remaining place where the window decided and main learned afterwards. That is what lets a closed tab come back or a frame flicker a tab out and in.

We chose to keep file content in the window and only send layout commands. Moving content to main would be a much bigger change for no gain, since content is per-window by design. The cost is that a move or rename must switch content and tabs in one store update, so that path is held in a small registry the frame flush applies.

Linked Issue

Internal (terminal-layout final design, D3a-2).

Visual Proof

N/A: dark path behind a build switch that is off in shipped builds. With the switch on, behaviour is covered by the tests and e2e runs below.

Testing

  • Proofs, all switch-on and unmocked:
    • the same file in two groups gives two tabs;
    • the same path on two hosts stays two files and two tabs;
    • a tab is selected only with its update;
    • a close lands only with main's update, and a refused close keeps the tab;
    • promotion clears with the update;
    • a move or rename lands in one store update with the update;
    • a re-own that reaches a tab still opening waits for main;
    • Q5: an editor tab Orca moved survives a restart, through main's real Store and a reloaded window.
  • Main's real Store: a diff tab keeps its view across later commands, a partition change and a failed write.
  • Switch-on comparison (src/main/runtime, src/main/persistence, src/renderer/src/runtime, terminal-pane, editor store and components), head against merge-base 7dfcfbf: no file passes at base and fails at head. The one file that newly failed (editor-buffer-views) is converted in this PR.
  • Server specs: tab-composition, layout-frames and focused-terminal-create pass at head and base (fresh switch-on builds at each commit).
  • E2e on a switch-on build: golden-source-control-open-diff, editor-tab-selection-restore, golden-file-open-edit-save, cli-file-open-position and editor-model-host-isolation pass. In workspace-layout-oracle, 18 of 20 pass; the other two (live-daemon-restart, sleep-quit-resume) fail the same way at base.
  • Latency, switch-on base against head, interleaved, 3 runs: no change counts under the owner's rule. Open-file p50 deltas were +2.1, −1.1 and −1.3 ms; rename was about +1.1 ms, below base's spread.
  • Switch-off bundle diff against the merge-base: 91 hunks, none a switch-off behaviour change. Every hunk is either behind the build constant (folded away, or reached only through layout.apply, which only switch-on builds register) or gives the same result: an empty editor-view map, a refactor with identical writes, or a callback that runs at once.
  • Unchanged ratchets and gates: ci-static-gate passes; the census and routing tests pass.

Switch-on tests this PR changed, classified (all STALE: the same user-visible result, now reached through main's command plus its update):

File Tests Verdict Reason
restored-editor-same-workspace-reown 1 STALE the re-own reached main only for a drawn tab; the test now draws from main
editor-close-file-cleanup (mirrored close-all) 2 STALE the fixture lacked the paired-server owner row; with it, close-all keeps today's path
rename-user-named-tab-access 8 STALE rename, Undo and Redo now land through main's answer
editor-buffer-record-lifecycle 1 STALE the self-move rekey lands through main's answer
editor-buffer-views 1 STALE the rename's buffer rekey lands through main's answer
tabs-label-and-pin-state, tabs-unread-and-focus 2 STALE promotion is sent once and clears with the update
editor-restored-tab-conflict-scan 14 STALE uses the id openFile returns

No REGRESSION was found.

Server specs: tab-composition, layout-frames and focused-terminal-create pass at head 438d6c2 (the final head adds one converted test file) and at base 7dfcfbf; layout-intents is absent on both.

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

Review

One independent review, then delta reviews for each fix round (CHANGES NEEDED twice, then APPROVE WITH NITS, nits fixed).

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

  • SSH and remote: a paired server's workspace keeps today's path. Main never lays it out, and mirrored tabs are not sent to main.
  • Partitions: editor views follow a tab within this process. A WSL move or an SSH host moving to a managed server puts the workspace on another Orca process, and views (memory-only, not saved, like today's diff tabs across a restart) are not carried there.
  • Folder workspaces: handled the same as git worktrees.
  • Owner-visible with the switch on:
    • a diff, conflict, check or preview tab survives a window reload while main runs;
    • a same-file duplicate in one group is folded on load and on move;
    • a newly opened tab is selected one main round-trip later.
  • Ledger:
    • closes L133, L134, L135, L136, L157, L158, L180, L182 and L183;
    • closes the createdAt part of L186 and the already-moved skip of L160;
    • keeps L137 and L160's tab_exists (ids are still window-proposed);
    • leaves L139, L140 and L141 for the terminal and browser lanes.

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)

…nd draws editor tabs only from main's frames (dark, layout-owner build only)

With ORCA_LAYOUT_OWNER_IS_MAIN on, editor open (preview replace, open to the side), reopen at
its position, close, close-all, promote, the resolved conflict placeholder, a restored-editor
move and a disk rename are layout commands the window sends before it draws anything. Window
content (open file records, drafts, buffers, the autosave gate) is written at once for an open,
and rekeyed in the same store update as the frame for a move or rename. Main publishes each
non-edit tab's view, keeps views in memory across applies and partition changes, stamps the
tab's time, folds same-file duplicates, and republishes a windowless host's session.tabs after
its own file open. The switch-off path is unchanged.
…draw

# Conflicts:
#	src/main/runtime/construction/runtime-file-command-state.ts
#	src/main/runtime/files/editor-open-through-layout-owner.ts
#	src/renderer/src/runtime/workspace-layout-frame-sync.ts
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c1bfc0ae-8d41-47ba-ab08-54d047bcb07d
📥 Commits

Reviewing files that changed from the base of the PR and between 82eba1c and 7dcf579.

📒 Files selected for processing: 2
  • tests/e2e/layout-compat-baselines.json
  • tests/e2e/layout-compat-old-phone-on-new-server.spec.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • tests/e2e/layout-compat-old-phone-on-new-server.spec.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.

📝 Walkthrough

The change adds layout-owned editor views and carries them through shared commands, workspace models, published frames, persistence partitions, renames, moves, and rollback paths. Renderer editor operations now coordinate with the layout owner through pending tabs and content rekeys. Tests now cover asynchronous frame synchronization, cross-workspace operations, preview behavior, restored tabs, and compatibility fixtures.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 7dcf5

Several editor workflows can lose tabs, reconstruct incorrect file state, or leave restored files unsaveable. These issues should be addressed 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 59.41% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 101 functions across 53 files. (1 skipped… 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 identifies the primary change: editor tabs now use main-first ownership in the layout-owner build. It is somewhat long but remains specific and relevant.
Description check Passed The description is comprehensive and follows the template. It explains the user-visible behavior, implementation, rationale, testing, compatibility considerations, and review status. The linked issue …
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 comprehensive and follows the template. It explains the user-visible behavior, implementation, rationale, testing, compatibility considerations, and review status. The linked issue is described as an internal design reference rather than an issue link, but the overall description is complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 59.41% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 101 functions across 53 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • 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: 4


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 39636caf-2fde-498b-842e-ce3bb2c58a52
📥 Commits

Reviewing files that changed from the base of the PR and between 92732bb and a75b039.

📒 Files selected for processing: 140
  • config/renderer-layout-writer-baseline.txt
  • src/main/persistence/loading-store/layout-editor-views.ts
  • src/main/persistence/loading-store/primary-state-write-runtime.ts
  • src/main/persistence/loading-store/store-runtime-state.ts
  • src/main/persistence/loading-store/workspace-session-write-listeners.ts
  • src/main/persistence/loading-store/write-scheduling.ts
  • src/main/persistence/terminal-topology/cross-partition-tab-move.ts
  • src/main/persistence/terminal-topology/duplicate-pty-pane-repair.ts
  • src/main/persistence/terminal-topology/editor-renames-across-partitions.test.ts
  • src/main/persistence/terminal-topology/layout-command-commit.ts
  • src/main/persistence/terminal-topology/layout-command-persistence.ts
  • src/main/persistence/terminal-topology/terminal-layout-renames-commit.ts
  • src/main/persistence/terminal-topology/terminal-pane-admission.ts
  • src/main/persistence/terminal-topology/terminal-topology-commit.ts
  • src/main/persistence/terminal-topology/terminal-topology-profile-fixture.ts
  • src/main/runtime/editor-view-layout-apply.test.ts
  • src/main/runtime/editor-view-partition-changes.test.ts
  • src/main/runtime/editor-view-switch-off.test.ts
  • src/main/runtime/restored-editor-move-restart.test.ts
  • src/main/runtime/rpc/methods/workspace-layout-apply.test.ts
  • src/main/runtime/runtime-layout-apply.test.ts
  • src/main/runtime/runtime-layout-apply.ts
  • src/main/runtime/runtime-store-contract.ts
  • src/main/runtime/workspace-layout-projection.ts
  • src/renderer/src/components/editor/editor-restored-tab-conflict-scan.test.ts
  • src/renderer/src/components/editor/markdown-preview-link-actions.ts
  • src/renderer/src/components/editor/migrate-restored-editor-file-owner.ts
  • src/renderer/src/components/editor/restored-editor-same-workspace-reown.test.tsx
  • src/renderer/src/components/terminal-pane/floating-file-link-selection.test.ts
  • src/renderer/src/components/terminal-pane/terminal-file-link-editor-open.ts
  • src/renderer/src/components/terminal-pane/terminal-link-handlers-test-fixtures.ts
  • src/renderer/src/components/terminal-pane/terminal-link-open-beside-source.test.ts
  • src/renderer/src/hooks/ipc-events/floating-workspace-reveal-routing.test.ts
  • src/renderer/src/hooks/ipc-events/mobile-terminal-close-ipc-bridge-reveal.test.ts
  • src/renderer/src/hooks/ipc-events/mobile-terminal-close-ipc-bridge.test.ts
  • src/renderer/src/hooks/ipc-events/runtime-file-position.test.ts
  • src/renderer/src/lib/execute-open-editor-path-move.test.ts
  • src/renderer/src/lib/execute-open-editor-path-move.ts
  • src/renderer/src/lib/remap-open-editor-tabs-for-path-change.test.ts
  • src/renderer/src/lib/rename-user-named-tab-access.test.ts
  • src/renderer/src/runtime/layout-apply-send.test.ts
  • src/renderer/src/runtime/layout-apply-send.ts
  • src/renderer/src/runtime/layout-apply-test-transport.test-fixture.ts
  • src/renderer/src/runtime/layout-frame-workspaces.ts
  • src/renderer/src/runtime/layout-owner-content-rekeys.test.ts
  • src/renderer/src/runtime/layout-owner-content-rekeys.ts
  • src/renderer/src/runtime/layout-owner-pending-tabs.ts
  • src/renderer/src/runtime/restored-editor-move-reload.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-builds.ts
  • src/renderer/src/runtime/workspace-layout-frame-editor-views.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-held-tabs.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-sync.ts
  • src/renderer/src/runtime/workspace-layout-frame-tab-props.test.ts
  • src/renderer/src/store/editor-buffer-record-lifecycle.test.ts
  • src/renderer/src/store/slices/active-selection-owner-scoping.test.ts
  • src/renderer/src/store/slices/editor-check-details-tabs.test.ts
  • src/renderer/src/store/slices/editor-close-document-siblings.test.ts
  • src/renderer/src/store/slices/editor-close-file-cleanup.test.ts
  • src/renderer/src/store/slices/editor-close-file-stale-active.test.ts
  • src/renderer/src/store/slices/editor-close-workspace-selection.test.ts
  • src/renderer/src/store/slices/editor-file-rename-twin-layout-owner.test.ts
  • src/renderer/src/store/slices/editor-layout-owner-records.test.ts
  • src/renderer/src/store/slices/editor-open-diff.test.ts
  • src/renderer/src/store/slices/editor-open-link-placement.test.ts
  • src/renderer/src/store/slices/editor-preview-tab-setting.test.ts
  • src/renderer/src/store/slices/editor-recently-closed-tabs.test.ts
  • src/renderer/src/store/slices/editor-rekey-open-files.test.ts
  • src/renderer/src/store/slices/editor-right-sidebar-state.test.ts
  • src/renderer/src/store/slices/editor-session-duplicate-restore.test.ts
  • src/renderer/src/store/slices/editor-tab-layout-owner.test.ts
  • src/renderer/src/store/slices/editor-tab-placement.test.ts
  • src/renderer/src/store/slices/editor/actions/close-file-action.ts
  • src/renderer/src/store/slices/editor/actions/git-status-actions.ts
  • src/renderer/src/store/slices/editor/actions/markdown-preview-actions.ts
  • src/renderer/src/store/slices/editor/actions/open-conflict-file.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/actions/recently-closed-editor-tabs.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/actions/restored-editor-owner.ts
  • src/renderer/src/store/slices/editor/buffers/editor-buffer-views.test.ts
  • src/renderer/src/store/slices/editor/file-ids/same-owned-editor-document.ts
  • src/renderer/src/store/slices/editor/tabs/editor-file-rename-through-layout-owner.ts
  • src/renderer/src/store/slices/editor/tabs/editor-tab-close-through-layout-owner.ts
  • src/renderer/src/store/slices/editor/tabs/editor-tab-label.ts
  • src/renderer/src/store/slices/editor/tabs/editor-tab-layout-owner.ts
  • src/renderer/src/store/slices/editor/tabs/editor-tab-open-through-layout-owner.ts
  • src/renderer/src/store/slices/editor/tabs/open-file-layout-view.test.ts
  • src/renderer/src/store/slices/editor/tabs/open-file-layout-view.ts
  • src/renderer/src/store/slices/editor/tabs/restored-editor-move-through-layout-owner.ts
  • src/renderer/src/store/slices/editor/tabs/workspace-editor-item.ts
  • src/renderer/src/store/slices/editor/types/editor-files-slice.ts
  • src/renderer/src/store/slices/new-markdown.test.ts
  • src/renderer/src/store/slices/project-removal-host-twin-state.test.ts
  • src/renderer/src/store/slices/project-removal-owner-host.test.ts
  • src/renderer/src/store/slices/restored-editor-owner-layout-owner.test.ts
  • src/renderer/src/store/slices/restored-editor-owner-reparent.test.ts
  • src/renderer/src/store/slices/restored-editor-owner-restart.test.ts
  • src/renderer/src/store/slices/server-editor-file-restart-identity.test.ts
  • src/renderer/src/store/slices/store-open-to-side-layout-owner.test.ts
  • src/renderer/src/store/slices/tabs-close-dangling-group.test.ts
  • src/renderer/src/store/slices/tabs-drawn-from-main.test-fixture.ts
  • src/renderer/src/store/slices/tabs-hydration.ts
  • src/renderer/src/store/slices/tabs-label-and-pin-state.test.ts
  • src/renderer/src/store/slices/tabs-open-close-lifecycle.test.ts
  • src/renderer/src/store/slices/tabs-unread-and-focus.test.ts
  • src/renderer/src/store/slices/tabs/moved-tab-selection.ts
  • src/renderer/src/store/slices/tabs/preview-tab-promotion.test.ts
  • src/renderer/src/store/slices/tabs/preview-tab-promotion.ts
  • src/renderer/src/store/slices/tabs/tabs-close-actions.ts
  • src/renderer/src/store/slices/tabs/tabs-focus-actions.ts
  • src/renderer/src/store/slices/tabs/tabs-label-actions.ts
  • src/renderer/src/store/slices/tabs/tabs-layout-owner-groups-order.test.ts
  • src/renderer/src/store/slices/tabs/tabs-reconciliation-empty-groups.test.ts
  • src/renderer/src/store/workspace-layout-frame-slices.ts
  • src/shared/rpc-contract/workspace-layout-editor-file-params.test.ts
  • src/shared/rpc-contract/workspace-layout-editor-file-params.ts
  • src/shared/rpc-contract/workspace-layout-params.ts
  • src/shared/workspace-layout/layout-editor-view.ts
  • src/shared/workspace-layout/workspace-layout-command-types.ts
  • src/shared/workspace-layout/workspace-layout-commands.test.ts
  • src/shared/workspace-layout/workspace-layout-content-commands.ts
  • src/shared/workspace-layout/workspace-layout-editor-duplicates.test.ts
  • src/shared/workspace-layout/workspace-layout-editor-rekey.test.ts
  • src/shared/workspace-layout/workspace-layout-editor-rekey.ts
  • src/shared/workspace-layout/workspace-layout-editor-tab-file.ts
  • src/shared/workspace-layout/workspace-layout-fact-locations.test.ts
  • src/shared/workspace-layout/workspace-layout-from-published.ts
  • src/shared/workspace-layout/workspace-layout-group-commands.ts
  • src/shared/workspace-layout/workspace-layout-load-tabs.ts
  • src/shared/workspace-layout/workspace-layout-load-types.ts
  • src/shared/workspace-layout/workspace-layout-load-workspace.ts
  • src/shared/workspace-layout/workspace-layout-model.ts
  • src/shared/workspace-layout/workspace-layout-published-editor-view.test.ts
  • src/shared/workspace-layout/workspace-layout-published.ts
  • src/shared/workspace-layout/workspace-layout-workspace-move.test.ts
  • src/shared/workspace-layout/workspace-layout-workspace-move.ts
  • tests/e2e/layout-compat-baselines.json
  • tests/e2e/layout-compat-old-phone-on-new-server.spec.ts

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

Comment on lines +83 to +86
// Switch point: the move is main's; its frame moves the file, or main refused it.
if (ORCA_LAYOUT_OWNER_IS_MAIN && result.ok && !(await contentRekeyOutcome([result.fileId]))) {
return { ok: false, reason: 'owner-changed' }
}

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 | 🟡 Minor | ⚡ Quick win

Clear the pending owner-migration flag when the content rekey is dropped without a refusal.

Only the refused handler in reparentRestoredEditorThroughLayoutOwner calls setRestoredEditorOwnerMigrationPending(args.fileId, false). In two other cases, contentRekeyOutcome resolves false and nothing clears the flag:

  • expectContentRekey passes MAX_REKEYS and drops the oldest entry.
  • rekey.patch throws, so finish(entry, false) runs.

In both cases this function returns owner-changed, and the file keeps pendingOwnerMigration: true. That flag blocks saves, so the user can no longer save the restored tab. Clear the flag on this failure path. The call is idempotent: if the migration ran, the old id no longer exists and the setter returns false.

🐛 Proposed fix
   if (ORCA_LAYOUT_OWNER_IS_MAIN && result.ok && !(await contentRekeyOutcome([result.fileId]))) {
+    // A dropped rekey left the file under its old id: its save gate must not stay closed.
+    useAppStore.getState().setRestoredEditorOwnerMigrationPending(fileId, false)
     return { ok: false, reason: 'owner-changed' }
   }
📝 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
// Switch point: the move is main's; its frame moves the file, or main refused it.
if (ORCA_LAYOUT_OWNER_IS_MAIN && result.ok && !(await contentRekeyOutcome([result.fileId]))) {
return { ok: false, reason: 'owner-changed' }
}
// Switch point: the move is main's; its frame moves the file, or main refused it.
if (ORCA_LAYOUT_OWNER_IS_MAIN && result.ok && !(await contentRekeyOutcome([result.fileId]))) {
// A dropped rekey left the file under its old id: its save gate must not stay closed.
useAppStore.getState().setRestoredEditorOwnerMigrationPending(fileId, false)
return { ok: false, reason: 'owner-changed' }
}

const keptOnly = <T>(record: Record<string, T>): Record<string, T> =>
Object.fromEntries(Object.entries(record).filter(([id]) => kept.has(id)))
return {
openFiles: s.openFiles.filter((f) => kept.has(f.id)),

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 | 🟡 Minor | ⚡ Quick win

Remove only the files the close-all closed, not every file outside kept.

With the switch on, cleanUp runs after main settles the closes. At that time, it keeps a file only if the file is in kept. kept holds only entries from closingFiles. These are the files that were open when closeAllFiles was called.

The user can open a file during this wait, for example with a quick open right after "Close all". That file is not in closingFiles, so it is not in kept. For the active worktree, line 117 removes its OpenFile record. Lines 120-146 then remove its draft and view state. With no active worktree, line 101 and keptOnly remove the records of every new file. Main's frame still draws the new tab, so the tab points at a file record that no longer exists.

Filter on the closed set: the closingFiles ids minus kept. Do not filter on "everything except kept".

🐛 Proposed fix
-      const cleanUp = (recorded: AppState | null, kept: ReadonlySet<string>): void => {
+      const closingIds = new Set(closingFiles.map((file) => file.id))
+      const cleanUp = (recorded: AppState | null, kept: ReadonlySet<string>): void => {
+        const closes = (id: string): boolean => closingIds.has(id) && !kept.has(id)
         set((s) => {
           const records = recorded ?? s
           if (!activeWorktreeId) {
             const keptOnly = <T>(record: Record<string, T>): Record<string, T> =>
-              Object.fromEntries(Object.entries(record).filter(([id]) => kept.has(id)))
+              Object.fromEntries(Object.entries(record).filter(([id]) => !closes(id)))
             return {
-              openFiles: s.openFiles.filter((f) => kept.has(f.id)),
+              openFiles: s.openFiles.filter((f) => !closes(f.id)),
 ...
-          const newFiles = s.openFiles.filter(
-            (f) => f.worktreeId !== activeWorktreeId || kept.has(f.id)
-          )
+          const newFiles = s.openFiles.filter((f) => !closes(f.id))

Apply the same scope to closedFileIds (lines 155-157). Then the tab order of a file opened later is not pruned.

Also applies to: 116-118

Comment on lines +28 to +41
/** Checks the mode, and an edit view's conflict; the snapshots are the window's own records. */
function isEditorTabView(value: unknown): value is EditorTabView {
return (
isRecord(value) &&
EDITOR_VIEW_MODES.has(value.mode) &&
(value.mode !== 'edit' || isRecord(value.conflict))
)
}

/** What a non-plain editor tab shows, with its file's facts; main keeps it in memory only. */
export const EditorViewRecord = z.object({
view: z.custom<EditorTabView>(isEditorTabView, 'Invalid editor tab view'),
file: EditorFileRecord.omit({ liveTail: true })
})

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 | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n 55,75p src/renderer/src/store/slices/editor/tabs/open-file-layout-view.ts
sed -n 165,200p src/renderer/src/store/workspace-layout-frame-slices.ts
rg -n "layout.apply|layoutApply" src/main/runtime/rpc/methods/workspace-layout-apply.ts | head -20

Repository: stablyai/orca

Length of output: 2079


🏁 Script executed:

set -u
printf '%s\n' '--- schema and imports ---'
nl -ba src/shared/rpc-contract/workspace-layout-editor-file-params.ts | sed -n '1,120p'
rg -n -F --glob '*.ts' -e 'EditorViewRecord' -e 'layout.apply' -e 'layoutApply' -e 'applyLayout' src/main src/shared src/renderer | head -200
printf '%s\n' '--- candidate layout/apply files ---'
rg --files src/main src/shared src/renderer | rg 'workspace-layout|layout.*(apply|rpc)|rpc.*layout'
printf '%s\n' '--- relevant main handlers/storage ---'
rg -n -F --glob '*.ts' -e 'PublishedWorkspaceLayout' -e 'editorViews' -e 'editorView' src/main/runtime src/main | head -240

Repository: stablyai/orca

Length of output: 42074


🏁 Script executed:

set -u
printf '%s\n' '--- schema and imports ---'
nl -ba src/shared/rpc-contract/workspace-layout-editor-file-params.ts | sed -n '1,120p'
rg -n -F --glob '*.ts' -e 'EditorViewRecord' -e 'layout.apply' -e 'layoutApply' -e 'applyLayout' src/main src/shared src/renderer | head -200
printf '%s\n' '--- candidate layout/apply files ---'
rg --files src/main src/shared src/renderer | rg 'workspace-layout|layout.*(apply|rpc)|rpc.*layout'
printf '%s\n' '--- relevant main handlers/storage ---'
rg -n -F --glob '*.ts' -e 'PublishedWorkspaceLayout' -e 'editorViews' -e 'editorView' src/main | head -240

Repository: stablyai/orca

Length of output: 41472


🏁 Script executed:

set -u
printf '%s\n' '--- RPC method and params ---'
nl -ba src/main/runtime/rpc/methods/workspace-layout.ts | sed -n '1,260p'
nl -ba src/shared/rpc-contract/workspace-layout-params.ts | sed -n '1,260p'
printf '%s\n' '--- main apply and projection ---'
nl -ba src/main/runtime/runtime-layout-apply.ts | sed -n '1,180p'
nl -ba src/main/runtime/workspace-layout-projection.ts | sed -n '1,130p'
printf '%s\n' '--- sender and reachability guard ---'
nl -ba src/renderer/src/runtime/layout-apply-send.ts | sed -n '1,280p'
nl -ba src/renderer/src/runtime/layout-apply-paired-server-guard.test.ts | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 42794


🏁 Script executed:

set -u
printf '%s\n' '--- apply params and command types ---'
nl -ba src/shared/rpc-contract/workspace-layout-params.ts | sed -n '250,390p'
nl -ba src/shared/workspace-layout/workspace-layout-commands.ts | sed -n '1,260p'
nl -ba src/shared/workspace-layout/workspace-layout-model.ts | sed -n '1,180p'
printf '%s\n' '--- editor view storage/publication ---'
nl -ba src/shared/workspace-layout/workspace-layout-published.ts | sed -n '1,220p'
nl -ba src/main/runtime/workspace-layout-projection.ts | sed -n '1,100p'
rg -n -F --glob '*.ts' -e 'operationProvenance' -e 'terminalArtifactGrantId' -e 'externalSshTargetId' -e 'type OpenFile' src/renderer/src src/shared | head -200
printf '%s\n' '--- method registration and client allowlists ---'
rg -n -F --glob '*.ts' -e 'LAYOUT_APPLY_METHODS' -e 'mobile' -e 'allowlist' src/main/runtime/rpc src/main src/shared | head -240

Repository: stablyai/orca

Length of output: 42636


🏁 Script executed:

set -u
printf '%s\n' '--- editor open and published editor view ---'
rg -n -F --glob '*.ts' -e 'function openEditorTab' -e 'editorView:' -e 'editorViews:' -e 'publishWorkspaceLayout' src/shared/workspace-layout src/main/runtime
nl -ba src/shared/workspace-layout/workspace-layout-content-commands.ts | sed -n '1,220p'
nl -ba src/shared/workspace-layout/workspace-layout-published.ts | sed -n '80,220p'
printf '%s\n' '--- renderer reconstruction and authority fields ---'
nl -ba src/renderer/src/store/slices/editor/tabs/open-file-layout-view.ts | sed -n '1,100p'
nl -ba src/renderer/src/store/workspace-layout-frame-slices.ts | sed -n '155,195p'
rg -n -F --glob '*.ts' -e 'operationProvenance' -e 'terminalArtifactGrantId' src/renderer/src | head -120
printf '%s\n' '--- RPC permission and registration ---'
nl -ba src/main/runtime/rpc/rpc-method-permission.ts | sed -n '1,180p'
rg -n -F --glob '*.ts' -e 'WORKSPACE_LAYOUT_METHODS' -e 'LAYOUT_VIEW_REPORT_METHODS' -e 'LAYOUT_APPLY_METHODS' src/main/runtime/rpc | head -100

Repository: stablyai/orca

Length of output: 43438


Reject unknown editor-view keys at the RPC boundary.

z.custom preserves the accepted object, so layout.apply can store and publish extra keys in view. Both renderer reconstruction paths spread that object last and can overwrite OpenFile identity and file metadata.

This endpoint is available to local or paired desktop clients with workspace permission, not mobile clients. This limits the security impact, but malformed or version-skewed desktop input can still corrupt editor state across windows.

🛡️ Suggested fix
--- "a/src/shared/rpc-contract/workspace-layout-editor-file-params.ts"
+++ "b/src/shared/rpc-contract/workspace-layout-editor-file-params.ts"
@@ -25,14 +25,29 @@
 const isRecord = (value: unknown): value is Record<string, unknown> =>
   typeof value === 'object' && value !== null && !Array.isArray(value)
 
-/** Checks the mode, and an edit view's conflict; the snapshots are the window's own records. */
-function isEditorTabView(value: unknown): value is EditorTabView {
-  return (
-    isRecord(value) &&
-    EDITOR_VIEW_MODES.has(value.mode) &&
-    (value.mode !== 'edit' || isRecord(value.conflict))
-  )
-}
+const VIEW_FIELDS: Record<EditorTabView['mode'], readonly string[]> = {
+  edit: ['conflict'],
+  diff: [
+    'diffSource', 'branchCompare', 'commitCompare', 'branchOldPath', 'combinedAlternate',
+    'combinedAreaFilter', 'branchEntriesSnapshot', 'commitEntriesSnapshot',
+    'uncommittedEntriesSnapshot', 'skippedConflicts'
+  ],
+  'markdown-preview': ['markdownPreviewSourceFileId', 'markdownPreviewAnchor'],
+  'conflict-review': ['conflictReview'],
+  'check-details': ['checkRunDetails']
+}
+
+/** Checks the mode, its view fields, and an edit view's conflict. */
+function isEditorTabView(value: unknown): value is EditorTabView {
+  if (!isRecord(value) || !EDITOR_VIEW_MODES.has(value.mode)) {
+    return false
+  }
+  const allowed = VIEW_FIELDS[value.mode as EditorTabView['mode']]
+  return (
+    Object.keys(value).every((key) => key === 'mode' || allowed.includes(key)) &&
+    (value.mode !== 'edit' || isRecord(value.conflict))
+  )
+}
 
 /** What a non-plain editor tab shows, with its file's facts; main keeps it in memory only. */
 export const EditorViewRecord = z.object({

Also whitelist the mode-specific fields when rebuilding an OpenFile instead of spreading editorView.view or framedFile.view without filtering.

📝 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
/** Checks the mode, and an edit view's conflict; the snapshots are the window's own records. */
function isEditorTabView(value: unknown): value is EditorTabView {
return (
isRecord(value) &&
EDITOR_VIEW_MODES.has(value.mode) &&
(value.mode !== 'edit' || isRecord(value.conflict))
)
}
/** What a non-plain editor tab shows, with its file's facts; main keeps it in memory only. */
export const EditorViewRecord = z.object({
view: z.custom<EditorTabView>(isEditorTabView, 'Invalid editor tab view'),
file: EditorFileRecord.omit({ liveTail: true })
})
const VIEW_FIELDS: Record<EditorTabView['mode'], readonly string[]> = {
edit: ['conflict'],
diff: [
'diffSource', 'branchCompare', 'commitCompare', 'branchOldPath', 'combinedAlternate',
'combinedAreaFilter', 'branchEntriesSnapshot', 'commitEntriesSnapshot',
'uncommittedEntriesSnapshot', 'skippedConflicts'
],
'markdown-preview': ['markdownPreviewSourceFileId', 'markdownPreviewAnchor'],
'conflict-review': ['conflictReview'],
'check-details': ['checkRunDetails']
}
/** Checks the mode, its view fields, and an edit view's conflict. */
function isEditorTabView(value: unknown): value is EditorTabView {
if (!isRecord(value) || !EDITOR_VIEW_MODES.has(value.mode)) {
return false
}
const allowed = VIEW_FIELDS[value.mode as EditorTabView['mode']]
return (
Object.keys(value).every((key) => key === 'mode' || allowed.includes(key)) &&
(value.mode !== 'edit' || isRecord(value.conflict))
)
}
/** What a non-plain editor tab shows, with its file's facts; main keeps it in memory only. */
export const EditorViewRecord = z.object({
view: z.custom<EditorTabView>(isEditorTabView, 'Invalid editor tab view'),
file: EditorFileRecord.omit({ liveTail: true })
})

Comment on lines +93 to +105
// A renamed tab's view follows its file to the new path.
const views = new Map(
renames.flatMap((rename) => (rename.view ? [[rename.newFileId, rename.view] as const] : []))
)
const entityOf = new Map(tabs.map((tab) => [tab.id, tab.entityId]))
const editorViews =
workspace.editorViews &&
Object.fromEntries(Object.entries(workspace.editorViews).map(([id, view]) => [tabId(id), view]))
Object.fromEntries(
Object.entries(workspace.editorViews).map(([id, view]) => [
tabId(id),
views.get(entityOf.get(tabId(id)) ?? '') ?? view
])
)

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

Store a rename's view even when the renamed tab has no view yet.

The new views are applied only while the code walks workspace.editorViews. A rename.view is therefore dropped in two cases:

  • The workspace has no editorViews at all.
  • The renamed tab has no entry in editorViews.

The window sends a view for every non-plain renamed tab. When main drops it, the tab stays without a view. A reloaded or second window then cannot draw it, because buildLayoutFrameSlices draws a diff, conflict or check tab only from its view.

moveTabToWorkspace (newView ?? source.editorViews?.[tab.id]) already adds a view the tab did not have. Rename should do the same.

🐛 Proposed fix
   const entityOf = new Map(tabs.map((tab) => [tab.id, tab.entityId]))
-  const editorViews =
-    workspace.editorViews &&
-    Object.fromEntries(
-      Object.entries(workspace.editorViews).map(([id, view]) => [
-        tabId(id),
-        views.get(entityOf.get(tabId(id)) ?? '') ?? view
-      ])
-    )
+  const rekeyedViews = Object.fromEntries(
+    Object.entries(workspace.editorViews ?? {}).map(([id, view]) => [tabId(id), view])
+  )
+  for (const tab of tabs) {
+    const view = EDITOR_KINDS.has(tab.kind) ? views.get(tab.entityId) : undefined
+    if (view) {
+      rekeyedViews[tab.id] = view
+    }
+  }
+  const editorViews =
+    workspace.editorViews || Object.keys(rekeyedViews).length > 0 ? rekeyedViews : undefined

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Delta review (Opus) of the commits after the last reviewed state, at a75b039: APPROVE WITH NITS. It covered the refile early return (correct and inert with the switch off), the main-merge resolutions (main's publishHeadlessTabs covers the dropped republish; the frame-binding loop matches main's helper and is stricter), and the editor-buffer-views conversion (every assertion kept). One nit: terminalLayoutsWithReboundFrames is left with no caller after the merge; it's deleted in the stacked follow-up.

@Jinwoo-H
Jinwoo-H merged commit cfd9e9c into main Oct 21, 2026
60 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 21, 2026
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