Skip to content

fix(floating-workspace): keep agent launches from moving the main window's tab - #22603

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/fix-floating-agent-launch-main-tab
Sep 24, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/fix-floating-agent-launch-main-tab

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 73 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​372 $\color{#cf222e}{\Huge{\mathbf{−}}}$​157 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​215
Prod 44 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​100 $\color{#cf222e}{\Huge{\mathbf{−}}}$​133 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33

ELI5

When you launch an agent from the floating workspace's + menu, the main window behind it jumped away from whatever you were looking at (a chat, a README, any non-terminal tab) and showed its own terminal instead. Now the new agent opens in the floating panel and the main window stays where you left it.

What Changed

Before: main window on README.md (or a chat tab) → floating panel + → OpenCode → the main window switches to its active terminal tab.

After: the same steps leave the main window on README.md. The new agent tab is selected and running in the floating panel. Launching from the main window's own + menu still brings the new terminal to the front, as before.

Mechanism. The main window's selection (activeTabType, activeTabId) belongs to the worktree the main window is showing. Every other store action that creates or moves a tab already respects this: browser tabs, editor tabs, splits, moves and drops only touch that selection when state.activeWorktreeId === worktreeId. Two places did not:

  • launchAgentInNewTab called setActiveTabType('terminal') with no worktree. With no worktree, that call targets the active one, so a launch into the floating workspace flipped the main window to terminals.
  • Terminal createTab wrote the global activeTabId for a new tab in any worktree, so the main window's "active terminal" became a floating tab.

Both now follow the same rule as the rest of the store. The launch still selects its tab within its own worktree, which is what the floating panel displays.

Three more launch paths had the same unscoped setActiveTabType('terminal') after creating a tab, and now name their worktree too: the paired-host agent launch (the call runs after the host's asynchronous create), Session History resume (it can target a worktree you are not viewing and switches to it only afterwards), and sleeping-agent resume (worktree activation runs it after asynchronous readiness checks, by which time you may have moved to another worktree).

The floating titlebar agent button had worked around this with an activate: false opt-out and then selected its tab by hand. That opt-out had no other caller, so it is removed and the button now just launches and focuses, like every other entry point. Every floating New Terminal entry point (the + menu, Cmd+T and the double-tap shortcut, whether the key lands on the panel or reaches the app menu) now goes through one creator that drops the same workaround: it creates the tab active in the floating group and focuses it. Before, the + menu and Cmd+T used two separate creators. That also moves the floating workspace's remembered tab to the new terminal; before, it stayed on the previously selected floating tab, and that remembered tab is what auto-acknowledge uses to decide which floating agent you are looking at.

Closing off the bug class. setActiveTabType now requires the worktree it applies to. A caller can no longer leave it out and silently target whichever worktree the main window is showing; a new unscoped call fails to compile. All 54 remaining callers now name their worktree. Where the call is by construction about the worktree on screen (keyboard shortcuts, the tab strip, the palette), nothing changes. A handful of paths could act on a tab in another worktree and now stop retyping the main window when that happens: a file dropped or a notebook opened from the browser after the user has switched worktrees mid-load, the New Terminal Tab command when the user switches worktrees while it is still resolving, a mobile emulator pane focus requested for a worktree the user is not viewing, and a split-pane focus on a paired client that lands after the user has moved on.

Regression point. The bug is not recent; it is as old as the floating terminal. It was introduced by #1724 (Add Floating Terminal, 2026-05-12). From that commit on, the floating panel's tab bar showed the shared agent launch items (showAgentLaunchItems defaulted to on), and those items called launchAgentInNewTab, which already made the unscoped setActiveTabType('terminal') call dating from #933. #21390 fixed only the floating titlebar button, and did it with the per-caller opt-out; it never covered the + menu. That is why v1.4.209 and the current release candidate behave the same.

Why

Fixing it in the store rule, rather than giving the floating + menu its own activate: false override, covers every floating entry point at once: the + menu's agent items, the + menu's New Terminal, and the titlebar button. It also removes a per-caller opt-out that each new floating launch point would otherwise have to remember. The alternative would have added a second guard next to the one the titlebar button already carried.

Requiring the worktree on setActiveTabType is what keeps the bug from coming back: every one of these regressions was a caller that forgot the worktree, and the compiler now asks for it. The main window's selection is still a separate stored copy, not read from the selection of the worktree it is showing. The activeWorktreeId === worktreeId check at each place that writes it is what keeps the two in step. Making the main window read the active worktree's own selection instead is a store-wide refactor, outside this fix.

One side effect is deliberate. Launching an agent into a worktree you are not looking at (for example from the dashboard or a source-control action) used to switch your current view to terminals. It now leaves your view alone. Switching to that worktree still lands on the new tab, because activation rebuilds the view from that worktree's own selection.

Linked Issue

No tracking issue. Reported from a screen recording of the floating workspace.

Visual Proof

Before (release candidate): main window on README.md, then OpenCode launched from the floating panel's + menu. The main window jumps to Terminal 2.

Before launch After launch
r210-03a-editor-active.png r210-04-editor-then-opencode.png

After (this branch): the same steps. The main window stays on README.md and OpenCode runs in the floating panel.

Before launch After launch
fix-01-before-launch.png fix-02-after-plus-menu-opencode.png

Testing

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

Manual (macOS, isolated dev build, background launch, driven through the real UI over CDP):

  • Floating + menu → OpenCode with the main window on README.md: the main window stays on README.md; the store still shows activeTabType: editor and the main window's active tab unchanged; the new tab is selected in the floating panel.
  • Floating titlebar agent button: the new tab is selected and has keyboard focus in the floating panel; the main window stays on the editor.
  • Main window + menu → OpenCode: the main window switches to the new OpenCode tab, as before.

Automated:

  • New launch-agent-in-new-tab-main-surface.test.ts runs the real launcher against a real store: a floating launch leaves the main window's tab type and active tab unchanged and selects the tab in the floating group; a launch into the active worktree still brings it to the front. Reverting either half of the fix (the launcher's scoped call, or createTab's check) makes it fail on its own.
  • Updated placement, caller-census and floating-controls tests for the removed opt-out.
  • Sleeping-agent resume: a new real-store test resumes into a worktree the user has left and checks the current view is untouched while the resumed worktree remembers the new tab. The paired-host and Session History tests now check the call names the worktree. Each fails when its one-line fix is reverted.
  • Full renderer suite at the final head: 33,739 passed.
  • Store / lib / tab-bar / floating-terminal / hooks suites: 11,080 passed. Two palette-search timing-budget tests failed under full-run load and pass when run alone.
  • Web typecheck, oxlint, oxfmt, the changed-code quality gate and React Doctor all pass.
  • Required worktree on setActiveTabType: the tests that asserted the old one-argument call now assert the worktree each caller passes, and activate-tab-and-focus-pane.test.ts gains a case where the tab lives in a worktree other than the one on screen. End-to-end helpers that drive the store directly now pass the active worktree, which keeps their previous behaviour.
  • Floating New Terminal: new real-store test use-floating-terminal-create-actions.test.ts checks the main window's tab and tab type are unchanged, and the floating group's active tab and the floating workspace's remembered tab are both the new terminal. The + menu and Cmd+T share the creator it drives; with that creator reverted to the old workaround the test fails on the remembered tab (still the previous floating tab).
  • After these two commits: pnpm tc (node, web, cli) passes; the store and lib suites plus every touched test (980 files) and the hooks and components suites, floating-terminal included (2,731 files, 22,147 tests), pass; oxlint, oxfmt, the changed-code quality gate and React Doctor pass. The end-to-end typecheck reports no errors on changed lines (it has unrelated existing errors).

Not tested: Linux, Windows, SSH. The change is renderer store logic with no platform- or host-specific branches.

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no change.
  • Cross-platform: no platform-specific code.
  • SSH: paired-host launches now also name their worktree when the host's create lands. SSH worktrees shown in the main window go through the same store rule as local ones.
  • Mobile: nothing is sent to paired clients; this is local renderer selection state only.
  • Backwards compatibility: no persisted fields or wire changes.
  • Performance: one extra id comparison in createTab.

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)

…dow's tab

Launching an agent from the floating workspace's "+" menu switched the main
window off whatever chat or editor tab it was showing and onto its terminals.

The main window's selection is supposed to move only for the worktree it is
showing: browser and editor tab creation, splits, moves and drops all check
`activeWorktreeId === worktreeId` before touching it. Two places did not:

- `launchAgentInNewTab` called `setActiveTabType('terminal')` without a
  worktree, which targets the active worktree whatever worktree the launch
  landed in.
- terminal `createTab` wrote the global `activeTabId` for a tab in any
  worktree.

Both now follow the store rule. The launch still selects its tab within its
own worktree, which is what the floating panel renders.

The floating titlebar button had side-stepped this with an `activate: false`
opt-out plus manual selection. That opt-out had no other caller and is removed;
the button now launches and focuses like every other entry point.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 6cc49dbc-ede0-4bc8-b427-88bf56dde4d3

📥 Commits

Reviewing files that changed from the base of the PR and between 9581c66 and 0c8c227.

📒 Files selected for processing (104)
  • config/scripts/linux-wayland-terminal-exercise.mjs
  • src/renderer/src/components/TerminalTitlebarTabs.tsx
  • src/renderer/src/components/activity/activity-thread-actions.ts
  • src/renderer/src/components/automations/automation-run-workspace-action.ts
  • src/renderer/src/components/browser-pane/navigate/navigate-browser-page-url.ts
  • src/renderer/src/components/floating-terminal/FloatingTerminalPanel.shortcuts.test.tsx
  • src/renderer/src/components/floating-terminal/FloatingTerminalPanel.tab-lifecycle.test.tsx
  • src/renderer/src/components/floating-terminal/use-floating-terminal-create-actions.test.ts
  • src/renderer/src/components/floating-terminal/use-floating-terminal-create-actions.ts
  • src/renderer/src/components/floating-terminal/use-floating-terminal-panel-store-state.ts
  • src/renderer/src/components/right-sidebar/ai-vault-original-pane-actions.ts
  • src/renderer/src/components/tab-group/useTabGroupActivationCommands.ts
  • src/renderer/src/components/tab-group/useTabGroupCreationCommands.ts
  • src/renderer/src/components/tab-group/useTabGroupWorkspaceModel.focus.test.ts
  • src/renderer/src/components/terminal-pane/terminal-handle-links.test.ts
  • src/renderer/src/components/terminal-pane/terminal-handle-links.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-tab-detach.ts
  • src/renderer/src/components/terminal/terminal-tab-actions-kill-all.test.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.test.ts
  • src/renderer/src/components/terminal/terminal-tab-actions.ts
  • src/renderer/src/components/terminal/terminal-tab-create.ts
  • src/renderer/src/components/use-terminal-activation-actions.ts
  • src/renderer/src/components/use-terminal-create-actions.ts
  • src/renderer/src/components/use-terminal-editor-close-queue.ts
  • src/renderer/src/components/use-terminal-window-lifecycle.ts
  • src/renderer/src/hooks/automation-dispatch-handler.ts
  • src/renderer/src/hooks/ipc-events/mobile-terminal-close-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/tab-lifecycle-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/terminal-presentation-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/terminal-request-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-events/terminal-ui-routing-ipc-bridge.ts
  • src/renderer/src/hooks/ipc-tab-switch-structured-tab-cycle.test.ts
  • src/renderer/src/hooks/ipc-tab-switch.test.ts
  • src/renderer/src/hooks/ipc-tab-switch.ts
  • src/renderer/src/hooks/structured-session-completion-focus.test.ts
  • src/renderer/src/hooks/useGlobalFileDrop.ts
  • src/renderer/src/hooks/useIpcEvents-terminal-create-surfacing.test.ts
  • src/renderer/src/lib/activate-tab-and-focus-pane.test.ts
  • src/renderer/src/lib/activate-tab-and-focus-pane.ts
  • src/renderer/src/lib/ensure-simulator-tab-behavior.test.ts
  • src/renderer/src/lib/ensure-simulator-tab.ts
  • src/renderer/src/lib/floating-workspace-tab-creation.ts
  • src/renderer/src/lib/floating-workspace-terminal-actions.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-main-surface.test.ts
  • src/renderer/src/lib/run-quick-command-in-new-tab.ts
  • src/renderer/src/lib/simulator-tab-palette-activation.ts
  • src/renderer/src/lib/tab-number-shortcuts.ts
  • src/renderer/src/lib/workspace-tab-palette-activation.test.ts
  • src/renderer/src/lib/workspace-tab-palette-activation.ts
  • src/renderer/src/store/slices/editor/actions/open-file-state.ts
  • src/renderer/src/store/slices/editor/types/editor-files-slice.ts
  • src/renderer/src/store/slices/recently-closed-tabs.ts
  • src/renderer/src/store/terminals/terminal-active-workspace-creation.ts
  • tests/e2e/activity-agent-pane-isolation.spec.ts
  • tests/e2e/automation-hidden-terminal-first-mount.spec.ts
  • tests/e2e/browser-local-https-certificate-trust.spec.ts
  • tests/e2e/browser-tab.spec.ts
  • tests/e2e/file-open.spec.ts
  • tests/e2e/helpers/docker-ssh-relay-terminal-tabs.ts
  • tests/e2e/helpers/docker-ssh-relay-worktree-activation.ts
  • tests/e2e/helpers/host-created-terminal-retention-oracle.ts
  • tests/e2e/helpers/paired-host-terminal.ts
  • tests/e2e/helpers/paired-web-filesystem-route.ts
  • tests/e2e/helpers/ssh-test-target-connection.ts
  • tests/e2e/helpers/store.ts
  • tests/e2e/helpers/terminal-hidden-parking.ts
  • tests/e2e/helpers/terminal.ts
  • tests/e2e/host-parked-pane-remote-viewer.spec.ts
  • tests/e2e/native-chat-history-prepend-anchor.spec.ts
  • tests/e2e/nested-runtime-ssh-routing.spec.ts
  • tests/e2e/orchestration-idle-mail-delivery.spec.ts
  • tests/e2e/paired-client-hosted-browser-title-hold.spec.ts
  • tests/e2e/paired-remote-pane-layout-retry.spec.ts
  • tests/e2e/paired-remote-terminal-client-restart-survival.spec.ts
  • tests/e2e/paired-remote-terminal-host-restart-background-sync.spec.ts
  • tests/e2e/paired-remote-terminal-lossy-initial-snapshot.spec.ts
  • tests/e2e/paired-remote-terminal-parked-reveal-interactivity.spec.ts
  • tests/e2e/sidebar-agent-row-identity.spec.ts
  • tests/e2e/ssh-codex-reconnect-replay-driver.ts
  • tests/e2e/ssh-terminal-parking.spec.ts
  • tests/e2e/tab-close-navigation.spec.ts
  • tests/e2e/terminal-attention.spec.ts
  • tests/e2e/terminal-codex-hidden-startup-background.spec.ts
  • tests/e2e/terminal-codex-home.spec.ts
  • tests/e2e/terminal-cold-activation-deferral.spec.ts
  • tests/e2e/terminal-hidden-child-tui-kill-mode-reset.spec.ts
  • tests/e2e/terminal-hidden-view-parking.spec.ts
  • tests/e2e/terminal-inline-images-memory.spec.ts
  • tests/e2e/terminal-inline-tui-reveal-convergence.spec.ts
  • tests/e2e/terminal-osc8-cold-park-restore.spec.ts
  • tests/e2e/terminal-pane-close-layout-consistency.spec.ts
  • tests/e2e/terminal-parked-cli-split.spec.ts
  • tests/e2e/terminal-parked-close-retirement.spec.ts
  • tests/e2e/terminal-parked-memory.spec.ts
  • tests/e2e/terminal-retention-budget.spec.ts
  • tests/e2e/terminal-shortcuts.spec.ts
  • tests/e2e/terminal-split-activation-latency.spec.ts
  • tests/e2e/terminal-tab-switch-sigwinch-restore.spec.ts
  • tests/e2e/terminal-tab-switch-visual-restore.spec.ts
  • tests/e2e/terminal-warm-reattach-split-live-output.spec.ts
  • tests/e2e/terminal-windows-shell-paste-ownership.spec.ts
  • tests/e2e/windows-wsl-terminal-restore.spec.ts
  • tests/e2e/worktree-switch-first-paint.spec.ts
💤 Files with no reviewable changes (1)
  • src/renderer/src/components/floating-terminal/use-floating-terminal-panel-store-state.ts

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


📝 Walkthrough

Walkthrough

Terminal launches now select tabs within the worktree that receives the launch. Tab creation updates the global active tab ID only when that worktree is active. Web-hosted, AI Vault, and resumed sleeping-agent launches scope terminal tab type updates to their target worktree. Floating terminal controls rely on the launch flow for tab activation and focus the launched tab surface after a successful launch.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 0c8c2

The available evidence supports keeping the main window’s tab selected during floating launches while selecting the new floating tab. No identified issue prevents merging after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.51% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 41 functions across 63 files. (53 skipped… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the primary fix: floating-workspace agent launches no longer move the main window's tab.
Description check ✅ Passed The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, platform considerations, and known test limitations. It does not provide a linked issue despit…
Full details: Docstring Coverage

Explanation

Docstring coverage is 19.51% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 41 functions across 63 files. (53 skipped: 53 over the file limit.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Scoped the launcher's tab-type write — launchAgentInNewTab now calls setActiveTabType('terminal', worktreeId) instead of the unscoped call that resolved to the active worktree, so a floating or background launch no longer flips the main window's visible tab type.
  • Guarded the global terminal selection in createTab — the global activeTabId only advances when shouldActivate && s.activeWorktreeId === worktreeId, while per-worktree selection, group activeTabId, and activeTabTypeByWorktree still update so the floating panel selects the new tab and switching to a background worktree lands on it. This mirrors the existing guard in tabs-create-actions.ts:199 and browser-tab-actions.ts:98.
  • Removed the floating workaround — dropped the now-redundant activate: false opt-out (and setActiveTabForWorktree + activateTab) from FloatingTerminalWindowControls; the shared launcher plus the store rule cover every floating entry point.
  • Tests — new real-store launch-agent-in-new-tab-main-surface.test.ts, plus placement/caller-census/floating-controls updates for the removed option.

I traced both halves against the store: switching worktrees rebuilds the surface from deriveActiveSurfaceForWorktree, so the per-worktree writes the launcher makes are what the panel and later activation read. The focused IPC/background-adoption createTab callers either pass activate: false or explicitly setActiveTab after activating the worktree (terminal-presentation-ipc-bridge.ts:58,128), so they are unaffected. I also confirmed empirically that the new test fails when either half of the fix is reverted, pnpm tc:web is clean, and the targeted store/hook suites pass.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…worktree

Three more launch paths create a terminal tab and then call
`setActiveTabType('terminal')` without a worktree, which targets whatever
worktree is active when the call runs rather than the one the tab landed in:

- the paired-host agent launch, after the host's asynchronous create
- Session History resume, which can target a worktree the user is not viewing
  and activates it only afterwards
- sleeping-agent resume, which the activation gate runs after asynchronous
  readiness checks, by which time the user may have moved to another worktree

Each now names its worktree, like the local agent launch. The new tab still
lands selected when the user switches to that worktree.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Scoped the paired-host launch — launchAgentInWebHostTab now calls setActiveTabType('terminal', worktreeId). Because this runs inside the async handleCreation after the host accepts the launch, the previous unscoped call could flip whatever worktree the user had moved to.
  • Scoped the AI-vault / Session History resume — both the local and web-runtime paths in launchAiVaultSessionInNewTab now name args.worktreeId. The caller (ai-vault-session-launch-actions.ts:139) still activates the target worktree afterwards, so the resumed tab is shown without the resume itself moving the main window.
  • Scoped the sleeping-agent resume — launchSleepingAgentSession now names record.worktreeId, matching the terminal launcher; the navigation-suppressed variant is unchanged.
  • Tests — added a real-store test that resumes into a worktree the user has left and asserts the current view is untouched while the resumed worktree remembers the new tab; the caller-census, web-runtime, and AI-vault tests now assert the scoped call (toHaveBeenCalledExactlyOnceWith('terminal', worktreeId)), and the placement fixture dropped activate for all profiles.

I traced each scoped write against setActiveTabType (open-file-state.ts:24): it writes the global activeTabType only when the target equals activeWorktreeId, and always records activeTabTypeByWorktree[worktreeId], so scoping keeps the per-worktree selection while leaving the main window alone. Ran the six affected suites (103 tests pass) and pnpm tc:web (clean).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

`setActiveTabType(type, worktreeId?)` quietly fell back to the active
worktree when the caller left the worktree out. A caller acting on a tab in
another worktree (the floating workspace, a background launch, a reveal that
lands after an async step) therefore retyped whatever the main window was
showing. The launch paths fixed earlier in this branch were instances of that;
54 other callers still relied on the fallback.

The worktree is now a required argument (nullable only for the no-active-
worktree case), so every caller states which worktree it means and a new
unscoped call fails to compile. Each call site passes the worktree of the tab
it acts on; where that is by construction the active worktree (shortcuts,
palette, tab strip), the result is unchanged. `activateTabAndFocusPane`
resolves the tab's owning worktree the same way `setActiveTab` does.

End-to-end helpers that drive the store directly pass the active worktree,
which keeps their previous behaviour.
…wn tab

The floating "+" New Terminal created its tab with `activate: false` and then
selected it with `activateTab`, because creating an active tab used to write
the main window's selected tab even for another worktree. `createTab` now
activates a tab only within its own worktree's group unless that worktree is
the one on screen, so the workaround is no longer needed.

Creating the tab active also moves the floating workspace's remembered tab to
the new one; before, it stayed on the previously selected floating tab, which
auto-acknowledge reads to decide which floating agent the user is looking at.
…gh one creator

The floating "+" New Terminal had stopped deferring activation, but Cmd+T with the
floating panel focused still went through a separate creator that created the tab
inactive and activated it by hand, which left the floating workspace's remembered tab
on the previous tab. Both now call createFloatingWorkspaceTerminalTab, which creates
the tab active in its own group and focuses it.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Two commits landed since the prior pullfrog review (9581c66): a refactor that makes the tab-type write require its worktree, and a floating-workspace fix.

  • Required the worktree on setActiveTabType — setActiveTabType(type, worktreeId) dropped the implicit "active worktree" default (worktreeId? → string | null), so an unscoped call no longer compiles. Every renderer, script, and e2e caller now passes the worktree it operates on; the global write is still gated on worktreeId === activeWorktreeId and the per-worktree record still updates.
  • Scoped the pane-reveal tab-type write to the tab's owner — activateTabAndFocusPane resolves the terminal tab's owning worktree via the existing resolveActiveTabOwnerWorktreeId (falling back to the active worktree when the tab is unknown) before retyping, matching setActiveTab's owner guard. A reveal that lands after a worktree switch no longer retypes the main window.
  • Let the floating "+ New Terminal" activate its own tab — createFloatingTerminalTab dropped its { activate: false } override and follow-up activateTab; createTab's active-worktree guard keeps the global selection put while the floating group and activeTabIdByWorktree[floating] (which auto-acknowledge reads) both move to the new tab.
  • Tests — new real-store use-floating-terminal-create-actions.test.ts, a new activate-tab-and-focus-pane.test.ts case for a tab owned by a non-active worktree, plus caller-census/floating-controls/e2e updates asserting the two-argument call.

I traced each remaining setActiveTabType caller to confirm it names the worktree it acts on (the reveal callers all activate the target worktree first, so the main window still retypes in those flows), confirmed the new floating test fails on the old remembered-tab behavior, ran the eight affected suites (139 tests pass), and confirmed pnpm tc:web is clean. pnpm run typecheck:e2e still reports only its pre-existing errors, none on changed lines.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

aeb0c16f2f consolidates the floating New Terminal onto the shared creator. No behavior change.

  • Routed the panel's New Terminal through createFloatingWorkspaceTerminalTab — useFloatingTerminalCreateActions now calls the same lib/floating-workspace-tab-creation creator that the IPC and workspace-keydown paths already use, reading fresh state via useAppStore.getState() instead of a passed createTab.
  • Dropped the redundant createTab plumbing — removed createTab from useFloatingTerminalPanelStoreState and from the create-actions input; the creator resolves its target group from activeGroupIdByWorktree, which createTab validates and falls back identically.
  • Tests — floating-workspace-terminal-actions.test.ts and the real-store use-floating-terminal-create-actions.test.ts now assert createTab is called active-in-group with no follow-up activateTab.

This follows the earlier 023f8436ed (required worktree on setActiveTabType) and 08a8cdf55c (floating New Terminal activates its own tab). I verified the consolidation does not change the created group, ran the floating-terminal directory plus the workspace-creation, IPC-surfacing, and keydown suites (211 tests pass), and confirmed pnpm tc:web is clean.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status — head 0c8c2279584

Verdict: ready for merge review. Five review passes, the last two clean in substance (loop 4 only added a one-line comment, loop 5 changed nothing). Readiness checklist passed at the start and at the end. Electron QA passed on the final head.

What the review changed

  • Same bug, three more launch paths. The paired-host agent launch, Session History resume and sleeping-agent resume also called setActiveTabType('terminal') without naming a worktree, so each could switch the main window's view. All three now name their worktree, and each has a test.
  • Closed off the bug class. Six places had the same mistake: a caller that changed the main window's selection for a tab in another worktree. setActiveTabType now requires its worktree (string | null), so a new call without one fails to compile. All 54 remaining callers and the e2e helpers now name their worktree. Where the call is about the worktree on screen, nothing changes.
  • One way to create a floating terminal. Every floating New Terminal entry point (the + menu, Cmd+T and the double-tap shortcut) now goes through one creator. It no longer uses the old "create it inactive, then select it" workaround, which is no longer needed now that createTab leaves the main window alone. The floating workspace's remembered tab, which auto-acknowledge reads, now follows the tab you actually see.

Electron QA (hidden dev instance, isolated profile, real UI driven over CDP)

Final head 0c8c227958. The main window starts on README.md each time.

Scenario Result
A. Floating + menu → OpenCode PASS: main window stays on README.md; the new tab is selected in the floating panel
B. Floating titlebar agent button PASS: main window unchanged; keyboard focus is in the new floating terminal
C. Floating + menu → New Terminal PASS: main window unchanged; the new terminal is selected and focused in the floating panel
D. Cmd+T in the floating panel PASS: same as C
E. Main window + → OpenCode PASS: the main window switches to the new tab, as before
F. Clicking tabs and Cmd+Shift+[ / ] tab cycling in the main window PASS: the visible tab and tab type follow each switch
Main window on a chat tab, then a floating + launch (checked at 9581c66) PASS: the chat stays on screen
Screenshots

A. After the floating + → OpenCode launch:
A-after

C. After floating + → New Terminal:
C-after

D. After Cmd+T in the floating panel:
D-after

E. After the main window + → OpenCode launch:
E-after

F. Tab switching in the main window (click README, click terminal, next tab, previous tab):
F-click-readme
F-click-terminal
F-chord-next
F-chord-prev

Titlebar button (checked at 9581c66), before and after:
s3-before
s3-after

Main window on a chat tab, before and after a floating launch (checked at 9581c66):
s5-before
s5-after

Validation

  • Full renderer suite: 33,739 passed. pnpm tc, oxlint, the changed-code quality gate and React Doctor all pass.
  • Each fix was checked by reverting it: the test that covers it fails for the right reason.
  • CI: all required checks pass: typecheck, static analysis, test shards 1–8, relay integration, package (mac and Windows), and real WSL terminal. e2e / changed e2e specs ran 96 passed and 1 failed. The failure is paired-remote-terminal-parked-reveal-interactivity.spec.ts:349, and it is not caused by this PR: it fails the same way (the cold-parked and reconnect-parked panes never receive host input) in every scheduled full e2e run on main since 2026-09-19, for example run 35926472314 at 7f203ad5aa. Locally the spec passed 3/3 on this head, 3/3 on main, and 3/3 on this head with main's copy of the spec. The e2e job is not a required check.
  • Not tested by hand: Linux, Windows and SSH. The change is renderer store logic with no platform-specific or host-specific branches.

Known follow-ups (not in this PR)

  • The main window's selection is still a separate stored copy, kept in step by a check at each place that writes it. Reading it from the active worktree's own selection instead would remove this class of bug entirely. That touches 100+ files and is a separate refactor.
  • setActiveBrowserTab still sets the main window's browser selection whatever worktree the tab is in. No current caller reaches it from the floating panel or from a worktree you aren't viewing.
  • Already like this before this PR: the floating + menu has no search box (only the main window's does), and floating terminals start in the home folder.

@brennanb2025
brennanb2025 merged commit 80e0bee into main Sep 24, 2026
35 of 36 checks passed
flosrn pushed a commit to flosrn/orca that referenced this pull request Sep 25, 2026
…dow's tab (stablyai#22603)

* fix(floating-workspace): keep agent launches from moving the main window's tab

Launching an agent from the floating workspace's "+" menu switched the main
window off whatever chat or editor tab it was showing and onto its terminals.

The main window's selection is supposed to move only for the worktree it is
showing: browser and editor tab creation, splits, moves and drops all check
`activeWorktreeId === worktreeId` before touching it. Two places did not:

- `launchAgentInNewTab` called `setActiveTabType('terminal')` without a
  worktree, which targets the active worktree whatever worktree the launch
  landed in.
- terminal `createTab` wrote the global `activeTabId` for a tab in any
  worktree.

Both now follow the store rule. The launch still selects its tab within its
own worktree, which is what the floating panel renders.

The floating titlebar button had side-stepped this with an `activate: false`
opt-out plus manual selection. That opt-out had no other caller and is removed;
the button now launches and focuses like every other entry point.

* fix(tabs): scope the remaining launch surface writes to the launch's worktree

Three more launch paths create a terminal tab and then call
`setActiveTabType('terminal')` without a worktree, which targets whatever
worktree is active when the call runs rather than the one the tab landed in:

- the paired-host agent launch, after the host's asynchronous create
- Session History resume, which can target a worktree the user is not viewing
  and activates it only afterwards
- sleeping-agent resume, which the activation gate runs after asynchronous
  readiness checks, by which time the user may have moved to another worktree

Each now names its worktree, like the local agent launch. The new tab still
lands selected when the user switches to that worktree.

* test(tabs): pin the paired-host launch scope in its existing web-runtime test

* test(tabs): type the left-worktree resume fixture instead of casting it

* refactor(tabs): require the worktree that setActiveTabType applies to

`setActiveTabType(type, worktreeId?)` quietly fell back to the active
worktree when the caller left the worktree out. A caller acting on a tab in
another worktree (the floating workspace, a background launch, a reveal that
lands after an async step) therefore retyped whatever the main window was
showing. The launch paths fixed earlier in this branch were instances of that;
54 other callers still relied on the fallback.

The worktree is now a required argument (nullable only for the no-active-
worktree case), so every caller states which worktree it means and a new
unscoped call fails to compile. Each call site passes the worktree of the tab
it acts on; where that is by construction the active worktree (shortcuts,
palette, tab strip), the result is unchanged. `activateTabAndFocusPane`
resolves the tab's owning worktree the same way `setActiveTab` does.

End-to-end helpers that drive the store directly pass the active worktree,
which keeps their previous behaviour.

* fix(floating-workspace): let the floating New Terminal activate its own tab

The floating "+" New Terminal created its tab with `activate: false` and then
selected it with `activateTab`, because creating an active tab used to write
the main window's selected tab even for another worktree. `createTab` now
activates a tab only within its own worktree's group unless that worktree is
the one on screen, so the workaround is no longer needed.

Creating the tab active also moves the floating workspace's remembered tab to
the new one; before, it stayed on the previously selected floating tab, which
auto-acknowledge reads to decide which floating agent the user is looking at.

* refactor(floating-workspace): route every floating New Terminal through one creator

The floating "+" New Terminal had stopped deferring activation, but Cmd+T with the
floating panel focused still went through a separate creator that created the tab
inactive and activated it by hand, which left the floating workspace's remembered tab
on the previous tab. Both now call createFloatingWorkspaceTerminalTab, which creates
the tab active in its own group and focuses it.

* docs(tabs): say why an unowned tab id keeps the on-screen worktree scope

(cherry picked from commit 80e0bee)
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