Repository navigation
fix(native-chat): stop seeding a stray terminal beside a chat create - #19123
Conversation
A native-chat worktree create activates with `providesInitialSurface: true`, meaning "I open my own primary surface, don't seed a shell". Activation only honoured that when there was no other activation work, so any repo returning a setup script fell through to `ensureWorktreeHasInitialTerminal`, which created a bare terminal purely to act as the primary tab before giving setup its own tab. The user landed on `Terminal 1` + `Setup` + `Claude Chat`. The bare terminal was never needed for a new-tab setup: `queueSetupAndIssueCommands` only uses the primary tab there to restore focus to it. Forward `providesInitialSurface` into seeding as `callerProvidesSurface`, and skip the shell when the launch work needs no host tab. A terminal is still seeded when something has to attach to it: a startup command, issue automation, a split-mode setup script, `createNewTerminalForStartup`, or configured default tabs.
📝 WalkthroughWalkthroughThe change adds Merge Risk: 🟠 High · up to A structured chat launch that resolves without opening a chat can leave the workspace with neither a chat nor a fallback terminal. The fallback must remain eligible after launch resolution before this is merge-ready. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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
Renderer-only fix that stops a worktree create from seeding a stray empty Terminal 1 beside a structured native chat when the repo also returns a setup script. It threads providesInitialSurface through activation into ensureWorktreeHasInitialTerminal as callerProvidesSurface, and adds a narrow guard that skips shell seeding only when the caller owns the surface, no tabs are renderable, and the sole launch work is a new-tab setup. queueSetupAndIssueCommands now takes terminalTabId: string | null so setup still gets its own tab without a host terminal to split from or restore focus to.
- Activation seam forwards the opt-out —
activateAndRevealWorktreepassescallerProvidesSurface: truethrough to seeding alongside the existingreseedEmptiedWorkspaceflag. - Narrow seeding guard —
worktree-initial-terminal-seeding.tsskips the shell whencallerProvidesSurfaceis set and there is no startup / issue command / split-mode setup / default-tab work; splits and issue automation still seed a pane. - Nullable
terminalTabIdin the setup/issue queue — focus-restore, split, and issue-split paths gate on a non-null tab id; new-tab setup still creates its ownSetuptab. - Tests — a 5-test suite covering new-tab, split-mode, issue automation, no-surface, and an end-to-end
activateAndRevealWorktreeforwarding case.
I verified the guard is unreachable in the split-drop case (it requires new-tab mode), that the hostAuthority === 'live' / SSH path returns before the guard, and that the structured-launch refusal fallback still re-seeds a real terminal. Ran the new suite plus the 12 related worktree-activation-* suites (96 tests) — all green.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The follow-up commit extends the surface opt-out to the background completion route: when the user navigates away during a structured native-chat create (so activateAndRevealWorktree is bypassed and ensureWorktreeHasInitialTerminal is called directly), the stray shell is now suppressed too.
- Background route forwards the opt-out —
executeWorktreeCreationnow passescallerProvidesSurface: truetoensureWorktreeHasInitialTerminalwhenstructuredLaunchis set, mirroring the foreground route'sprovidesInitialSurfaceforwarding. - Background-route integration test — the new
worktree-creation-chat-setup.test.tsdrivesexecuteWorktreeCreationforclaude/codex, asserting a singleSetuptab, anullprimary tab, preserved focus, andlaunchStructuredWorktreeSession({ primaryTabId: null, shouldActivateOnCompletion: false }).
I verified the background refusal fallback still seeds a real terminal (createNewTerminalForStartup: true with no callerProvidesSurface), that structured-native-chat is only ever routed for session-handle providers (agent-launch-routing.ts requires isAgentSessionHandleProvider), and that the guard ordering leaves the hostAuthority === 'live' SSH path unchanged. Ran both new suites (7 tests) — green.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Electron QA (Playwright CDP, hidden renderer)Tested SHA: New-tab setup + Claude native chat — passComposer: Claude, Backing: one No-setup + Claude native chatOn Retest on Split-vertical setup (neighboring; still seeds a host pane) — passTerminal 1 with vertical split (idle shell | setup runner) plus Claude Chat. GapsCodex UI create, background-create (navigate-away) path, structured-launch refusal fallback, SSH, and Windows were not exercised. New-tab setup was created before Full writeup: |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 9b3c67e2-ff6f-49a0-bdb0-ac44d7b82e7a
📒 Files selected for processing (2)
src/renderer/src/components/terminal/initial-terminal-structured-launch.test.tsxsrc/renderer/src/components/use-terminal-watcher-effects.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.
| (agent) => getStructuredAgentLaunchStatus(activeWorktreeId, agent) !== 'idle' | ||
| ) | ||
| ) { | ||
| return |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Re-enable fallback after structured launch resolution.
At Line 170, this return occurs after the worktree is added to startupActivationGateWorktreeIdsRef. If the status is pending or unknown when the gate returns empty, a later transition to idle cannot run this activation path again for the same worktree.
Keep the worktree eligible until the structured launch resolves, or trigger one fallback activation when it resolves without publishing a surface. Add a regression test that changes pending to idle and verifies one terminal is created only when no chat tab exists.
|
Review completed at Two focused fixes were pushed:
Regression tests failed before each fix and passed afterward. Final verification: 18 focused tests and 152 broader activation/creation tests passed; renderer typecheck, lint, React Doctor, formatting, and diff checks passed. The watcher adds at most two existing Map reads, with no new polling, subscriptions, timers, or retained state. Scope remains unwanted terminal creation; existing startup, split setup, issue automation, default-tab, and refusal-fallback behavior is preserved. Grok's Electron screenshots and scenario report show setup plus focused Claude Chat, the no-setup failure before the watcher fix, chat alone after the fix, and the expected host pane for split setup. QA used the real composer and hidden CDP renderer; the disposable app/profile/repos were cleaned up and its CDP/renderer ports are no longer listening. Remaining validation limits: Codex/background creation have deterministic regression coverage but were not exercised through the UI; refusal fallback, SSH, and Windows were not manually exercised. New-tab setup was created on the prior commit and reopened on the final commit. Latest-head CI is still queued/running, so this is a clean code-review result, not unconditional merge approval. Initial and final readiness audits were completed; the initial severity-counsel attempt was unavailable, and the final audit had zero candidate findings requiring counsel. The pre-existing uncommitted |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
The latest commit closes the final route that could seed the stray Terminal 1 during a native chat create: the passive, effect-driven path in useTerminalWatcherEffects that seeds a default shell once the activation gate reports empty.
- Passive seeding guard — after
gateWorktreeAgentActivationresolvesempty, the effect now returns early when any session-handle provider (claude/codex) has a non-idlegetStructuredAgentLaunchStatusfor the active worktree, so a chat create in flight during the gate's async inventory is not shadowed by a shell. - Regression test pinned to the mechanism —
initial-terminal-structured-launch.test.tsxdrives the watcher effect with a held-open gate, flips the launch status topending/unknown, resolves the gate, and assertscreateTabwas not called (once foridle).
The guard is narrow and correct: it reads only the active worktree's own launch state, only the two session-handle providers can enter startStructuredAgentLaunch, and a non-idle status means the create flow is already mid-launch and owns the surface. The refusal fallback still seeds a real terminal via activateAndRevealWorktree({ createNewTerminalForStartup: true }).
ℹ️ One boundary worth awareness
The effect's startupActivationGateWorktreeIdsRef is one-shot, so a worktree whose launch was pending/unknown at gate-resolution and then resolves to idle without publishing a surface is never re-seeded by this path. That leaves no tab only on a definitive generic failure — the structured-not-available refusal already seeds a fallback terminal, and generic failures surface an error toast. This matches the foreground route's behavior since the first commit, so it is a pre-existing boundary rather than a new regression; flagging it only so the create flow's error path can be revisited independently if "never leave a workspace dead" matters.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
PR 19123 Windows QA — BLOCKEDPR: #19123 What was requestedClose the Windows QA gap left by the prior Electron QA comment on Constraints: assigned existing worktree only; never checkout/reset/clean/edit owner source; no new worktrees (cross-host parent lineage failed); Identity at first inspect (this worker, ~15:46 local)
Tracked dirt (owner diagnostic overlay, not PR 19123):
At first inspect, no process in this worktree was running Coordinator stopInbox messages on Dispatch
This worker did not launch Orca, did not attach CDP, did not create fixture repos, and did not mutate owner files. A recursive skill-directory search ( Identity at stop (~15:52 local) — owner moved the checkoutThe assigned worktree is no longer at the requested merge SHA. Owner processes are live.
Tracked source diffs are now clean. Untracked owner diagnostic files grew: Live owner processes whose command line contains this worktree path (not killed):
Building or attaching to this instance would validate the owner's Windows stale-parent-PID diagnostic checkout, not PR 19123 at Why a clean Windows QA of
|
SSH gap QA (throwaway Linux Docker) — 933a61dFull report: Local refusal (requested before SSH): WSL-bound Claude account injection, restored immediately. Composer create SSH Create worktree (real UI, demo-project on linux-arm64 Docker sshd, relay deployed):
Limits: a true no-setup SSH create was not isolated (composer used default-branch No source edits. |
…tablyai#19123) * fix(native-chat): stop seeding a stray terminal beside a chat create A native-chat worktree create activates with `providesInitialSurface: true`, meaning "I open my own primary surface, don't seed a shell". Activation only honoured that when there was no other activation work, so any repo returning a setup script fell through to `ensureWorktreeHasInitialTerminal`, which created a bare terminal purely to act as the primary tab before giving setup its own tab. The user landed on `Terminal 1` + `Setup` + `Claude Chat`. The bare terminal was never needed for a new-tab setup: `queueSetupAndIssueCommands` only uses the primary tab there to restore focus to it. Forward `providesInitialSurface` into seeding as `callerProvidesSurface`, and skip the shell when the launch work needs no host tab. A terminal is still seeded when something has to attach to it: a startup command, issue automation, a split-mode setup script, `createNewTerminalForStartup`, or configured default tabs. * Fix background native chat setup terminal seeding * Avoid passive terminal seeding during native chat launch --------- Co-authored-by: Merge Sim <sim@local>



















ELI5
Creating a workspace that opens a Claude/Codex native chat also dropped an empty
Terminal 1next to it. The chat already is your starting surface — the shell was pure noise. Now you get the chat (plus the backgroundSetuptab, when your repo has a setup script).What Changed
activateAndRevealWorktreeacceptsprovidesInitialSurface: true, which means "I open my own primary surface, don't seed a shell for me". That opt-out was only honoured when there was no other activation work (worktree-activation.ts).A worktree create in a repo with a setup script returns
setup, which counts as activation work — so the opt-out was skipped,ensureWorktreeHasInitialTerminalran, and it created a bare terminal purely to serve as the "primary tab" before handing setup its own tab. Result:Terminal 1+Setup+Claude Chat.That bare terminal was never needed for a new-tab setup.
queueSetupAndIssueCommandsonly uses the primary tab in that mode to restore focus to it after the Setup tab auto-activates.worktree-activation.ts— forwardsprovidesInitialSurfaceinto seeding ascallerProvidesSurface.worktree-initial-terminal-seeding.ts— when the caller owns the surface and the workspace has no tab yet, skip the shell and let setup open its own tab.worktree-setup-issue-command-queue.ts—terminalTabIdis now nullable; with no host tab, setup still gets its tab and the focus-restore/split paths are skipped.A terminal is still seeded whenever the launch work genuinely needs one to attach to:
split-vertical/split-horizontal)createNewTerminalForStartupdefaultTabsOne seam covers all three create routes (full composer, quick create, work-item launch), since they all activate through
activateAndRevealWorktree.Why
Direct user report: "When I start a claude native chat via worktree create it spawns a terminal AND a claude chat. It should JUST spawn the claude/codex native chat."
Fixing it at the activation seam rather than in each create route matches how the folder-workspace path already behaves —
ensureFolderWorkspaceInitialTerminalreturnsnullforprovidesInitialSurfacetoday, so this makes the git-worktree path honour the same contract instead of diverging on the presence of a setup script.The structured-launch refusal fallback is unaffected: it re-activates with
createNewTerminalForStartup: trueand gets a real terminal. It actually gets cleaner — that path previously produced three tabs (stray shell + Setup + fallback agent terminal) and now produces two.Linked Issue
No tracking issue — came in as a direct report with a screenshot. Happy to file one if preferred.
Visual Proof
Before (reported):
Terminal 1(focused, empty shell) |Setup|Claude ChatAfter:
Setup|Claude Chat, with the chat focused.Attaching a recorded before/after next — flagging that the screenshots are not yet on this PR rather than letting the section imply they are.
Testing
New suite
src/renderer/src/lib/worktree-activation-structured-chat-surface.test.ts(5 tests):Setup,primaryTabIdisnullactivateAndRevealWorktree, provingprovidesInitialSurfaceis actually forwardedRed/green ablation: with the guard removed, the two behaviour tests fail (
expected '<uuid>' to be null) and the three "still seeds a shell" guards pass either way — so the suite is pinned to the mechanism, not just to a passing state.Also run:
pnpm tc— cleanpnpm run check:code-quality:changed— 0 findings across 5 files (code quality, type-aware, React Doctor)Renderer-only tab-seeding logic, no platform-specific paths, so macOS/Linux/Windows/SSH behave identically. Not yet exercised in a running app — see Visual Proof.
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
hostAuthority === 'live'branch returns before the new guard, so host-owned terminal creation is unchanged.callerProvidesSurfaceis optional and only set by activation when the caller already opted out; every existing caller keeps today's behaviour.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)