Skip to content

Browser, chat and simulator tabs main-first: the window asks main for each change and draws only main's update (dark, layout-owner build only) - #31516

Merged
Jinwoo-H merged 71 commits into
mainfrom
fd/d3b-content-tabs-main-first
Oct 22, 2026
Merged

Jinwoo-H merged 71 commits into
mainfrom
fd/d3b-content-tabs-main-first

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 60 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4181 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1459 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2722
Prod 59 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2354 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1237 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1117

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, browser, chat and simulator tabs now work the way editor tabs do since #31438. When you open, close or change one, the window asks main, and the tab appears or goes away only when main's update arrives. The window no longer draws the change first and tells main afterwards.

Follows #31438 (editor tabs), now merged. This branch merged main after #31438 landed and again at cd8b289. In the second merge, runtime-layout-apply.ts takes main's #31571 close (refused pinned tabs and the launch mark only for a closed tab) with D3b's comment, and store-active-worktree-split-groups.test.ts keeps both sides.

What Changed

Everything below happens only with ORCA_LAYOUT_OWNER=main:

  • Browser tabs: opening and closing a tab, adding, closing and converting a page, and switching profiles are commands to main.
    • The window proposes the ids and writes the page records at once. It draws the tab from main's update.
    • A close drops the page content after main's update, and skips that if main refuses (L146, L147).
  • Chat tabs: opening and closing are commands to main, and main places the chats this machine's host lists (L153).
    • A chat created from this machine's window is placed by the window's own open. Main does not place it a second time.
    • When the host lists chats, the window writes no tab structure for workspaces that main draws; a changed chat title only changes the drawn label.
    • A cancelled local launch is fenced by main's close and no longer needs the window's tombstone (L155, and the switch-on local part of L156).
  • Simulator tabs: opening and closing are commands to main (L194).
  • Main side:
    • A tab whose group main lacks goes to the workspace's first group. The window's anchor fallback is deleted (L150).
    • moveTab takes an optional isPinned, so a move and a pin are one step.
    • Main builds the phone's diff and markdown-preview rows the same way the window does. A preview names its source by the window's open-file id.
  • Window side: a close that main answers with workspace_not_found is handled like tab_not_found, so the tab leaves.
  • Deleted:
    • the draw-first browser, chat and simulator recorders (12 call sites);
    • the duplicate chat command builder: one chatTabLayoutCommand now serves main and the switch-off save;
    • a frame-binding helper that the merge left without callers.

Drawn-tab holds (L263): D3b removes every content-tab caller of the hold, as listed above. These drawn: true callers remain:

  • terminal create (terminal-tab-create-through-layout-owner.ts, D1a);
  • terminal close (terminal-tab-close-layout-owner.ts, D1b);
  • tab-order and recently-closed moves (tab-order-layout-owner.ts, recently-closed-tab-position.ts);
  • divider ratios (tab-group-layout-owner-commands.ts).

Sleep/wake, setChatPane and default tabs still go through recordLayoutApply, but they hold no tab. The file is deleted by whichever PR removes the last caller.

Switch-on product bugs fixed here

These three bugs appeared only once these tabs were drawn from main, and none of them occurs switch-off. For each one, I took the fix back out at the final head and confirmed its test fails; with the fix in, the test passes in both builds.

  1. The hidden chat slot. A resumed CLI chat keeps a hidden launch slot in the window. Main's first update dropped that slot, so the chat lost its saved place. The fix keeps the slot after its neighbour through main's updates, and main no longer places a chat the window created.
    • Tests: cli-chat-resume-run.test.ts "keeps canonical membership through registered IPC" (×4) and "opens a resumed chat once, through main, after the tab before its hidden slot"; structured-agent-session-create-window-placement.test.ts; structured-agent-session-windowless-layout.test.ts "puts a window's chat where the window opens it".
    • Switch-off: does not happen. The window draws its own tabs and main never places a window's chat.
  2. A declined chat's pin and move. A chat whose launch is declined is replaced by its terminal at the chat's position, pinned as the chat was. This was done only in the window, and sending the pin separately re-sorted the order. Now one main moveTab carries isPinned, at the chat's index among the tabs main draws, before main closes the chat.
    • Tests: workspace-layout-move-tab-pin.test.ts (pin and unpin); structured-agent-session-provisional-tab.test.ts "owns the destination through terminal completion" (typed-before, typed-during) and "places a declined chat's terminal right after the chat past a hidden launch slot".
    • Switch-off: does not happen. The window makes the same move and pin in one store update, unchanged.
  3. A chat the host couldn't close never came back. Main dropped the tab, and nothing asked main to open it again. Now, if this machine's host still lists the chat, the window asks main to reopen it.
    • Test: structured-session-tab-close-regressions.unit.test.ts "shows the chat again when the host could not close it".
    • Switch-off: does not happen. The window re-reads the host's list and shows the chat again.

Why

The plan's target is a single owner for the layout, with or without a window. Browser, chat and simulator tabs were the remaining content tabs where the window decided first and main found out afterwards. That ordering is what lets a closed tab come back, or a tab flicker out and back in.

The approach follows #31438. Content stays in the window (page records, chat drafts, emulator attachment) and only layout commands go to main. Moving content to main would be a much larger change for no gain, since that content is per-window by design.

Linked Issue

