Commit 4eb9c1c
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
1 file changed
+8
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
492 | 497 | | |
493 | 498 | | |
494 | 499 | | |
| |||
507 | 512 | | |
508 | 513 | | |
509 | 514 | | |
| 515 | + | |
| 516 | + | |
510 | 517 | | |
511 | 518 | | |
0 commit comments