-
Notifications
You must be signed in to change notification settings - Fork 205
Description
Description
Happy crashes completely when switching input from a remote device (e.g., iPhone via Universal Control) back to the main computer and entering local mode.
Environment
- Happy version: 0.11.2
- Claude Code version: 2.0.14
- OS: macOS (Darwin 24.6.0)
- Device setup: MacBook Pro M4 with iPhone input via Universal Control/Continuity
Steps to Reproduce
- Start Happy on Mac
- Begin typing from iPhone (via Universal Control or similar remote input method)
- Press space twice to trigger local mode switch
- Happy crashes completely and exits
Expected Behavior
Happy should gracefully handle the local mode switch even when input device state changes mid-session.
Actual Behavior
Happy crashes immediately with no error message when attempting to switch to local mode after device input switch.
Root Cause
When the input device switches mid-session, the TTY state becomes inconsistent. The code calls `process.stdin.setRawMode()` without error handling, which throws an exception when stdin is in an inconsistent state due to the device switch.
Affected Code Locations
- `dist/index-sSOy3f2x.mjs:2503` (setRawMode true)
- `dist/index-sSOy3f2x.mjs:2798` (setRawMode false)
- `dist/index-DmJ8WyYo.cjs:2525` (setRawMode true)
- `dist/index-DmJ8WyYo.cjs:2820` (setRawMode false)
- `dist/runCodex-BnjA1TX6.mjs:951` (setRawMode true)
- `dist/runCodex-DQPZNHzH.cjs:953` (setRawMode true)
Note: The runCodex files already have try-catch when setting to false (lines 1310-1313 and 1312-1314 respectively), but not when setting to true. The main index files have no error handling at all.
Proposed Fix
Wrap all `setRawMode()` calls in try-catch blocks to gracefully handle TTY state inconsistencies:
```javascript
if (process.stdin.isTTY) {
try {
process.stdin.setRawMode(true); // or false
} catch (err) {
logger.debug(`Failed to set raw mode: ${err.message}`);
}
}
```
This fix allows Happy to continue operating even when TTY state is inconsistent due to input device switching.
Workaround
Until fixed, avoid pressing space twice when typing from a remote device, as this triggers the local mode switch that causes the crash.
Status
I have tested a local patch with this fix and can confirm it resolves the crash. Happy now switches to local mode gracefully even when input device state changes.