Internal (terminal-layout final design, D3b).

Visual Proof

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

Testing

  • Converted tests: 155 switch-on tests failed at head and passed at base. Two more (pty-connection-spawn-and-startup) pass on re-run, so they are flaky. All 155 are STALE: they share one cause, a test store with no main to answer the command. After conversion, 8 of them exposed the three bugs above, which are now fixed in product code. All 29 files pass at the final head, both switch-on and switch-off (379 tests).

  • Switch-on comparison, head 78a2d24 against merge-base cfd9e9c (main with 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). Folders: src/main/runtime, src/main/persistence, src/renderer/src/runtime, terminal-pane, store, lib, browser-pane, tab-bar, native-chat, editor and shared/workspace-layout. No test fails at head that does not also fail at base. Head has 37 failures in 18 files, out of 46,085 tests; base has 50 failures.

  • After the second main merge (cd8b289, head 7bf2dd2): switch-on comparison over src/main/runtime and src/renderer/src/store, which hold the two conflicted files. No test fails at head that passes at base: 22 head failures in 7 files out of 18,748, all failing at base too (base: 26).

  • Server specs: tab-composition, layout-frames and focused-terminal-create pass at head 7bf2dd2 and at base cd8b289, each on a fresh switch-on build (earlier: head 78a2d24 against base cfd9e9c, same result). layout-intents is absent at both.

  • Latency, switch-on, base a75b039 (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) against head, interleaved, 3 runs of 40 samples, p50:

    • browser open: −1.0, −0.7 and −0.2 ms;
    • browser close: +1.9, +2.0 and +1.4 ms.

    Both are far below the 16 ms rule. Chat open was not timed. The window's chat open is reachable only inside a lazy chunk, and only from a structured launch. Timing it would need a fake structured agent host wired into the latency harness, which is more than about an hour of work. It moves to the pre-flip latency gate (gate 9), where it is measured once.

  • Switch-off bundle diff against a75b039: 241 hunks, none a switch-off behaviour change.

    • 20 can't run switch-off: they sit behind the build constant, are reached only through layout.apply, or only switch-on senders reach them (the anchor fallback, isPinned, main's phone rows).
    • 221 give the same result: import and chunk lists, the browser actions wrapped as "do it here" and called at once, and the chat command extraction, which uses the same rule.
  • Unchanged ratchets and gates: ci-static-gate passes, and the census and routing tests pass both ways.

Switch-on tests this PR changed, classified:

Group Tests Files Verdict Reason
Browser open on the harness's partial store 41 browser 24, annotation-retention 8, annotation-document 4, host-ownership 3, remote-tab-creation 2 STALE the tab now comes from main's update; a store fixture drawn from main is added
Browser open, close or convert on a full store 69 doc-location 18, creation-placement 17, page-conversion 14, active-worktree-tab-close 6, mount-admission-removal 3, client-hosted-row 3, remote-page-lifecycle 2, jump-palette 2, conversion-publish 2, removal-successor 1, split-groups 1 STALE same result, through main's command plus its update
Chat open 33 launch-admission 13, cli-chat-resume-run 11, new-chat-own-launch 4, AiVault keyboard 2, initial-terminal-admission-wait 2, provisional-tab 1 STALE same; new-chat-own-launch checks main's command only, because its stand-in store can't draw updates
Chat close 12 tab-close-regressions 6, agent-status 2, chat-close-owner 1, draft-teardown 1, unread snapshot 1, status-bridge 1 STALE the e2e stub now answers from a real main model, and paired-server tests get an owner row

No REGRESSION remains; the three bugs found are fixed above.

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

Review

