Repository navigation
fix(spawn): honor --new-window --session even when session equals team - #1175
Conversation
Follow-up to #1174 (auto-team-of-one). The isolatedSessionSpawn heuristic in #1173 used `sessionOverride !== team` as a proxy for "TUI per-agent spawn". That proxy breaks the moment resolveTeamAndResume auto-creates a team-of-one named after the agent — now session equals team, isolatedSessionSpawn goes false, and resolveSpawnTeamWindow runs again, producing the same 3-window (bash + team-named + claude) cruft topology Felipe hit before. The fix: when the caller explicitly passes both --new-window and --session, always skip team-window creation. The agent runs in its own window in its own session — team windows exist to group multi-member teams that share a session, and the TUI spawn path doesn't want that coordination surface.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Code Review
This pull request modifies the launchTmuxSpawn function in src/term-commands/agents.ts to simplify the logic for identifying isolated session spawns. The change removes the requirement that the session override must differ from the team name, ensuring that 'auto-team-of-one' scenarios for globally-registered teamless agents are handled correctly without creating redundant tmux windows. I have no feedback to provide.
…mplification) PR #1175 (merge f43db8d) simplified the isolatedSessionSpawn guard in launchTmuxSpawn — removed the `sessionOverride !== team` redundancy that was a stale proxy for TUI per-agent spawn. Auto-team-of-one (PR #1174) now makes session and team equal for globally-registered teamless agents, and the explicit `--session` flag should be honored unconditionally. Accepted theirs verbatim. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… death When `--new-window --session <name>` bootstraps a fresh tmux session for a team-of-one (or any isolated spawn), the session previously contained only the agent's `claude` window. When that window closed — via `genie kill`, agent crash, or natural exit — tmux's default behavior tore the session down with it. Any subsequent resume inside another tmux context then fell through `resolveRepoSession` tier 1 (exact match — the session was gone) to tier 2 (current TMUX session), so the agent respawned as a window in the caller's session instead of returning to its dedicated home. Observed: after killing `khal-os` canonical, pressing Enter in the TUI (attached to `genie-configure`) placed the respawned khal-os as window 2 of `genie-configure` rather than a standalone `khal-os` session — losing the topology guarantee that PR #1175 restored for fresh spawns. Fix: when creating a new session in the isolated path, create a `home` window (bash shell) first, then add the `claude` agent window. The home window is cheap (single shell, no work) and acts as a session keeper: closing the agent leaves `home` behind so the session stays alive. Future resume/respawn calls find the exact-match session via tier 1 and return the agent to its intended home. For existing sessions the branch is unchanged — we just add the claude window. Verified tmux semantics directly: tmux new-session -d -s probe -n home tmux new-window -a -d -t probe: -n claude 'sleep' tmux kill-window -t probe:claude tmux list-windows -t probe # => just home, session still alive Test plan: - `bun run typecheck` clean - `bun test` 2634/2634 pass - Live tmux probe confirmed keeper behavior
Summary
bash+ team-named +claude) that fix(spawn): eliminate cruft windows for isolated-session --new-window #1173 set out to kill.launchTmuxSpawn: treat any spawn with explicit--new-window+--sessionas isolated, regardless of whether session happens to equal team.Why the old proxy broke
#1173usedsessionOverride !== teamas a heuristic for "TUI per-agent spawn". When #1174 added auto-team-of-one, globally registered teamless agents (e.g.khal-os) now auto-create a team named after themselves — so the TUI callgenie spawn khal-os --session khal-os --new-windowhassessionOverride === team,isolatedSessionSpawngoes false,resolveSpawnTeamWindowruns, and you get the same cruft:The fix
Drop the
!== teamclause. Rationale: the explicit--sessionflag IS the signal that the caller wants isolation; team-window organization exists to group multi-member teams that share a session, which is orthogonal to the per-agent TUI spawn path.Test plan
bun run typecheck— cleanbun test src/term-commands/agents.test.ts— 9/9 passgenie spawn khal-os --session khal-os --new-windowfrom a teamless state produces exactly one tmux window namedclaude, nobashor team-named cruft.