[bug]: PTY panel crash during tmux mouse selection
Bug Description
PTY panelem crashes (becomes unresponsive, must restart emdash) when performing multi-line mouse selection inside a tmux session with mouse mode enabled on a remote SSH connection. Likely related to high-frequency bidirectional IPC traffic (mouse input and terminal output) with no backpressure mechanism, though exact crash mechanism is unconfirmed.
Steps to Reproduce
- Create a project connected to a remote SSH host
- Open a task/terminal session (PTY panel)
- SSH into the remote and start tmux (which enables mouse mode by default via
set -g mouse on) - Open a file or long output in tmux (enough content to select across multiple lines)
- Click and drag to select multiple lines of text
- Continue holding and dragging; within a few seconds the panel freezes and becomes unresponsive
Escape, q, ctrl+Q, etc. does not work. All other tmux sessions on the same host also freezes with a [server unexpectedly] message. To recover, emdash has to be restarted. The sub-tasks open under a project task (different terminal windows for a given task) do not resume by themselves, so they have to be closed, new sub-tasks (agents) have to be created, and resumed with the agent's own commands (i.e., after restarting emdash, I need to close the existing agent windows, create new agents, and then use agent's /resume command). This is very counter-productive, one mis-click somewhere requires me to close emdash entirely and create new agents.
Actual vs Expected Behavior
Actual: Panel freezes during multi-line mouse drag. Eventually the panel crashes or becomes permanently unresponsive, requiring an emdash restart. No error is surfaced to the user.
Expected: Mouse selection should work normally inside tmux, or at minimum degrade gracefully (slowdown, dropped frames) without crashing the panel.
emdash Version
v1.1.16
Operating System
macOS connecting via SSH tunnel to RHEL running tmux
Additional Context
Root Cause Analysis (Hypothesized, Not Profiled)
Note: This analysis is based on code inspection only. The exact bottleneck (Canvas rendering, IPC serialization, GC pressure, or an Electron limitation) has not been confirmed via profiling. The crash mechanism (OOM, unresponsive timeout, canvas context loss) is also unconfirmed.
What we know from code inspection:
- Bidirectional traffic with tmux mouse mode (verified in code):
- When tmux mouse mode is active (
\e[?1000h/ SGR\e[?1006h), xterm.js reports mouse events back to the PTY viaterminal.onData()inuse-pty.ts - Each mouse move generates both an input message (mouse position → PTY) AND an output message (tmux visual update → renderer)
- When tmux mouse mode is active (
- No backpressure exists (verified in code):
webContents.send()inevents.tsfires unconditionally- No mechanism for renderer to signal "slow down" to main process
- Main process will continue queuing IPC messages regardless of renderer state
- Unbounded flush buffer (verified in code):
buffer += datainpty-session-registry.tshas no size cap- Ring buffer is capped at 64KB, but active flush buffer is not
Hypothesized crash sequence (one plausible path, not confirmed):
- Mouse drag at high rate (~100+ events/sec, exact rate unknown)
- Renderer becomes CPU-bound from some combination of: DOM events, xterm parsing, Canvas repaints, IPC handling
- Main process continues sending via IPC (no backpressure)
- Renderer eventually crashes or becomes permanently unresponsive
Possible bottlenecks (not determined which, if any, is primary):
- CanvasAddon (Canvas2D) repaint frequency under rapid cursor movement
- IPC message serialization/deserialization overhead at high frequency
- V8 GC pressure from string allocations in both directions
- Electron renderer unresponsive detection
- Something else entirely (xterm.js internal state, Electron IPC limits)
Contributing factors (observed in code, severity unknown):
- Auto-copy selection debounce in
use-pty.tsadds work during drag - CanvasAddon (Canvas2D) may be less performant than WebGL for rapid repaints
Relevant Code Locations
| File | What to look for |
|---|---|
src/main/core/pty/pty-session-registry.ts |
buffer += data unbounded accumulation, 16ms flush timer |
src/main/lib/events.ts |
webContents.send() with no backpressure |
src/renderer/lib/pty/pty.ts |
terminal.write(data) no error handling in connect() |
src/renderer/lib/pty/use-pty.ts |
terminal.onData sends mouse input back to PTY; onSelectionChange debounce |
Suggested Fixes (Pending Root Cause Confirmation)
These are reasonable directions based on code inspection, but the right fix depends on profiling to identify the actual bottleneck:
- IPC backpressure: Implement flow control so main process pauses PTY forwarding when renderer signals overload (e.g., high-water mark on pending writes)
- Throttle xterm.write(): Batch incoming data per
requestAnimationFrameinstead of writing synchronously on every IPC message - Cap flush buffer: Add max size (e.g., 16KB) to the accumulation buffer in pty-session-registry, drop oldest data on overflow
- Consider WebGL addon:
@xterm/addon-webglhandles rapid repaints better than CanvasAddon for GPU-capable systems - Defensive try-catch: Wrap
terminal.write()in try-catch to prevent renderer crash if xterm ever does throw (defensive, not primary fix)
To confirm root cause, a developer could:
- Run Electron DevTools Performance profiler during reproduction
- Check
chrome://tracingfor IPC queue depth - Add temporary logging to measure events/sec during mouse drag
- Test with WebGL addon to see if crash still occurs
Thanks for flagging this, @yarisoy! Will keep you up to date here
@yarisoy is this still an issue on the latest version of emdash? we cannot reproduce
Apologies for the very late response. I didn't run into this issue for a while. Thank you for your great work!
Thank you for the update! @yarisoy