One independent review, then a delta review for each fix round. The last delta review covered the six fixes in bab77a6 and everything after it, up to the final head 1d796cb, including the queue fix 9b5f10e and the test-only commit 1d796cb. Verdict: APPROVE. Its one finding, a CLI-chat resume dropping its tab, was withdrawn: 1d796cb shows the window opens that tab once, through main. That review read the code only. It ran no tests. SSH has since been traced; see Notes.

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 paired servers:
    • Browser and simulator tabs in an SSH worktree go through this machine's main, like any local workspace.
    • Chats in a plain SSH worktree: none can run there. No runtime serves an ssh: owner (structured-agent-session-owner.ts:15-25, runtime-client-target.ts:55-66), so a launch there takes the terminal route (agent-launch-route-input.test.ts, "never consults the local project runtime for a worktree on an SSH connection"). The new test in content-tabs-paired-server-workspace.test.ts checks that an SSH worktree has no chat owner. So none of the chat open, close or three-fix paths reach SSH.
    • SSH worktrees served by a managed server: owned by runtime: and handled as a paired server's workspace. That workspace keeps today's path for browser and chat tabs, and main never lays it out (runtime-layout-apply.ts:71-73 answers host_not_owned; content-tabs-paired-server-workspace.test.ts).
    • The three fixes on those workspaces:
      • The refused-close reopen applies only to this machine's chats (tabs-close-actions.ts:84-87); a paired server's chat comes back through today's re-read, as the e2e "does not bring a paired server's closed chat back either" covers.
      • Main's placement of a window's chat and the hidden-slot hold act only on workspaces main draws.
      • The declined-chat move falls back to today's window move when main is not asked (structured-agent-session-action-launch.ts:194-224).
  • Wire: isPinned is a new optional field on moveTab. Only the local window sends it, and only to its own main.
  • Merging main after 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: git's automatic merge used the older base 7dfcfbf. In workspace-layout-group-commands.ts it silently produced a duplicate moveTab block (the same-file tab_exists check, twice). I redid every D3b file as a three-way merge against a75b039, the base this branch was built on. The diff from main now matches D3b's original diff line for line, and every file D3b does not touch equals main. The merge also brought in main's new workspace-record-read ratchet, so content-tab-open-placement.ts now reads folder workspaces through selectFolderWorkspaces.
  • Folder workspaces: handled the same as git worktrees.
  • Phones: main's diff and markdown-preview rows match the window's rows (session-tab-rows-main-window-parity.test.ts). For a diff tab the window lists, the window's own row still wins, so isDirty is not lost.
  • Changes the owner will see with the switch on:
    • a browser, chat or simulator tab appears, and is selected, one main round-trip later;
    • a close lands with main's update;
    • a tab whose group main lacks opens in the first group;
    • a declined chat's terminal keeps the chat's pin in one move.
  • Fixed in this PR before opening: a switch-on background browser open had set the worktree's remembered browser tab; it now leaves it unset, as switch-off does.
  • Open:
    • L196a is not done. The chat-eligibility facts are window-only (the pane's foreground agent, the agent read from the title, the hint leaf, and the active leaf and exit). A proposal is in the lane notes.
    • Main can't yet build isDirty for a diff row, or rows for conflict-review and check details. The window's rows cover these until reportView carries the draft versions.
    • Within one process, editor views follow their tab. A WSL move or a managed-server move does not carry them (as in 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).
    • An unlabelled chat in main's layout is assumed to be local.
    • The host's chat listing still builds a tab-structure patch and discards it, because phone close and focus depend on records it updates along the way.
  • Ledger: closes L146, L147, L150, L153, L155, L194, and the switch-on local part of L156. Keeps L149 and L154, which stay while ids are window-proposed. Updates L263's caller list as above.

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)

E2E Test and others added 30 commits October 20, 2026 10:17
…reading its session back (dark, layout-owner build only)

A records frame no longer re-serializes the window's whole session and runs the
Loader. Panes' terminal bindings and live titles apply alone, to the tabs the
frame names; any other record builds only its own workspace's slices, with the
view and facts read from the store. Only a workspace the store does not show
from frames yet (startup, a reopened stream, a first visit, one sent whole)
takes the full build.

Tests install an apply check that, after every flush, compares the store with
the full build for the same cache and pre-flush store; the shared layout-apply
transport now sends main's records frames and fails a flush that differs.
…ack or running the Loader (test, layout-owner build only)
…ing generations, so it passes with the switch on (test only)
…ave's own writers, as the full build does (dark, layout-owner build only)
… builds one in full, and the shared transport keeps a test's own check (test only)
…ld, and the shared transport restores only the check it installed (test only)
…s the open file it lacks from it

Main's in-memory editor view now carries the file facts an open file needs; it rides the tab row
(PublishedTab.editorView) and a frame build rebuilds a diff, conflict, preview or check-details tab.
Inert with the switch off: views are set only by layout.apply (switch builds) and read only in frame-sync.
…ons to main and draws the tabs from its frames

Layout-owner build only; the switch-off path is unchanged. An open proposes the tab id and sends
openEditorTab with the edit file's record or the tab's view (a reopen also its index); the open
file is written at once and the tab is selected once its frame draws it. Callers that act on the
tab (focus request, link reveal, group focus) wait for that frame through layout-owner-pending-tabs.
A close sends closeTabs; the tab goes with the frame and the file's content after it, and a
refusal keeps both. A promotion sends promotePreviewTab and the frame clears the flag. Deleted:
the drawn editor senders, their before/after captures, the editor drawn-tab holds and the
window-record keep rule (a transient tab is kept by its frame view).
…draw

# Conflicts:
#	src/renderer/src/runtime/layout-apply-test-transport.test-fixture.ts
#	src/renderer/src/runtime/workspace-layout-frame-builds.ts
#	src/renderer/src/runtime/workspace-layout-frame-pending.ts
…k names its group, and main stamps an open's time

Layout-owner build only. After main's frame drops a closed editor tab, the window selects the
group's previous tab and its surface through activateTab and focusGroup, after closeFile's
content cleanup rather than before it; a reopen sent while the close was in flight keeps the
file. openFileForLink's proposed view names the group the open asked for. The window's
openEditorTab sends no createdAt: main stamps the tab's time (ledger L186). Preview promotion
writes no tab itself: the window ends a preview only where a paired server owns the layout.
… and frame (test only)

Each store and hook test that assumed an immediate editor-tab draw now runs with main's model
through the T1 transport in apply mode and its frames (tabs-drawn-from-main.test-fixture), and
asserts the tab, its selection and its content after main's frame. The fixture fills the frame
slices a partial editor-and-tabs store lacks.
…ab's path, and keeps one tab per file per group

