Temp-file open failure kills the process: createWriteStream has no error listener in either output path #1552
Jiaaqiliu
started this conversation in
Bug reports
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Environment. prime-agent 0.7.3,
mainat f8f0036, Node 22.17.0, macOS 15 (darwin 25.5.0).Summary
The two code paths that spill large tool output to a temp file create a
WriteStreamand write to it without registering an"error"listener.createWriteStreamreports open failures asynchronously via"error", so with no listener Node treats it as an unhandled error event and terminates the process.This fires on any tool output crossing the 50KB threshold whenever the temp directory is not writable.
Reproduction
In the agent: run any command producing more than 50KB with
TMPDIRpointing somewhere that does not exist. Real-world triggers are a staleTMPDIR, a full or read-only/tmp(ENOSPC/EROFS), and EMFILE under a wide subagent fan-out. The agent dies mid-turn with an ENOENT stack trace.Root cause
core/tools/output-accumulator.ts:205(ensureTempFile)core/bash-executor.ts:54(ensureTempFile)OutputAccumulatordoes attach an"error"listener, but only later insidecloseTempFile(:127), which is after the failure and is not reached on this path.bash-executor.tsnever attaches one.There is a second symptom on the same path:
end()on a stream that failed to open never emits"finish", socloseTempFilenever settles and the bash tool call hangs.Suggested fix
Register the listener at creation and degrade rather than die: mark the temp file as failed, clear the path so callers stop advertising a file that does not exist, and keep returning the truncated output that is already held separately in memory. Losing the full-output file is recoverable; losing the process mid-turn is not.
I have a fix with a regression test on a branch:
fix/temp-file-stream-error.npm run checkpasses and the surrounding suites still pass. I opened it as a PR first and the contribution gate closed it, which is what CONTRIBUTING.md says should happen, so I am bringing it here instead. Happy to leave it as is, adjust it, or drop it entirely if you would rather fix this differently.All reactions