Skip to content

Replace three copied new-terminal tab-order blocks with the shared helper - #26771

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/tab-order-new-terminal
Oct 11, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/tab-order-new-terminal

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​114 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​111
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10 $\color{#cf222e}{\Huge{\mathbf{−}}}$​71 $\color{#cf222e}{\Huge{\mathbf{−}}}$​61

ELI5

When Orca opens a new terminal tab, it also saves the worktree's tab list with the new tab at the end. Three new-terminal paths each kept their own copy of that "put it at the end" code, and one copy had drifted: it forgot browser tabs. This PR deletes the three copies. All three now call the one shared function the agent-launch paths already use.

What Changed

The problem: three places held near-copies of the shared tab-placement function persistAgentLaunchTabOrder:

  1. createNewTerminalTab in terminal-tab-create.ts, used by the file explorer's right-click Open in Terminal on a folder. Its copy listed terminal and editor tabs when it saved the worktree's tab order, and left browser tabs out.
  2. handleNewTab's fallback in use-terminal-create-actions.ts. It runs when a terminal is opened with a specific shell, or the worktree has no tab group yet.
  3. The menu New Terminal fallback in tab-lifecycle-ipc-bridge.ts, used when the terminal is not created through a remote Orca host.

Copies 2 and 3 matched each other line for line. Copy 1 was the one that drifted.

User-facing change: none expected in the normal tab strip. I checked this before writing the PR:

  • The visible tab strip (TabGroupPanel) draws from the tab group's own order. It does not read the worktree-level saved order (tabBarOrderByWorktree) that these three paths write. createTab always puts the new terminal at the end of the group order, so on main the new terminal already shows last and other tabs stay put.
  • The worktree-level saved order is read only by fallbacks for a worktree that has no tab group yet. Those fallbacks are the legacy titlebar tab strip and its "Close Others / Close to the Right / Close to the Left" actions, plus keyboard and mobile tab navigation when no group is active. Opening a worktree creates its group, so these fallbacks are rarely reached. When they are, path 1's saved order now includes browser tabs.

Behaviour differences, both intended:

  • Path 1 now includes browser tabs in the saved order. That is the drift this PR fixes.
  • Repeated ids are dropped (paths 2 and 3). If an already-saved order lists the same tab twice, the shared function keeps only the first. Copies 2 and 3 kept both. Copy 1 already went through the same reconcile function, so it already dropped them. For example, a saved order [browser, terminal, browser] plus a new terminal used to save [browser, terminal, browser, new] and now saves [browser, terminal, new]. A repeated id is already a broken state: the shared reconcile function drops repeats so the tab bar never shows the same tab twice. I compared copies 2 and 3 with the shared function line by line, and this is their only difference. Both read the store after the tab is created, append missing tabs in the same order (terminals, editors, browsers), move the new tab last, and call the same store action.

Mechanism: each copy is replaced by persistAgentLaunchTabOrder(worktreeId, newTab.id). use-terminal-create-actions.ts no longer needs the setTabBarOrder store binding, so this PR removes it from use-terminal-workspace-store-bindings.ts; nothing else read it.

Line delta: across the four source files, +10 / −71 (net −61). The tests add 114 lines and remove 3.

This PR changes nothing about how agents are launched or how they receive prompts. The paired web-client path, where the host creates the terminal, returns before this code and is unchanged.

Why

The copies had already drifted, which is how path 1 lost browser tabs. Pointing every copy at one function keeps the next fix to tab placement in one place. Adding browser ids to copy 1 alone would have left three versions to drift again.

The shared function's name still says "agent launch", although it now covers general new-tab placement. I'm leaving the rename for later, because it would touch files in open launch PRs.

Copies this PR leaves alone. Searching for the same pattern turns up three more places that build the saved order inline. All three live inside store actions:

  • openNewTerminalTabInActiveWorkspace in store/terminals/terminal-active-workspace-creation.ts, the group path behind "+", Cmd+T and Cmd+J. It behaves the same as the old copies, including keeping repeated ids. I left it because it runs inside the store, and the shared function is a module outside the store that imports the store. Moving the shared function into the store is the follow-up.
  • createBrowserTab in store/slices/browser/browser-tab-actions.ts and the new-file path in store/slices/editor/actions/open-file-apply.ts behave differently. They build the order inside the store update itself and append a tab id that is not in the store yet, so the shared function cannot serve them as written.

Linked Issue

N/A (maintainer follow-up to #26704).

Visual Proof

N/A. Nothing visible changes in the normal tab strip (see above), and each changed path has a unit test.

Testing

Each changed path has its own unit test:

  • terminal-tab-actions.test.ts: Open in Terminal, with one terminal, one open browser tab and no saved order, saves [terminal, browser, new terminal]. On main's code it fails because the browser tab is missing.
  • use-terminal-create-actions.test.tsx (new test): the shell-override fallback, given the saved order [browser, terminal, browser], saves [browser, terminal, new terminal].
  • tab-lifecycle-ipc-bridge.test.ts (new file): the menu New Terminal fallback, with the same input and the same expected result.
  • I ran the two new tests against the old inline copies. Both fail, and the only mismatch is the kept repeat browser. That confirms the repeated-id drop is the only difference on those paths. With this change, all of them pass.

Gates:

  • pnpm tc:web passes.

  • orca-ci-checks --no-typecheck passes.

  • I ran four test files by name: the three above plus useIpcEvents-terminal-create-surfacing.test.ts. All 38 tests pass.

  • A fresh reviewer checked the full diff for any behaviour change beyond the two differences above and found none. Its two notes (wording, and the copy left in terminal-active-workspace-creation.ts) are addressed above.

  • Not tested by hand in the running app; nothing on screen changes.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Renderer-only tab-order change with no platform-specific code. SSH and folder workspaces go through the same local path as before, and the paired web/mobile host path is untouched.

Known gap, not changed here: the shared function also leaves simulator tabs and native chat tabs out of the saved order. Every caller had that gap before this PR, and it is a candidate follow-up.

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)

Author: @BrennanKB5

The + new-terminal path kept its own copy of the tab-order placement and
left browser tabs out, so in a workspace with no saved order a browser tab
could land after the new terminal. Use the shared persistAgentLaunchTabOrder
helper instead.
@brennanb2025 brennanb2025 changed the title Keep browser tabs in place when + opens a new terminal Use the shared tab-placement helper for file explorer Open in Terminal Oct 9, 2026
handleNewTab's shell-override fallback and the menu new-terminal IPC
fallback each kept an inline copy of the "put the new tab last" order
logic. Both now call persistAgentLaunchTabOrder. The one behaviour
difference: the shared reconcile drops ids repeated in a saved order,
where the copies kept them.
@brennanb2025 brennanb2025 changed the title Use the shared tab-placement helper for file explorer Open in Terminal Replace three copied new-terminal tab-order blocks with the shared helper Oct 10, 2026
@brennanb2025
brennanb2025 marked this pull request as ready for review October 10, 2026 01:24
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review and checks, head c7c7cc2

  • Review: a fresh reviewer read the full diff with one question: does behaviour change beyond the two stated differences? Those differences are that "Open in Terminal" now includes browser tabs, and that the menu and shell-override fallbacks drop repeated ids. The reviewer found nothing else. It checked append order, which store snapshot is read, the single setTabBarOrder call, sequencing around setActiveTabType and focusTerminalTabSurface, the removed binding (no other readers), hook dependencies, and the floating, web-runtime, SSH and folder paths. It made two notes, both now handled in the body:
    • The repeated-id drop is new only for the two fallbacks; "Open in Terminal" already went through the same reconcile function.
    • The store-internal copy in terminal-active-workspace-creation.ts is left alone. It is listed in the body with the reason.
  • Tests: the two new tests fail against the old inline copies, and the only mismatch is the kept repeated id. With this change, all 38 tests in the four affected files pass.
  • Local gates: pnpm tc:web and orca-ci-checks --no-typecheck (22/22) pass.
  • CI: green, with every non-skipped check passing.
  • Manual UI pass: not run. Nothing on screen changes, and each changed path has a unit test.

@coderabbitai

coderabbitai Bot commented Oct 10, 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: 416ff643-a72d-4c92-a7f8-f4e4dae53459

📥 Commits

Reviewing files that changed from the base of the PR and between 59631b8 and c7c7cc2.


📒 Files selected for processing (7)
  • src/renderer/src/components/terminal/terminal-tab-actions.test.ts
  • src/renderer/src/components/terminal/terminal-tab-create.ts
  • src/renderer/src/components/use-terminal-create-actions.test.tsx
  • src/renderer/src/components/use-terminal-create-actions.ts
  • src/renderer/src/components/use-terminal-workspace-store-bindings.ts
  • src/renderer/src/hooks/ipc-events/tab-lifecycle-ipc-bridge.test.ts
  • src/renderer/src/hooks/ipc-events/tab-lifecycle-ipc-bridge.ts

💤 Files with no reviewable changes (1)
  • src/renderer/src/components/use-terminal-workspace-store-bindings.ts

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



📝 Walkthrough

Walkthrough

Terminal creation through component actions and the new-terminal-tab IPC path now delegates saved tab-order updates to persistAgentLaunchTabOrder. The workspace store bindings no longer expose setTabBarOrder. Tests cover saved order when no order exists and when it contains repeated tab IDs.


Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to c7c7c

The tab-order change is ready to merge after normal checks; no actionable risk remains identified.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: replacing three duplicated new-terminal tab-order implementations with the shared helper.
Description check Passed The description is complete and directly aligned with the template. It explains the user impact, implementation, rationale, linked issue context, visual proof, tests, known limitations, and checklist …
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.


  • Fix all pre-merge checks with AI
✨ 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.

@brennanb2025
brennanb2025 merged commit c07b045 into main Oct 11, 2026
54 checks passed
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