Layout-owner build only (the switch gates every change; shipped builds unchanged). moveTabToWorkspace no
longer skips a tab "the window's save got there first" (L160): window saves no longer carry the move, so
a repeat is tab_not_found; tab_exists and invalid_params stay. A move or rename may carry a non-plain
tab's new view (its file under the new path or owner), which replaces editorViews[tab] (L180). Main
refuses a moveTab or moveTabToWorkspace that would put a second tab for a file into a group (tab_exists),
and its loader folds a saved session's duplicate into the first, as the window's restore does
(dedupeEditorTabsWithinGroups): the window's frame dedupe hid the second, which no close could reach.
…ands, and the frame that shows them rekeys the content

Layout-owner build only; the switch-off path is unchanged. A restored editor tab re-owned by its
file's workspace (L157, L158) sends moveTabToWorkspace (a re-own in place sends renameEditorFiles)
under the ids and group the window proposes, with each view tab's new view; a disk rename (L180)
sends renameEditorFiles per workspace and draws nothing first. The window's content rekey (open
file records, drafts, buffers, the editorBuffers echo gate, pendingLiveDiskVerification and
pendingSelfMoveEcho) waits in layout-owner-content-rekeys and the frame flush that first shows main's
change applies it, in the same store update as the frame (a flush now writes one patch). A change no
tab shows is rekeyed on main's answer; a refusal drops it and changes nothing. The move coordinator
and the restored-owner loader wait for that outcome; a refused rename rolls the disk move back.
A rename picks a runtime-owned or floating file's owned id, as main's frames restore it.

Deleted: recordRestoredEditorMoveInLayoutOwner, recordRenamedEditorFilesInLayoutOwner, the
reparent's before/after capture and the drawn-tab holds for moves and renames. Tests that assumed
the window moves or renames first now run through main's T1 transport in apply mode and its frames.
…r the switch-on move, rename and gap fixes

Layout-owner build only. The content rekey's pure store change stays in rekey-open-files-action
(its writer count drops 4 -> 2, pruned); a twin tab main routes to a paired server ends its
preview through patchTab, the existing tab writer, instead of a new one; a frame-only editor tab
takes its label through the frame build's tab-label facts, read from its view or file record; the
moved file's activation names the moved tab, writing no surface field. Test casts are typed or carry
a SAFETY note.
…argument, so the two modules do not import each other

Layout-owner build only; no behaviour change. Clears the static gate's no-cycle finding.
… closes and page changes to main and draws them from its frames

Main places the chats its host lists (twin h), a local cancel keeps no tombstone (L155), and the
listing no longer writes chat tab structure where frames draw it (L153).

Co-Authored-By: Claude <[email protected]>
…'s frame, lands an emptied workspace as today, and its tests read main's frames
…ch-on local cancel through main, with a presence precondition and per-test resets
…irst group, not beside the window's anchor (L150)
…e files the writer ratchet counts them in, and a drawn browser close carries its position instead of a rebuilt layout
…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.
The shared close joins a close already in flight and marks its ask as a close; the editor file's
close keeps closeFile's per-file cleanup from D3a-2.
…e tab's content as tab_not_found does, and placement reads a missing active-group map safely
…n's command and draw from its frame (test only)
…nset through the restore projection's own rule, not a second write
… no wait; only the switch-on move waits for main
…window's own open, so a reserved chat slot keeps its place (switch-on)
…eue reaches it, through the one rule the switch-off save uses, so a close right after an open closes it
…s main draws, not past a hidden launch slot, so it still replaces the chat (switch-on)
…ow wins, and a test shows a window-listed diff keeps its dirty state (comments and test only)
…he fields main's frame keeps; no caller reads more
…wn-from-main store fixture as a support bridge (test only)
…as a saved session, and one failed change no longer stops the ones after it (switch-on)
…d the batches after it still land (switch-on)
…ugh main, after the tab before its hidden slot (test only)
…he chat open, close or fix paths reach it (test only)
@Jinwoo-H
Jinwoo-H changed the base branch from fd/d3a2-editor-frame-draw to main October 21, 2026 16:39
@coderabbitai

coderabbitai Bot commented Oct 21, 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

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: d299bcfd-703b-446c-be24-32739ff41c5e
📥 Commits

Reviewing files that changed from the base of the PR and between e97d564 and 23e837d.

📒 Files selected for processing: 2
  • src/main/runtime/runtime-layout-apply.ts
  • src/renderer/src/runtime/layout-apply-send.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/main/runtime/runtime-layout-apply.ts

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

📝 Walkthrough

The change routes browser, chat, and simulator tab operations through the main layout owner when enabled. It adds queued chat-layout updates, placement and close coordination, and pending-tab facts. Structured-agent session publication and cancellation handling are updated. Session-row projections now include editor and diff views. Tests across runtime and renderer areas use main-drawn layouts and wait for frame updates.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 23e83

A drawing failure in a narrow fallback path can block later opens for the same entity. The change is otherwise mergeable with this bounded recovery risk noted.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 49.06% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 106 functions across 74 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 identifies the main change: browser, chat, and simulator tabs now use main-first layout ownership. It is somewhat long but specific and relevant.
Description check Passed The description is detailed and covers the change, rationale, testing, visual proof, compatibility considerations, limitations, and checklist. The linked issue is described textually but does not incl…
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 detailed and covers the change, rationale, testing, visual proof, compatibility considerations, limitations, and checklist. The linked issue is described textually but does not include an actual issue number or link, and the AI Disclosure heading is omitted; these omissions do not make the otherwise complete description largely incomplete.

