fix(adapter-utils): handle closed child stdin safely (#14057)

Handle closed child stdin without losing the child result.

Keep each child stdin error handler scoped to that child. Expected EPIPE
and stream-destroyed failures no longer crash the host. The child close
event remains the source of its exit result.

Verification: 2,024 tests passed and 12 live/platform cases skipped across
87 complete adapter-utils suites. The final 140-test server-utils suite
passed. The regression reproduces the EPIPE crash on unchanged master.

Final qualification: all applicable CI passed and exact-head Greptile Apex
scored 5/5 with no unresolved findings.

Co-Authored-By: Grzegorz Golaś <193330749+greegorij@users.noreply.github.com>
Co-Authored-By: Devin Foley <devinfoley@users.noreply.github.com>
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
authored and GitHub committed 2026-11-07 03:01:03 -08:00
1 parent d2efe3392b
commit 5a92d53f7d
2 files changed
+109 -5

No files matched your search

+24 -4
View File
@@ -4933,10 +4933,30 @@ export async function runChildProcess(
const stdin = child.stdin;
if (opts.stdin != null && stdin) {
void spawnPersistPromise.finally(() => {
if (child.killed || stdin.destroyed) return;
stdin.write(opts.stdin as string);
stdin.end();
let stdinFailureHandled = false;
const handleStdinFailure = (err: unknown) => {
if (!err || stdinFailureHandled) return;
stdinFailureHandled = true;
const code = (err as NodeJS.ErrnoException).code;
if (code === "EPIPE" || code === "ERR_STREAM_DESTROYED") return;
onLogError(err, runId, "failed to write child process stdin");
};
stdin.on("error", handleStdinFailure);
void spawnPersistPromise.then(() => {
if (
child.exitCode !== null ||
child.signalCode !== null ||
child.killed ||
stdin.destroyed
)
return;
try {
stdin.write(opts.stdin as string, handleStdinFailure);
stdin.end();
} catch (err) {
handleStdinFailure(err);
}
});
}