Repository navigation
fix(floating-workspace): keep agent launches from moving the main window's tab - #22603
Conversation
…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.
|
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 configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (104)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughTerminal 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 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)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation 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.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Scoped the launcher's tab-type write —
launchAgentInNewTabnow callssetActiveTabType('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 globalactiveTabIdonly advances whenshouldActivate && s.activeWorktreeId === worktreeId, while per-worktree selection, groupactiveTabId, andactiveTabTypeByWorktreestill update so the floating panel selects the new tab and switching to a background worktree lands on it. This mirrors the existing guard intabs-create-actions.ts:199andbrowser-tab-actions.ts:98. - Removed the floating workaround — dropped the now-redundant
activate: falseopt-out (andsetActiveTabForWorktree+activateTab) fromFloatingTerminalWindowControls; 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.
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.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Scoped the paired-host launch —
launchAgentInWebHostTabnow callssetActiveTabType('terminal', worktreeId). Because this runs inside the asynchandleCreationafter 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
launchAiVaultSessionInNewTabnow nameargs.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 —
launchSleepingAgentSessionnow namesrecord.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 droppedactivatefor 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).
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.
There was a problem hiding this comment.
✅ 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 onworktreeId === activeWorktreeIdand the per-worktree record still updates. - Scoped the pane-reveal tab-type write to the tab's owner —
activateTabAndFocusPaneresolves the terminal tab's owning worktree via the existingresolveActiveTabOwnerWorktreeId(falling back to the active worktree when the tab is unknown) before retyping, matchingsetActiveTab'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 —
createFloatingTerminalTabdropped its{ activate: false }override and follow-upactivateTab;createTab's active-worktree guard keeps the global selection put while the floating group andactiveTabIdByWorktree[floating](which auto-acknowledge reads) both move to the new tab. - Tests — new real-store
use-floating-terminal-create-actions.test.ts, a newactivate-tab-and-focus-pane.test.tscase 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ 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—useFloatingTerminalCreateActionsnow calls the samelib/floating-workspace-tab-creationcreator that the IPC and workspace-keydown paths already use, reading fresh state viauseAppStore.getState()instead of a passedcreateTab. - Dropped the redundant
createTabplumbing — removedcreateTabfromuseFloatingTerminalPanelStoreStateand from the create-actions input; the creator resolves its target group fromactiveGroupIdByWorktree, whichcreateTabvalidates and falls back identically. - Tests —
floating-workspace-terminal-actions.test.tsand the real-storeuse-floating-terminal-create-actions.test.tsnow assertcreateTabis called active-in-group with no follow-upactivateTab.
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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…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)













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 whenstate.activeWorktreeId === worktreeId. Two places did not:launchAgentInNewTabcalledsetActiveTabType('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.createTabwrote the globalactiveTabIdfor 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: falseopt-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.
setActiveTabTypenow 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 (
showAgentLaunchItemsdefaulted to on), and those items calledlaunchAgentInNewTab, which already made the unscopedsetActiveTabType('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: falseoverride, 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
setActiveTabTypeis 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. TheactiveWorktreeId === worktreeIdcheck 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.
After (this branch): the same steps. The main window stays on README.md and OpenCode runs in the floating panel.
Testing
Manual (macOS, isolated dev build, background launch, driven through the real UI over CDP):
activeTabType: editorand the main window's active tab unchanged; the new tab is selected in the floating panel.Automated:
launch-agent-in-new-tab-main-surface.test.tsruns 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, orcreateTab's check) makes it fail on its own.setActiveTabType: the tests that asserted the old one-argument call now assert the worktree each caller passes, andactivate-tab-and-focus-pane.test.tsgains 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.use-floating-terminal-create-actions.test.tschecks 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).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
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
createTab.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)