✨ 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: 3


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 43312239-c709-41a5-8f94-f7b7fa2799e0
📥 Commits

Reviewing files that changed from the base of the PR and between cfd9e9c and 9f0a9e9.

📒 Files selected for processing: 244
  • config/renderer-layout-writer-baseline.txt
  • config/scripts/pr-unit-support-routing.test.mjs
  • 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/agent-session-tab-layout-command.test.ts
  • src/main/runtime/agent-session-tab-layout-queue.test.ts
  • src/main/runtime/agent-session-tab-layout-queue.ts
  • src/main/runtime/agent-session-tab-layout.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/structured-agent-session-close-before-create.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-create-handler.ts
  • src/main/runtime/rpc/methods/structured-agent-session-create-window-placement.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-create.ts
  • src/main/runtime/rpc/methods/structured-agent-session.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/session-layout-apply.test-fixture.ts
  • src/main/runtime/session-tabs/main-session-tab-rows.test.ts
  • src/main/runtime/session-tabs/main-session-tab-rows.ts
  • src/main/runtime/session-tabs/structured-session-tab-close.ts
  • src/main/runtime/session-tabs/structured-session-tab-restoration.ts
  • src/main/runtime/structured-agent-session-windowless-layout-host.test.ts
  • src/main/runtime/structured-agent-session-windowless-layout.test.ts
  • src/main/runtime/terminal/launch/mobile-terminal-chat-fork.test.ts
  • src/main/runtime/workspace-layout-projection.ts
  • src/renderer/src/components/browser-pane/host-guest/browser-page-annotation-document.test.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/native-chat/structured-agent-session-status-bridge-unconfirmed-start.test.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionVirtualList.keyboard.test.tsx
  • src/renderer/src/components/tab-bar/cli-chat-resume-run.test.ts
  • 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/components/terminal/initial-terminal-admission-wait.test.tsx
  • src/renderer/src/components/worktree-jump-palette-browser-navigation.test.tsx
  • 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/ensure-simulator-tab-behavior.test.ts
  • src/renderer/src/lib/ensure-simulator-tab.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/launch-cancel-tombstones-compat/structured-agent-session-launch-cancellation.test.ts
  • src/renderer/src/lib/pane-manager/client-hosted-browser-row-ephemerality.test.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/lib/simulator-tab-layout-owner.test.ts
  • src/renderer/src/lib/simulator-tab-layout-owner.ts
  • src/renderer/src/lib/structured-agent-session-action-launch.ts
  • src/renderer/src/lib/structured-agent-session-launch-admission.test.ts
  • src/renderer/src/lib/structured-agent-session-launch-close-race.test.ts
  • src/renderer/src/lib/structured-agent-session-launch-registry.ts
  • src/renderer/src/lib/structured-agent-session-launch-surface.ts
  • src/renderer/src/lib/structured-agent-session-local-launch-cancel.ts
  • src/renderer/src/lib/structured-agent-session-new-chat-own-launch.test.ts
  • src/renderer/src/lib/structured-agent-session-provisional-tab.test.ts
  • src/renderer/src/lib/structured-agent-session-provisional-tab.ts
  • src/renderer/src/lib/structured-agent-session-tab-open-through-layout-owner.ts
  • src/renderer/src/runtime/agent-session-tab-layout-owner.test.ts
  • src/renderer/src/runtime/agent-session-tab-layout-owner.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-content-tab-open.ts
  • src/renderer/src/runtime/layout-owner-drawn-tab-placement.test.ts
  • src/renderer/src/runtime/layout-owner-drawn-tab-placement.ts
  • src/renderer/src/runtime/layout-owner-pending-tab-facts.ts
  • src/renderer/src/runtime/layout-owner-pending-tabs.ts
  • src/renderer/src/runtime/local-structured-session-tabs-sync/frame-drawn-chat-tabs.test.ts
  • src/renderer/src/runtime/local-structured-session-tabs-sync/frame-drawn-chat-tabs.ts
  • src/renderer/src/runtime/local-structured-session-tabs-sync/inventory-refresh.ts
  • src/renderer/src/runtime/local-structured-session-tabs-sync/snapshot-apply.ts
  • src/renderer/src/runtime/restored-editor-move-reload.test.ts
  • src/renderer/src/runtime/session-tab-rows-main-window-parity.test.ts
  • src/renderer/src/runtime/structured-agent-session-tab-retirement.ts
  • src/renderer/src/runtime/structured-launch-cancel-layout-owner.test.ts
  • src/renderer/src/runtime/sync-runtime-graph-conversion-publish.test.ts
  • src/renderer/src/runtime/workspace-layout-frame-bindings.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/agent-status.test.ts
  • src/renderer/src/store/slices/browser-annotation-retention.test.ts
  • src/renderer/src/store/slices/browser-cleanup-close.test.ts
  • src/renderer/src/store/slices/browser-layout-owner-commands.test.ts
  • src/renderer/src/store/slices/browser-mount-admission-removal.test.ts
  • src/renderer/src/store/slices/browser-page-close-intent-recording.test.ts
  • src/renderer/src/store/slices/browser-page-conversion.test.ts
  • src/renderer/src/store/slices/browser-page-conversion.ts
  • src/renderer/src/store/slices/browser-remote-page-lifecycle.test.ts
  • src/renderer/src/store/slices/browser-remote-tab-creation.test.ts
  • src/renderer/src/store/slices/browser-slice-drawn-from-main.test-fixture.ts
  • src/renderer/src/store/slices/browser-slice-test-harness.ts
  • src/renderer/src/store/slices/browser-tab-creation-placement.test.ts
  • src/renderer/src/store/slices/browser-workspace-doc-location.test.ts
  • src/renderer/src/store/slices/browser-workspace-host-ownership.test.ts
  • src/renderer/src/store/slices/browser.test.ts
  • src/renderer/src/store/slices/browser/browser-close-actions.ts
  • src/renderer/src/store/slices/browser/browser-hydration-actions.ts
  • src/renderer/src/store/slices/browser/browser-hydration-state.ts
  • src/renderer/src/store/slices/browser/browser-layout-owner-commands.ts
  • src/renderer/src/store/slices/browser/browser-page-conversion-actions.ts
  • src/renderer/src/store/slices/browser/browser-page-create-actions.ts
  • src/renderer/src/store/slices/browser/browser-tab-actions.ts
  • src/renderer/src/store/slices/browser/browser-tab-close-through-layout-owner.ts
  • src/renderer/src/store/slices/browser/browser-tab-focus-actions.ts
  • src/renderer/src/store/slices/browser/browser-tab-open-through-layout-owner.ts
  • src/renderer/src/store/slices/content-tabs-from-main-frames.test.ts
  • src/renderer/src/store/slices/content-tabs-paired-server-workspace.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/native-chat-launch-draft-teardown.test.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/recently-closed-tabs.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-active-worktree-removal-successor.test.ts
  • src/renderer/src/store/slices/store-active-worktree-split-groups.test.ts
  • src/renderer/src/store/slices/store-active-worktree-tab-close.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/content-tab-close-through-layout-owner.ts
  • src/renderer/src/store/slices/tabs/content-tab-open-placement.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/structured-chat-close-owner.test.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/slices/workspace-attention/attention-removal-follow-up.ts
  • src/renderer/src/store/slices/workspace-attention/workspace-unread-removal-characterization.test.ts
  • src/renderer/src/store/slices/worktrees/listing/stale-listing-purges-created-worktree.test.ts
  • src/renderer/src/store/workspace-layout-frame-held-tabs.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/old-client/old-client-session-editor-rows.ts
  • src/shared/workspace-layout/old-client/old-client-session-row-ids.ts
  • src/shared/workspace-layout/old-client/old-client-session-tab-rows.ts
  • src/shared/workspace-layout/old-client/old-client-session-tabs-projection.ts
  • src/shared/workspace-layout/workspace-layout-browser-commands.test.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-move-tab-pin.test.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-tab-commands.ts
  • src/shared/workspace-layout/workspace-layout-workspace-move.test.ts
  • src/shared/workspace-layout/workspace-layout-workspace-move.ts
  • tests/e2e/cross-version-wire/structured-agent-session-surface-execution.ts
  • tests/e2e/layout-compat-baselines.json
  • tests/e2e/layout-compat-old-phone-on-new-server.spec.ts
  • tests/e2e/structured-session-tab-close-regressions.unit.test.ts
