Skip to content

Commit 4eb9c1c

Browse files
authored
🤖 fix: keep process alive when stdin closes in agentSessionCli (#529)
## Problem Terminal-bench was failing with all tasks showing 0 input/output tokens because the agent was exiting immediately after receiving the user message, without making any API calls. **Symptoms:** - Latest nightly runs (Nov 5-7): All 80 tasks failed with `agent_timeout` - Agent ran for only ~45 seconds then exited - `total_input_tokens: 0`, `total_output_tokens: 0` - Stream started with `caught-up` and `user` message, but no `stream-delta` or `stream-end` events **Root cause:** The `agentSessionCli.ts` reads the user message from stdin via a pipe: ```bash printf '%s' "$instruction" | bun src/debug/agentSessionCli.ts ... ``` Once stdin reaches EOF and is consumed, Bun detects no other active handles keeping the event loop alive and exits the process, **even though async work (API streaming) is still pending**. ## Solution Add an explicit keepalive interval that ensures the process stays alive until `main()` completes. The interval runs far into the future (1000 seconds) but gets cleared in the finally block once the agent session finishes. ## Testing **Before fix:** - Run #19173435224: 1 task, 0 tokens, ~2 min total (agent ran 45s) - Agent exited immediately after user message **After fix:** - Run #19173548174: 1 task, **resolved: true**, ~7 min total (agent ran 3m17s) - 22 tool calls made - Stream-delta events present - Agent completed successfully ## Related - Fixes nightly terminal-bench failures from Nov 5-7 - Related to PR #507 (dist/ in archive) and PR #513 (build step in workflow) _Generated with `cmux`_
1 parent 0da5381 commit 4eb9c1c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/debug/agentSessionCli.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,12 @@ async function main(): Promise<void> {
488488
}
489489
}
490490

491-
void (async () => {
491+
// Keep process alive explicitly - Bun may exit when stdin closes even if async work is pending
492+
const keepAliveInterval = setInterval(() => {
493+
// No-op to keep event loop alive
494+
}, 1000000);
495+
496+
(async () => {
492497
try {
493498
await main();
494499
} catch (error) {
@@ -507,5 +512,7 @@ void (async () => {
507512
process.stderr.write(`Error: ${message}\n`);
508513
}
509514
process.exitCode = 1;
515+
} finally {
516+
clearInterval(keepAliveInterval);
510517
}
511518
})();

0 commit comments

Comments
 (0)