drain stdin on exit (#17241)

This commit is contained in:
Tommaso Sciortino
2026-01-21 13:13:10 -08:00
committed by GitHub
parent a91665db40
commit dce450b1e8

View File

@@ -55,6 +55,10 @@ export function registerTelemetryConfig(config: Config) {
}
export async function runExitCleanup() {
// drain stdin to prevent printing garbage on exit
// https://github.com/google-gemini/gemini-cli/issues/1680
await drainStdin();
runSyncCleanup();
for (const fn of cleanupFunctions) {
try {
@@ -84,6 +88,18 @@ export async function runExitCleanup() {
}
}
async function drainStdin() {
if (!process.stdin?.isTTY) return;
// Resume stdin and attach a no-op listener to drain the buffer.
// We use removeAllListeners to ensure we don't trigger other handlers.
process.stdin
.resume()
.removeAllListeners('data')
.on('data', () => {});
// Give it a moment to flush the OS buffer.
await new Promise((resolve) => setTimeout(resolve, 50));
}
export async function cleanupCheckpoints() {
const storage = new Storage(process.cwd());
const tempDir = storage.getProjectTempDir();