From 660ce7c54b9c397b2b1d23d9904159b645f04d30 Mon Sep 17 00:00:00 2001 From: Nexus Date: Tue, 28 Apr 2026 20:20:16 +0100 Subject: [PATCH] fix(ui-tui): prevent React effect cleanup from killing python TUI gateway subprocess MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The useEffect at useMainApp.ts:546-565 calls gw.kill() in its cleanup function. React calls cleanup on every re-render when the dependency array ([gw, sys]) shifts — which happens whenever sys changes identity (any system message). This sends SIGTERM to the Python TUI gateway subprocess, silently killing the backend mid-session. The kill path was already handled by entry.tsx's setupGracefulExit for real app exits (SIGINT, uncaught exception). The die() function also calls gw.kill() for explicit user exit. Removing the cleanup kill leaves all exit paths covered while preventing accidental mid-session kills on ordinary React re-renders. --- ui-tui/src/app/useMainApp.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-tui/src/app/useMainApp.ts b/ui-tui/src/app/useMainApp.ts index b39cc29a32..282f8da208 100644 --- a/ui-tui/src/app/useMainApp.ts +++ b/ui-tui/src/app/useMainApp.ts @@ -606,10 +606,10 @@ export function useMainApp(gw: GatewayClient) { gw.on('exit', exitHandler) gw.drain() + // entry.tsx's setupGracefulExit handles process cleanup on real exit. return () => { gw.off('event', handler) gw.off('exit', exitHandler) - gw.kill() } }, [gw, sys])