From f431f626090371fbf2d1d323593bbb5e446da5a4 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 2 Feb 2026 19:24:55 +0100 Subject: [PATCH] fix(tui): pause stdin before restoring raw mode to prevent SSH session close Fixes #1185 --- packages/tui/CHANGELOG.md | 1 + packages/tui/src/terminal.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md index 1e07609c..ff67aed3 100644 --- a/packages/tui/CHANGELOG.md +++ b/packages/tui/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixed - Fixed unnecessary full redraws when appending many lines after content had previously shrunk (viewport check now uses actual previous content size instead of stale maximum) +- Fixed Ctrl+D exit closing the parent SSH session due to stdin buffer race condition ([#1185](https://github.com/badlogic/pi-mono/issues/1185)) ## [0.51.0] - 2026-02-01 diff --git a/packages/tui/src/terminal.ts b/packages/tui/src/terminal.ts index cc5d925a..9c852b3e 100644 --- a/packages/tui/src/terminal.ts +++ b/packages/tui/src/terminal.ts @@ -178,6 +178,11 @@ export class ProcessTerminal implements Terminal { this.resizeHandler = undefined; } + // Pause stdin to prevent any buffered input (e.g., Ctrl+D) from being + // re-interpreted after raw mode is disabled. This fixes a race condition + // where Ctrl+D could close the parent shell over SSH. + process.stdin.pause(); + // Restore raw mode state if (process.stdin.setRawMode) { process.stdin.setRawMode(this.wasRaw);