Repository navigation
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
Conversation
…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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
There was a problem hiding this comment.
Actionable comments posted: 4
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
39636caf-2fde-498b-842e-ce3bb2c58a52
📒 Files selected for processing: 140
config/renderer-layout-writer-baseline.txtsrc/main/persistence/loading-store/layout-editor-views.tssrc/main/persistence/loading-store/primary-state-write-runtime.tssrc/main/persistence/loading-store/store-runtime-state.tssrc/main/persistence/loading-store/workspace-session-write-listeners.tssrc/main/persistence/loading-store/write-scheduling.tssrc/main/persistence/terminal-topology/cross-partition-tab-move.tssrc/main/persistence/terminal-topology/duplicate-pty-pane-repair.tssrc/main/persistence/terminal-topology/editor-renames-across-partitions.test.tssrc/main/persistence/terminal-topology/layout-command-commit.tssrc/main/persistence/terminal-topology/layout-command-persistence.tssrc/main/persistence/terminal-topology/terminal-layout-renames-commit.tssrc/main/persistence/terminal-topology/terminal-pane-admission.tssrc/main/persistence/terminal-topology/terminal-topology-commit.tssrc/main/persistence/terminal-topology/terminal-topology-profile-fixture.tssrc/main/runtime/editor-view-layout-apply.test.tssrc/main/runtime/editor-view-partition-changes.test.tssrc/main/runtime/editor-view-switch-off.test.tssrc/main/runtime/restored-editor-move-restart.test.tssrc/main/runtime/rpc/methods/workspace-layout-apply.test.tssrc/main/runtime/runtime-layout-apply.test.tssrc/main/runtime/runtime-layout-apply.tssrc/main/runtime/runtime-store-contract.tssrc/main/runtime/workspace-layout-projection.tssrc/renderer/src/components/editor/editor-restored-tab-conflict-scan.test.tssrc/renderer/src/components/editor/markdown-preview-link-actions.tssrc/renderer/src/components/editor/migrate-restored-editor-file-owner.tssrc/renderer/src/components/editor/restored-editor-same-workspace-reown.test.tsxsrc/renderer/src/components/terminal-pane/floating-file-link-selection.test.tssrc/renderer/src/components/terminal-pane/terminal-file-link-editor-open.tssrc/renderer/src/components/terminal-pane/terminal-link-handlers-test-fixtures.tssrc/renderer/src/components/terminal-pane/terminal-link-open-beside-source.test.tssrc/renderer/src/hooks/ipc-events/floating-workspace-reveal-routing.test.tssrc/renderer/src/hooks/ipc-events/mobile-terminal-close-ipc-bridge-reveal.test.tssrc/renderer/src/hooks/ipc-events/mobile-terminal-close-ipc-bridge.test.tssrc/renderer/src/hooks/ipc-events/runtime-file-position.test.tssrc/renderer/src/lib/execute-open-editor-path-move.test.tssrc/renderer/src/lib/execute-open-editor-path-move.tssrc/renderer/src/lib/remap-open-editor-tabs-for-path-change.test.tssrc/renderer/src/lib/rename-user-named-tab-access.test.tssrc/renderer/src/runtime/layout-apply-send.test.tssrc/renderer/src/runtime/layout-apply-send.tssrc/renderer/src/runtime/layout-apply-test-transport.test-fixture.tssrc/renderer/src/runtime/layout-frame-workspaces.tssrc/renderer/src/runtime/layout-owner-content-rekeys.test.tssrc/renderer/src/runtime/layout-owner-content-rekeys.tssrc/renderer/src/runtime/layout-owner-pending-tabs.tssrc/renderer/src/runtime/restored-editor-move-reload.test.tssrc/renderer/src/runtime/workspace-layout-frame-builds.tssrc/renderer/src/runtime/workspace-layout-frame-editor-views.test.tssrc/renderer/src/runtime/workspace-layout-frame-held-tabs.test.tssrc/renderer/src/runtime/workspace-layout-frame-sync.tssrc/renderer/src/runtime/workspace-layout-frame-tab-props.test.tssrc/renderer/src/store/editor-buffer-record-lifecycle.test.tssrc/renderer/src/store/slices/active-selection-owner-scoping.test.tssrc/renderer/src/store/slices/editor-check-details-tabs.test.tssrc/renderer/src/store/slices/editor-close-document-siblings.test.tssrc/renderer/src/store/slices/editor-close-file-cleanup.test.tssrc/renderer/src/store/slices/editor-close-file-stale-active.test.tssrc/renderer/src/store/slices/editor-close-workspace-selection.test.tssrc/renderer/src/store/slices/editor-file-rename-twin-layout-owner.test.tssrc/renderer/src/store/slices/editor-layout-owner-records.test.tssrc/renderer/src/store/slices/editor-open-diff.test.tssrc/renderer/src/store/slices/editor-open-link-placement.test.tssrc/renderer/src/store/slices/editor-preview-tab-setting.test.tssrc/renderer/src/store/slices/editor-recently-closed-tabs.test.tssrc/renderer/src/store/slices/editor-rekey-open-files.test.tssrc/renderer/src/store/slices/editor-right-sidebar-state.test.tssrc/renderer/src/store/slices/editor-session-duplicate-restore.test.tssrc/renderer/src/store/slices/editor-tab-layout-owner.test.tssrc/renderer/src/store/slices/editor-tab-placement.test.tssrc/renderer/src/store/slices/editor/actions/close-file-action.tssrc/renderer/src/store/slices/editor/actions/git-status-actions.tssrc/renderer/src/store/slices/editor/actions/markdown-preview-actions.tssrc/renderer/src/store/slices/editor/actions/open-conflict-file.tssrc/renderer/src/store/slices/editor/actions/open-file-action.tssrc/renderer/src/store/slices/editor/actions/open-file-mutations.tssrc/renderer/src/store/slices/editor/actions/recently-closed-editor-tabs.tssrc/renderer/src/store/slices/editor/actions/rekey-open-files-action.tssrc/renderer/src/store/slices/editor/actions/restored-editor-owner-transition.tssrc/renderer/src/store/slices/editor/actions/restored-editor-owner.tssrc/renderer/src/store/slices/editor/buffers/editor-buffer-views.test.tssrc/renderer/src/store/slices/editor/file-ids/same-owned-editor-document.tssrc/renderer/src/store/slices/editor/tabs/editor-file-rename-through-layout-owner.tssrc/renderer/src/store/slices/editor/tabs/editor-tab-close-through-layout-owner.tssrc/renderer/src/store/slices/editor/tabs/editor-tab-label.tssrc/renderer/src/store/slices/editor/tabs/editor-tab-layout-owner.tssrc/renderer/src/store/slices/editor/tabs/editor-tab-open-through-layout-owner.tssrc/renderer/src/store/slices/editor/tabs/open-file-layout-view.test.tssrc/renderer/src/store/slices/editor/tabs/open-file-layout-view.tssrc/renderer/src/store/slices/editor/tabs/restored-editor-move-through-layout-owner.tssrc/renderer/src/store/slices/editor/tabs/workspace-editor-item.tssrc/renderer/src/store/slices/editor/types/editor-files-slice.tssrc/renderer/src/store/slices/new-markdown.test.tssrc/renderer/src/store/slices/project-removal-host-twin-state.test.tssrc/renderer/src/store/slices/project-removal-owner-host.test.tssrc/renderer/src/store/slices/restored-editor-owner-layout-owner.test.tssrc/renderer/src/store/slices/restored-editor-owner-reparent.test.tssrc/renderer/src/store/slices/restored-editor-owner-restart.test.tssrc/renderer/src/store/slices/server-editor-file-restart-identity.test.tssrc/renderer/src/store/slices/store-open-to-side-layout-owner.test.tssrc/renderer/src/store/slices/tabs-close-dangling-group.test.tssrc/renderer/src/store/slices/tabs-drawn-from-main.test-fixture.tssrc/renderer/src/store/slices/tabs-hydration.tssrc/renderer/src/store/slices/tabs-label-and-pin-state.test.tssrc/renderer/src/store/slices/tabs-open-close-lifecycle.test.tssrc/renderer/src/store/slices/tabs-unread-and-focus.test.tssrc/renderer/src/store/slices/tabs/moved-tab-selection.tssrc/renderer/src/store/slices/tabs/preview-tab-promotion.test.tssrc/renderer/src/store/slices/tabs/preview-tab-promotion.tssrc/renderer/src/store/slices/tabs/tabs-close-actions.tssrc/renderer/src/store/slices/tabs/tabs-focus-actions.tssrc/renderer/src/store/slices/tabs/tabs-label-actions.tssrc/renderer/src/store/slices/tabs/tabs-layout-owner-groups-order.test.tssrc/renderer/src/store/slices/tabs/tabs-reconciliation-empty-groups.test.tssrc/renderer/src/store/workspace-layout-frame-slices.tssrc/shared/rpc-contract/workspace-layout-editor-file-params.test.tssrc/shared/rpc-contract/workspace-layout-editor-file-params.tssrc/shared/rpc-contract/workspace-layout-params.tssrc/shared/workspace-layout/layout-editor-view.tssrc/shared/workspace-layout/workspace-layout-command-types.tssrc/shared/workspace-layout/workspace-layout-commands.test.tssrc/shared/workspace-layout/workspace-layout-content-commands.tssrc/shared/workspace-layout/workspace-layout-editor-duplicates.test.tssrc/shared/workspace-layout/workspace-layout-editor-rekey.test.tssrc/shared/workspace-layout/workspace-layout-editor-rekey.tssrc/shared/workspace-layout/workspace-layout-editor-tab-file.tssrc/shared/workspace-layout/workspace-layout-fact-locations.test.tssrc/shared/workspace-layout/workspace-layout-from-published.tssrc/shared/workspace-layout/workspace-layout-group-commands.tssrc/shared/workspace-layout/workspace-layout-load-tabs.tssrc/shared/workspace-layout/workspace-layout-load-types.tssrc/shared/workspace-layout/workspace-layout-load-workspace.tssrc/shared/workspace-layout/workspace-layout-model.tssrc/shared/workspace-layout/workspace-layout-published-editor-view.test.tssrc/shared/workspace-layout/workspace-layout-published.tssrc/shared/workspace-layout/workspace-layout-workspace-move.test.tssrc/shared/workspace-layout/workspace-layout-workspace-move.tstests/e2e/layout-compat-baselines.jsontests/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.
| // 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' } | ||
| } |
There was a problem hiding this comment.
🩺 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:
expectContentRekeypassesMAX_REKEYSand drops the oldest entry.rekey.patchthrows, sofinish(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.
| // 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)), |
There was a problem hiding this comment.
🗄️ 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
| /** 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 }) | ||
| }) |
There was a problem hiding this comment.
🗄️ 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 -20Repository: 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 -240Repository: 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 -240Repository: 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 -240Repository: 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 -100Repository: 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.
| /** 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 }) | |
| }) |
| // 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 | ||
| ]) | ||
| ) |
There was a problem hiding this comment.
🎯 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
editorViewsat 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|
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. |
… the file, as main does since #31291 (test only)
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:openEditorTab.editorFileKey, so the fact-locations test reads them from there.Not changed: the
openInNewGrouptolerances 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
editor-buffer-views) is converted in this PR.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.ci-static-gatepasses; 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):
openFilereturnsNo 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.
Review
One independent review, then delta reviews for each fix round (CHANGES NEEDED twice, then APPROVE WITH NITS, nits fixed).
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)