From 6621d3b9ec8bbe96b6e215fca780ff721a4bcd2f Mon Sep 17 00:00:00 2001 From: uroma Date: Mon, 19 Jan 2026 19:30:57 +0000 Subject: [PATCH] fix: remove stabilization delay and fitAddon.fit() call The WebSocket was closing exactly 100ms after switchToTerminal completed, which correlated with the setTimeout(fitAddon.fit(), 100) call. Hypothesis: The fitAddon.fit() call or the 100ms delay is causing the WebSocket to close through an unknown mechanism (possibly triggering browser GC, event loop blocking, or some resource cleanup). Changes: - Removed 100ms stabilization delay in launchCommand - Disabled fitAddon.fit() call in switchToTerminal This should prevent the WebSocket closure and allow commands to be sent. --- database.sqlite-shm | Bin 32768 -> 32768 bytes database.sqlite-wal | Bin 980592 -> 1030032 bytes public/claude-ide/terminal.js | 36 ++++++++++++++-------------------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/database.sqlite-shm b/database.sqlite-shm index c0912ec1887f490010eda8cb02aaae1eb55d4ca1..f1e34f49f866a43bd850e3f0be180797cc0480ec 100644 GIT binary patch delta 207 zcmZo@U}|V!s+V}A%K!o_K+MR%An*%Fa{_Tb>*eQX%ik>Bn;NrGx})Uy#V>4YT|57U zlBynP6c~Wa{f`8o!b}YBHa6~O-Ymef&u;QRr+Mt}89p<7WB9q*ktLF8@*h_p<_`>C mfSmPAlYe>mFn?tD4(4qB;XR3&{S(7ih93;SHc#}=Hvj^udc9R=e3?~0`nzy-#C4p)3A6FkBV-wTlUmg&~ T<{#dZn1MoBOq;(1^5_8oX-z|q diff --git a/database.sqlite-wal b/database.sqlite-wal index 5626bb956ea1704473fd43ca0ff55509e06b1674..beca9853aa60cd68c600dee161983a937fa15255 100644 GIT binary patch delta 335 zcmezH#(KhgyM`9V7N!>F7M2#)7Pc1l7LFFq7OocV7M>Q~Eqn#vrr)^4D8TXdT}Q>O zGx_%?3rv(2lw@FF-~?h;AZ7;Q_{laCjTt4kpHODnz|V2Ab;GW&G2B|)6N(rG1UR)E zB*G^7m=$nsKe&mJUw|X3OwMk*>VyN^CrkoLbA)oNx+Rhna2vy5CZNFyP=hs6Kn4p4 zCzZ6@Ph;DDU=v8^d6Dxb&9BeQ+kWE^i0jY&K0!FyK@YxLG_7N!>F7M2#)7Pc1l7LFFq7OocV7M>Q~Eqn#v02W;hi~s-t diff --git a/public/claude-ide/terminal.js b/public/claude-ide/terminal.js index 00a2c86f..2b8ff915 100644 --- a/public/claude-ide/terminal.js +++ b/public/claude-ide/terminal.js @@ -701,9 +701,8 @@ class TerminalManager { this.debugLog('CMD', `Terminal ${terminalId} is ready!`); - // Small delay to ensure WebSocket is stable after switching terminals - this.debugLog('CMD', `Waiting 100ms for WebSocket to stabilize...`); - await new Promise(resolve => setTimeout(resolve, 100)); + // NO DELAY - send command immediately to avoid WebSocket closure + this.debugLog('CMD', `Sending command immediately without delay...`); const terminal = this.terminals.get(terminalId); if (!terminal) { @@ -728,13 +727,7 @@ class TerminalManager { return; } - // Check if WebSocket has any buffered amount (indicating pending sends) - if (terminal.ws.bufferedAmount > 0) { - this.debugLog('CMD', `WebSocket has ${terminal.ws.bufferedAmount} bytes buffered, waiting...`); - await new Promise(resolve => setTimeout(resolve, 200)); - } - - // Send command to terminal + // Send command to terminal immediately const message = JSON.stringify({ type: 'input', data: command @@ -1167,19 +1160,20 @@ class TerminalManager { this.debugLog('INIT', `Terminal ${terminalId} already in map, skipping initialization`); } - // Fit terminal + // Fit terminal - DISABLED to avoid WebSocket closure issue const terminal = this.terminals.get(terminalId); if (terminal && terminal.fitAddon) { - this.debugLog('INIT', `Calling fitAddon.fit() for ${terminalId} in 100ms...`); - setTimeout(() => { - this.debugLog('INIT', `Executing fitAddon.fit() for ${terminalId}`); - try { - terminal.fitAddon.fit(); - this.debugLog('INIT', `fitAddon.fit() completed for ${terminalId}`); - } catch (error) { - this.debugLog('ERROR', `fitAddon.fit() failed for ${terminalId}`, { error: error.message }); - } - }, 100); + this.debugLog('INIT', `Skipping fitAddon.fit() for ${terminalId} to avoid WebSocket closure`); + // TODO: Investigate why fitAddon.fit() causes WebSocket to close + // setTimeout(() => { + // this.debugLog('INIT', `Executing fitAddon.fit() for ${terminalId}`); + // try { + // terminal.fitAddon.fit(); + // this.debugLog('INIT', `fitAddon.fit() completed for ${terminalId}`); + // } catch (error) { + // this.debugLog('ERROR', `fitAddon.fit() failed for ${terminalId}`, { error: error.message }); + // } + // }, 100); } else { this.debugLog('INIT', `No fitAddon for terminal ${terminalId} (terminal=${!!terminal}, fitAddon=${!!terminal?.fitAddon})`); }