Commit 59aeadd
fix(windows): daemon must NEVER die from uncaught errors
Three independent bugs that combined to crash the daemon on Windows:
1. **Duplicate uncaughtException handlers** — lifecycle.ts registered a
handler that called shutdown(1), index.ts registered a 'stays alive'
handler. Node calls ALL listeners, so the shutdown handler always
ran and the keep-alive log was just decoration. Daemon died on every
uncaught exception.
Fix: removed the lifecycle.ts handler. Single global handler in
index.ts.
2. **Stays-alive handler registered AFTER startup()** — node-pty can
throw synchronously from socket event callbacks during startup
(e.g. Cannot resize a pty that has already exited). If that fires
before line 125 of index.ts, no handler is installed yet and the
daemon dies on Node's default uncaughtException behavior.
Fix: moved the global handlers to the very top of index.ts (lines
3-30), BEFORE any imports. Now the handler is in place before any
module-load-time side effect can fire.
3. **conptyResize crashed on already-exited PTY** — node-pty's resize()
throws synchronously if the PTY has exited but the close event
hasn't propagated yet. This was hitting ConPTY sessions during
normal teardown.
Fix: skip resize when session.exited is true; wrap the call in
try/catch and mark exited if node-pty throws anyway.
Verified end-to-end on Windows: daemon survived multiple terminal
resize events that previously killed it. PID 1404180 still running.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 96eda9b commit 59aeadd
3 files changed
+43
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
328 | 338 | | |
329 | 339 | | |
330 | 340 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
767 | 767 | | |
768 | 768 | | |
769 | 769 | | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
774 | 774 | | |
775 | 775 | | |
776 | 776 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
2 | 29 | | |
3 | 30 | | |
4 | 31 | | |
| |||
103 | 130 | | |
104 | 131 | | |
105 | 132 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 133 | + | |
113 | 134 | | |
114 | 135 | | |
115 | 136 | | |
| |||
0 commit comments