You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(cli): prevent zombie socket reconnections when MacBook lid is closed
When a MacBook lid closes, macOS powers down WiFi hardware even though
caffeinate keeps the CPU alive. During Power Nap (~every 15 min), WiFi
briefly activates for 1-3 seconds — just long enough for socket.io to
auto-reconnect. The server sees these brief connections as "active"
sessions, creating zombies that appear reachable but aren't.
The fix: disable socket.io's built-in reconnection entirely and manage
it ourselves. On disconnect, we check two conditions before reconnecting:
1. hasNetworkConnectivity() — os.networkInterfaces() has a non-internal
IPv4 address (cross-platform, instant, no subprocess)
2. !isLidClosed() — ioreg AppleClamshellState is not Yes (macOS only,
returns false on other platforms so reconnection proceeds normally)
If either check fails, we poll every 5s until both pass. This was
validated with a multi-probe test comparing four socket strategies
side-by-side through multiple Power Nap cycles:
- SOCK-BASELINE (socket.io auto): reconnected every Power Nap ✗
- SOCK-CAFF (with caffeinate): reconnected every Power Nap ✗
- SOCK-MANUAL (our fix): stayed disconnected through all
Power Nap cycles, reconnected instantly when lid opened ✓
Additional changes:
- Caffeinate only managed by daemon now (removed from individual
sessions to prevent process leaks — was spawning per-session)
- Orphaned caffeinate processes cleaned up on daemon startup
- External display detection via system_profiler JSON for clamshell
mode support (lid closed + monitor = stay connected)
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
0 commit comments