fix: prevent tmux detach from stalling Happy CLI#539
fix: prevent tmux detach from stalling Happy CLI#539dzlobin wants to merge 1 commit intoslopus:mainfrom
Conversation
When tmux detaches, the PTY buffer fills and process.stdout.write() blocks synchronously, freezing the Node.js event loop. This wraps Ink's stdout in a non-blocking proxy that drops writes during backpressure instead of blocking. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]>
Cherry-picked from upstream PRs: - slopus#566: Path normalization alignment with Claude Code (Adam Murphy) - slopus#561: YOLO mode race condition fix (Adam Murphy) - slopus#570: Terminal state restoration after remote→local switch (blechschmidt/tomstetson) - slopus#539: tmux detach stalling prevention (claudio) All 4 PRs applied successfully. slopus#561 required conflict resolution (merged effectiveMode race fix with AskUserQuestion guard).
|
We've been testing a similar fix in our fork for about a week across multiple tmux setups (both detach/reattach cycles and long-running detached sessions), and can confirm this approach resolves #533 effectively. The Proxy-based wrapper is a clean solution — it avoids patching A few observations from our testing:
Solid fix. Hope this gets merged soon — it's a real pain point for tmux users running multiple sessions. |
Ports: slopus/happy#539 (full) Refs: slopus/happy#539 Upstream-PR: slopus/happy#539 Credit: @dzlobin
Summary
Root Cause
When tmux detaches, the PTY buffer (~4KB on macOS) fills with no reader.
process.stdout.write()then blocks synchronously, freezing the entire Node.js event loop and stalling all Happy instances in that tmux session.Fix
A
Proxywrapsprocess.stdoutand interceptswrite()calls. WhenwritableNeedDrainis true orwrite()returns false, subsequent writes are silently dropped (with callbacks still invoked) until adrainevent fires. This is passed to Ink'srender()via thestdoutoption.Closes #533
Test plan
happyin tmux, detach, verify no stall, reattach and confirm UI resumes🤖 Generated with Claude Code