Skip to content

fix(cli): prevent daemon respawn and harden tmux session resume#139

Closed
caseyjkey wants to merge 9 commits intohappier-dev:devfrom
keycasey:fix/session-stop-respawn
Closed

fix(cli): prevent daemon respawn and harden tmux session resume#139
caseyjkey wants to merge 9 commits intohappier-dev:devfrom
keycasey:fix/session-stop-respawn

Conversation

@caseyjkey
Copy link

@caseyjkey caseyjkey commented Mar 22, 2026

Summary

  • prevent daemon-managed sessions from respawning after an explicit stop/kill flow and align daemon attach payloads with the upstream v2 schema
  • fix shared CLI dependency build ordering so @happier-dev/agents consumes fresh protocol declarations, and widen session RPC payload typing for plaintext-session flows
  • harden tmux session startup by retrying with the configured base window index and avoiding bootstrap-window cleanup races when another process creates the session first
  • keep the daemon-only TTY guard in resolveHasTTY but allow tmux sessions started by the daemon to re-enable Ink when HAPPIER_CLI_ALLOW_DAEMON_TTY_IN_TMUX=1, so tmux-based resumes from the app continue to work while other daemon sessions stay headless

Verification

  • yarn workspace @happier-dev/cli vitest run src/integrations/tmux/env.extractIndex.test.ts src/integrations/tmux/tmux.spawnAndEnv.test.ts src/sessionControl/sessionRpc.plaintext.test.ts
  • HAPPIER_CLI_TMUX_INTEGRATION=1 yarn workspace @happier-dev/cli vitest run --config vitest.integration.config.ts src/integrations/tmux/tmux.real.integration.test.ts src/backends/claude/runClaude.fastStart.integration.test.ts
  • yarn workspace @happier-dev/cli vitest run --config vitest.integration.config.ts src/backends/claude/claudeRemoteLauncher.integration.test.ts -t \"does not mount Ink UI for daemon-started sessions even when a TTY is available\"
  • yarn workspace @happier-dev/cli typecheck

Follow-up

  • nothing blocking here; remaining automatic integrations already pass when the new flag is set strictly by tmux-driven resumes

caseyjkey and others added 7 commits February 27, 2026 15:36
When creating a new window in an existing tmux session, tmux can fail with
"create window failed: index N in use" due to window index allocation issues.
The previous retry logic just retried the same command, which would fail again
if tmux kept trying to use the same conflicting index.

This fix:
- Adds extractTmuxWindowIndexConflict() to parse the conflicting index
- Adds getWindowIndices() to query session for existing window indices
- Adds findAvailableWindowIndex() to find an available index (gap or next)
- Updates retry logic to explicitly target an available index on retry

On first attempt: tmux new-window -t session (auto-assign)
On retry: tmux new-window -t session:3 (explicit available index)
Bumping version so daemon detects code change and restarts with
the tmux window index conflict fix from previous commit.
When stopping a session via the app (killSession RPC) or Ctrl-C,
the daemon would sometimes respawn it after ~60 seconds. This
happened because the killSession RPC handler exited without
notifying the daemon, so the heartbeat loop detected a missing
process and triggered respawn.

Fix: Call stopDaemonSession(sessionId) in the killSession handler
before exiting. This marks the session as "stop requested" in the respawn manager,
preventing unwanted respawns.

Discovered during mobile development testing on Termux.
@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

Important

Review skipped

Draft detected.

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: CHILL

Plan: Pro

Run ID: bf1f12e3-7157-4fc1-b454-a6dc2e5eeae5

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

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.

@caseyjkey caseyjkey closed this Mar 23, 2026
@caseyjkey caseyjkey deleted the fix/session-stop-respawn branch March 23, 2026 02:57
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