From 4b7d3906da62f9e3bf3605638635d40455e9df74 Mon Sep 17 00:00:00 2001 From: Ammar Date: Fri, 7 Nov 2025 15:59:44 +0000 Subject: [PATCH 1/2] fix: keep process alive when stdin closes in agentSessionCli Terminal-bench was failing with all tasks showing 0 input/output tokens because Bun was exiting immediately after stdin closed, even though async work (API calls) was still pending. The agentSessionCli reads the user message from stdin, then waits for stream completion. However, once stdin reaches EOF and is consumed, Bun may exit if it detects no other active handles keeping the event loop alive. Add an explicit keepalive interval that ensures the process stays alive until main() completes. This interval runs far into the future but gets cleared in the finally block once the agent session finishes. This fixes the nightly terminal-bench failures where all 80 tasks were failing with agent_timeout and 0 tokens. --- src/debug/agentSessionCli.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/debug/agentSessionCli.ts b/src/debug/agentSessionCli.ts index 0b0c0f429..add1a5a56 100644 --- a/src/debug/agentSessionCli.ts +++ b/src/debug/agentSessionCli.ts @@ -488,7 +488,10 @@ async function main(): Promise { } } -void (async () => { +// Keep process alive explicitly - Bun may exit when stdin closes even if async work is pending +const keepAliveInterval = setInterval(() => {}, 1000000); + +(async () => { try { await main(); } catch (error) { @@ -507,5 +510,7 @@ void (async () => { process.stderr.write(`Error: ${message}\n`); } process.exitCode = 1; + } finally { + clearInterval(keepAliveInterval); } })(); From 7d8aa1c77fa8caf6bbad7ec06d5b8511c83e2808 Mon Sep 17 00:00:00 2001 From: Ammar Date: Fri, 7 Nov 2025 16:02:07 +0000 Subject: [PATCH 2/2] lint: add comment to keepalive interval to satisfy no-empty-function rule --- src/debug/agentSessionCli.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/debug/agentSessionCli.ts b/src/debug/agentSessionCli.ts index add1a5a56..0b1f1e1e0 100644 --- a/src/debug/agentSessionCli.ts +++ b/src/debug/agentSessionCli.ts @@ -489,7 +489,9 @@ async function main(): Promise { } // Keep process alive explicitly - Bun may exit when stdin closes even if async work is pending -const keepAliveInterval = setInterval(() => {}, 1000000); +const keepAliveInterval = setInterval(() => { + // No-op to keep event loop alive +}, 1000000); (async () => { try {