Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

[RSI, bug] fix(coding-agent): absorb kernel child stderr stream errors like stdin/stdout (#2383)

Seth Kartenb6b94c78a774
diff --git a/packages/coding-agent/.changes/kernel-stderr-pipe-error.md b/packages/coding-agent/.changes/kernel-stderr-pipe-error.md
new file mode 100644
index 0000000000..514dee4849
--- /dev/null
+++ b/packages/coding-agent/.changes/kernel-stderr-pipe-error.md
@@ -0,0 +1 @@
+- Fixed an unhandled error on the kernel child stderr pipe crashing the daemon worker: the stream now records a kernel diagnostic like stdin and stdout instead of reaching the daemon uncaughtException handler and exiting with every hosted session.
diff --git a/packages/coding-agent/src/core/kernel/repl-manager.ts b/packages/coding-agent/src/core/kernel/repl-manager.ts
index 9413847708..396e284281 100644
--- a/packages/coding-agent/src/core/kernel/repl-manager.ts
+++ b/packages/coding-agent/src/core/kernel/repl-manager.ts
@@ -462,7 +462,8 @@ export class ReplKernelManager {
// stream (write EPIPE); without a listener Node rethrows it and takes
// down the whole worker. The pending writeLine rejection and the child
// 'exit' handler below own the fallout, so this only records the
- // diagnosis.
+ // diagnosis. Read-side pipe errors on stdout/stderr land the same way
+ // and need the same guard.
child.stdin?.on("error", (error) => {
if (this.child !== child) return;
this.appendKernelDiagnostic(`kernel stdin error: ${errorMessage(error)}`);
@@ -471,6 +472,10 @@ export class ReplKernelManager {
if (this.child !== child) return;
this.appendKernelDiagnostic(`kernel stdout error: ${errorMessage(error)}`);
});
+ child.stderr?.on("error", (error) => {
+ if (this.child !== child) return;
+ this.appendKernelDiagnostic(`kernel stderr error: ${errorMessage(error)}`);
+ });
child.once("exit", () => {
// One turn for the poll phase to deliver the bytes the kernel wrote
// before dying (the pipe buffer bounds them), then destroy: EOF may
diff --git a/packages/coding-agent/test/repl-kernel-pipe-errors.test.ts b/packages/coding-agent/test/repl-kernel-pipe-errors.test.ts
index 46266cd42c..d40026b3f7 100644
--- a/packages/coding-agent/test/repl-kernel-pipe-errors.test.ts
+++ b/packages/coding-agent/test/repl-kernel-pipe-errors.test.ts
@@ -47,11 +47,13 @@ describeIf("ReplKernelManager pipe errors (real runtime)", () => {
const child = (manager as unknown as { child?: ChildProcess }).child;
expect(child?.stdin).toBeDefined();
expect(child?.stdout).toBeDefined();
+ expect(child?.stderr).toBeDefined();
// A write racing the kernel's death lands as an 'error' event on the pipe;
// without a listener Node would crash the worker (observed in production as
- // "uncaught exception: Error: write EPIPE").
+ // "write EPIPE"). Read-side pipes need the same guard.
expect(() => child?.stdin?.emit("error", new Error("write EPIPE"))).not.toThrow();
expect(() => child?.stdout?.emit("error", new Error("read ECONNRESET"))).not.toThrow();
+ expect(() => child?.stderr?.emit("error", new Error("read ECONNRESET"))).not.toThrow();
// The kernel is still healthy: further cells keep executing and shutdown
// (afterEach) still completes.