Skip to content

fix(spawn): honor --new-window --session even when session equals team - #1175

Merged
namastex888 merged 1 commit into
devfrom
fix/auto-team-spawn-topology
Apr 17, 2026
Merged

namastex888 merged 1 commit into
devfrom
fix/auto-team-spawn-topology

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

Summary

Why the old proxy broke

#1173 used sessionOverride !== team as 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 call genie spawn khal-os --session khal-os --new-window has sessionOverride === team, isolatedSessionSpawn goes false, resolveSpawnTeamWindow runs, and you get the same cruft:

khal-os: 3 windows
  0: bash#  (bootstrap session default window)
  1: claude (real agent)
  2: khal-os (ghost team window)

The fix

Drop the !== team clause. Rationale: the explicit --session flag 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 — clean
  • bun test src/term-commands/agents.test.ts — 9/9 pass
  • Pre-push full suite — 2505/2505 pass
  • Live: after install, genie spawn khal-os --session khal-os --new-window from a teamless state produces exactly one tmux window named claude, no bash or team-named cruft.

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

coderabbitai Bot commented Apr 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 20997cc8-a149-4064-8176-c5e9fc79c17f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/auto-team-spawn-topology

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 and usage tips.

@namastex888
namastex888 merged commit f43db8d into dev Apr 17, 2026
6 checks passed

@gemini-code-assist gemini-code-assist 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.

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.

automagik-genie pushed a commit that referenced this pull request Apr 17, 2026
…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>
namastex888 pushed a commit that referenced this pull request Apr 18, 2026
… 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
@automagik-genie
automagik-genie deleted the fix/auto-team-spawn-topology branch September 25, 2026 04:49
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.

2 participants