💤 Files with no reviewable changes: 5
  • src/renderer/src/runtime/agent-session-tab-layout-owner.test.ts
  • src/renderer/src/runtime/layout-owner-drawn-tab-placement.ts
  • src/renderer/src/runtime/workspace-layout-frame-bindings.ts
  • src/renderer/src/runtime/agent-session-tab-layout-owner.ts
  • src/renderer/src/runtime/layout-owner-drawn-tab-placement.test.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.

Comment on lines +49 to +52
asToday: () => {
release()
settle(open.drawHere())
},

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

Settle the pending tab when drawHere throws.

The asToday handler calls settle(open.drawHere()). If drawHere() throws, settle never runs, and the entry stays in layout-owner-pending-tabs for good. Two consequences follow:

  • hasPendingEntityTab returns true for that chat forever. openAgentSessionTabThroughLayoutOwner then returns the tab without sending an open.
  • openingSimulatorTabId keeps returning the dead id. ensureSimulatorTab then never opens a simulator tab for that worktree.

The apply handler here and openEditorTabThroughLayoutOwner already use try/finally for this reason ("A throwing selection must not leave the tab pending"). Use the same guard here.

🛡️ Proposed fix
--- "a/src/renderer/src/runtime/layout-owner-content-tab-open.ts"
+++ "b/src/renderer/src/runtime/layout-owner-content-tab-open.ts"
@@ -46,10 +46,15 @@
         settle(shownId)
       }
     },
     asToday: () => {
       release()
-      settle(open.drawHere())
+      let shownId: string | null = null
+      try {
+        shownId = open.drawHere()
+      } finally {
+        settle(shownId)
+      }
     },
     refused: () => {
       release()
       settle(null)
📝 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
asToday: () => {
release()
settle(open.drawHere())
},
asToday: () => {
release()
let shownId: string | null = null
try {
shownId = open.drawHere()
} finally {
settle(shownId)
}
},


/** Kept until the release, which is a no-op once a later expectation for the tab replaced it. */
export function expectTabFacts(facts: PendingTabFacts): () => void {
pending.set(facts.tabId, facts)

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

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect expectation callers and the tab IDs they pass.
rg -n -C 6 -F 'expectTabFacts(' src/renderer/src
rg -n -C 5 'tabId:|tabId =' \
  src/renderer/src/store/slices/editor/tabs/editor-tab-open-through-layout-owner.ts \
  src/renderer/src/store/slices/browser/browser-tab-open-through-layout-owner.ts \
  src/renderer/src/lib/structured-agent-session-tab-open-through-layout-owner.ts

Repository: stablyai/orca

Length of output: 10509


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- expectTabFacts callers ---'
rg -n -C 12 -F 'expectTabFacts(' src/renderer/src || test "$?" -eq 1
printf '%s\n' '--- ID constructors and uses ---'
rg -n -C 8 -F 'function structuredAgentSessionTabId' src/renderer/src src || test "$?" -eq 1
rg -n -C 8 -F 'structuredAgentSessionTabId' src/renderer/src || test "$?" -eq 1
rg -n -C 8 -F 'function createBrowserUuid' src/renderer/src src || test "$?" -eq 1
rg -n -C 8 -F 'createBrowserUuid' src/renderer/src | head -240 || true
printf '%s\n' '--- tab ID uniqueness and structured tab ID tests/contracts ---'
rg -n -i -C 4 'unique.*tab|tab.*unique|tab id|tabId' src/renderer/src/lib src/renderer/src/store src/renderer/src/runtime --glob '*.{ts,tsx}' | head -320 || true

Repository: stablyai/orca

Length of output: 42426


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- structured agent layout-owner open ---'
sed -n '1,220p' src/renderer/src/lib/structured-agent-session-tab-open-through-layout-owner.ts
printf '%s\n' '--- structured agent callers and session/worktree inputs ---'
rg -n -C 10 -F 'openAgentSessionTabThroughLayoutOwner' src/renderer/src src/shared || test "$?" -eq 1
rg -n -C 8 -e 'sessionId:.*worktree|worktreeId:.*sessionId|sessionId.*worktreeId' src/renderer/src src/shared --glob '*.{ts,tsx}' | head -240 || true
printf '%s\n' '--- createBrowserUuid binding ---'
rg -n -C 6 -F 'createBrowserUuid' src/renderer/src src/shared --glob '*.{ts,tsx}' | head -180 || true
printf '%s\n' '--- structured session identity declarations ---'
rg -n -C 8 -e 'type .*Session.*Open|interface .*Session.*Open|sessionId.*string|worktreeId.*string' src/shared/structured-agent* src/renderer/src/lib/structured-agent* --glob '*.{ts,tsx}' | head -280 || true

Repository: stablyai/orca

Length of output: 41942


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- pending entity-tab guard ---'
rg -n -C 12 -F 'function hasPendingEntityTab' src/renderer/src/runtime src/renderer/src || test "$?" -eq 1
rg -n -C 8 -F 'hasPendingEntityTab(' src/renderer/src/runtime src/renderer/src/lib | head -160 || true
printf '%s\n' '--- pending facts overlay ---'
sed -n '1,180p' src/renderer/src/runtime/layout-owner-pending-tab-facts.ts

Repository: stablyai/orca

Length of output: 10832


Key pending tab facts by worktree and tab ID.

hasPendingEntityTab suppresses duplicate opens only within the same worktree. Two worktrees can therefore open the same sessionId, which produces the same tabId. The second pending.set replaces the first, so withPendingTabFacts cannot provide the first worktree’s facts.

Use both worktreeId and tabId for pending-fact storage, lookup, and release.

Comment on lines +38 to +42
const reopened =
hasPendingEntityTab(file.worktreeId, file.fileId) ||
(get().unifiedTabsByWorktree[file.worktreeId] ?? []).some(
(tab) => tab.entityId === file.fileId
)

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

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Does the frame store patch replace openFiles/editorDrafts wholesale (which would mask the leak)?
rg -n -C5 'openFiles|editorDrafts' --type=ts -g '*workspace-layout-frame-store-patch*' -g '*workspace-layout-frame-builds*'
fd -i 'frame-store-patch' src | xargs -r rg -n 'openFiles'

Repository: stablyai/orca

Length of output: 9117


The pending-close path can be mistaken for a reopen. hasPendingEntityTab includes pending opens and pending closes, so the cleanup waiter can skip cleanUp() after the file’s own close request is registered. Count only pending opens when computing reopened.

@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: b9475b8d-24ed-408b-b0fa-1ea07d0eb9a4
📥 Commits

Reviewing files that changed from the base of the PR and between 78a2d24 and 7bf2dd2.

📒 Files selected for processing: 4
  • src/main/runtime/runtime-layout-apply.ts
  • src/renderer/src/runtime/structured-agent-session-tab-retirement.ts
  • src/renderer/src/store/slices/store-active-worktree-split-groups.test.ts
  • src/shared/workspace-layout/old-client/old-client-session-tabs-projection.ts
💤 Files with no reviewable changes: 1
  • src/shared/workspace-layout/old-client/old-client-session-tabs-projection.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • src/main/runtime/runtime-layout-apply.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 +162 to +169
reacceptHostSessionTabs(
args.target,
args.worktreeId,
intentOwner,
!hostTabClosed && args.reopen
? { sessionId: args.sessionId, reopen: args.reopen }
: undefined
)

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

🔎 Supported by static analysis

🏁 Script executed:

sed -n '75,185p' src/renderer/src/runtime/structured-agent-session-tab-retirement.ts
sed -n '45,115p' src/renderer/src/store/slices/tabs/tabs-close-actions.ts
rg -n 'beginStructuredAgentSessionTabClose|reopen:' src/renderer/src/runtime src/renderer/src/store/slices/tabs

Repository: stablyai/orca

Length of output: 10349


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- tabs-close-actions caller ---'
sed -n '1,145p' src/renderer/src/store/slices/tabs/tabs-close-actions.ts
printf '%s\n' '--- retirement owner and close ---'
sed -n '1,90p' src/renderer/src/runtime/structured-agent-session-tab-retirement.ts
printf '%s\n' '--- reopenChatTab definitions/usages ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'function reopenChatTab' -e 'const reopenChatTab' -e 'reopenChatTab' src/renderer/src
printf '%s\n' '--- focused tests ---'
sed -n '1,360p' src/renderer/src/runtime/structured-agent-session-tab-retirement.test.ts
sed -n '1,340p' src/renderer/src/runtime/structured-launch-cancel-layout-owner.test.ts

Repository: stablyai/orca

Length of output: 34461


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- closeUnifiedTab remainder ---'
sed -n '135,360p' src/renderer/src/store/slices/tabs/tabs-close-actions.ts
printf '%s\n' '--- local inventory refresh ---'
rg -n -F --glob '*.ts' -e 'refreshLocalStructuredSessionWorktreeTabs' -e 'reacceptCurrentVersion' src/renderer/src/runtime src/renderer/src
printf '%s\n' '--- refresh implementation ---'
rg -l -F --glob '*.ts' 'refreshLocalStructuredSessionWorktreeTabs' src/renderer/src | while read -r f; do echo "FILE $f"; sed -n '1,260p' "$f"; done
printf '%s\n' '--- layout close helper ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'closeContentTabThroughLayoutOwner' -e 'closeTabThroughLayoutOwner' src/renderer/src

Repository: stablyai/orca

Length of output: 41892


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- layout owner close helper ---'
sed -n '1,180p' src/renderer/src/store/slices/tabs/content-tab-close-through-layout-owner.ts
printf '%s\n' '--- provisional tab opener ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'openStructuredAgentSessionProvisionalTab' src/renderer/src
rg -l -F --glob '*.ts' 'openStructuredAgentSessionProvisionalTab' src/renderer/src | while read -r f; do echo "FILE $f"; rg -n -F -C 20 -- 'openStructuredAgentSessionProvisionalTab' "$f"; done
printf '%s\n' '--- close helper usages/tests ---'
rg -n -F --glob '*.test.ts' --glob '*.test.tsx' -e 'closeContentTabThroughLayoutOwner' -e 'layout owner' src/renderer/src/store src/renderer/src/runtime
printf '%s\n' '--- main close/open handlers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'session.tabs.close' -e 'session.tabs.list' -e 'agentSession.reveal' src | head -200

Repository: stablyai/orca

Length of output: 41940


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- provisional opener body ---'
sed -n '140,215p' src/renderer/src/lib/structured-agent-session-launch-surface.ts
printf '%s\n' '--- layout apply sender ---'
sed -n '1,280p' src/renderer/src/runtime/layout-apply-send.ts
printf '%s\n' '--- pending tab state ---'
sed -n '1,300p' src/renderer/src/runtime/layout-owner-pending-tabs.ts
printf '%s\n' '--- layout apply/frame consumers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'pendingTab' -e 'isPendingTab' -e 'closeTabs' src/renderer/src/runtime src/renderer/src/store | head -240
printf '%s\n' '--- close race tests ---'
sed -n '1,300p' src/renderer/src/lib/structured-agent-session-launch-close-race.test.ts

Repository: stablyai/orca

Length of output: 35954


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- agent-session layout open helper ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'openAgentSessionTabThroughLayoutOwner' src/renderer/src
rg -l -F --glob '*.ts' 'openAgentSessionTabThroughLayoutOwner' src/renderer/src | while read -r f; do echo "FILE $f"; sed -n '1,240p' "$f"; done
printf '%s\n' '--- layout transport fixture and runtime command path ---'
sed -n '1,180p' src/renderer/src/runtime/layout-apply-test-transport.test-fixture.ts
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'layout.apply' -e 'sendLayoutApply' src/main src/renderer/src/runtime | head -160
printf '%s\n' '--- open-after-close sequencing tests ---'
rg -n -F --glob '*.test.ts' --glob '*.test.tsx' -e 'openAgentSessionTab' -e 'open after' -e 'close then open' -e 'reopen' src/renderer/src/store src/renderer/src/runtime src/renderer/src/lib | head -240

Repository: stablyai/orca

Length of output: 42286


Wait for the layout close before reopening the listed chat.

When closeTabs is still pending, openAgentSessionTabThroughLayoutOwner returns early for the same pending entity and sends no openAgentSessionTab command. The later close frame can then remove the tab, leaving the still-listed chat hidden. Defer the reopen until the pending entity close settles.

Suggested fix
+import { afterPendingEntityTabs } from './layout-owner-pending-tabs'
...
-              stillListed.reopen()
+              afterPendingEntityTabs(worktreeId, stillListed.sessionId, stillListed.reopen)

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