From e8db5ca3be8f9e7ead3e060cc9fb302580feae7d Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Sun, 18 Oct 2026 12:51:12 -0500 Subject: [PATCH 1/3] test(acp): cover stdout closing before the agent exits Co-Authored-By: Claude Opus 5.5 --- packages/effect-acp/src/protocol.test.ts | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/effect-acp/src/protocol.test.ts b/packages/effect-acp/src/protocol.test.ts index cc0a3ea7e3c08..e757153fa443c 100644 --- a/packages/effect-acp/src/protocol.test.ts +++ b/packages/effect-acp/src/protocol.test.ts @@ -1193,6 +1193,35 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => { }), ); + it.effect("fails pending and later requests when input ends before the process exits", () => + Effect.gen(function* () { + const { stdio, input, output } = yield* makeInMemoryStdio(); + const terminated = yield* Deferred.make(); + const transport = yield* AcpProtocol.makeAcpPatchedProtocol({ + stdio, + terminationError: Effect.never, + serverRequestMethods: new Set(), + onTermination: (error) => Deferred.succeed(terminated, error).pipe(Effect.asVoid), + }); + + const pending = yield* transport + .request("x/test", {}) + .pipe(Effect.asVoid, Effect.flip, Effect.forkScoped); + yield* Queue.take(output); + yield* Queue.end(input); + + const error = yield* TestClock.withLive( + Deferred.await(terminated).pipe(Effect.timeout("2 seconds")), + ); + assert.instanceOf(error, AcpError.AcpInputStreamEndedError); + assert.strictEqual(yield* Fiber.join(pending), error); + assert.strictEqual( + yield* transport.request("x/test", {}).pipe(Effect.asVoid, Effect.flip), + error, + ); + }), + ); + it.effect("fails pending extension requests with the propagated exit code", () => Effect.gen(function* () { const { stdio, input, output } = yield* makeInMemoryStdio(); From 83d147d7a61834a8b4855508626290669023b2b9 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Sun, 18 Oct 2026 12:51:39 -0500 Subject: [PATCH 2/3] fix(acp): fail requests when stdout closes before the agent exits When an ACP agent closed stdout but kept running, the protocol waited for its exit status with no bound. Pending requests never failed and later requests waited on the unfinished termination. Wait at most 250 ms for the exit status, then end the connection with the existing input-stream-ended error. An exit status that arrives in time is still reported. Co-Authored-By: Claude Opus 5.5 --- packages/effect-acp/src/protocol.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/effect-acp/src/protocol.ts b/packages/effect-acp/src/protocol.ts index 1be22e0af460f..8f631a86dc940 100644 --- a/packages/effect-acp/src/protocol.ts +++ b/packages/effect-acp/src/protocol.ts @@ -1,5 +1,6 @@ import type * as AcpCompat from "./compat.ts"; import * as Cause from "effect/Cause"; +import * as Clock from "effect/Clock"; import * as Effect from "effect/Effect"; import * as Deferred from "effect/Deferred"; import * as Exit from "effect/Exit"; @@ -734,10 +735,17 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi return handleTermination(() => Effect.succeed(normalized)); }, onSuccess: () => - handleTermination( - () => - options.terminationError ?? Effect.succeed(new AcpError.AcpInputStreamEndedError({})), - ), + handleTermination(() => { + const ended = new AcpError.AcpInputStreamEndedError({}); + if (!options.terminationError) return Effect.succeed(ended); + // An agent can close stdout and keep running. Bound the wait for its + // exit status, on the live clock so a test clock cannot stall it. + return options.terminationError.pipe( + Effect.timeoutOption("250 millis"), + Effect.provideService(Clock.Clock, Clock.Clock.defaultValue()), + Effect.map(Option.getOrElse(() => ended)), + ); + }), }), Effect.forkScoped, ); From c574f4c666097617c372338278ee896987bf4318 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Mon, 26 Oct 2026 03:34:25 +0000 Subject: [PATCH 3/3] test(acp): cover requests after stdout closes without process exit --- packages/effect-acp/src/protocol.test.ts | 30 ++++++++++++++++++++++++ packages/effect-acp/src/protocol.ts | 3 +-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/effect-acp/src/protocol.test.ts b/packages/effect-acp/src/protocol.test.ts index 2ee7347537fb6..e9a5f1187d32e 100644 --- a/packages/effect-acp/src/protocol.test.ts +++ b/packages/effect-acp/src/protocol.test.ts @@ -867,6 +867,36 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => { }), ); + it.effect("fails pending and later requests when input ends before the process exits", () => + Effect.gen(function* () { + const { stdio, input, output } = yield* makeInMemoryStdio(); + const termination = yield* Deferred.make(); + const transport = yield* AcpProtocol.makeAcpPatchedProtocol({ + stdio, + terminationError: Effect.never, + serverRequestMethods: new Set(), + onTermination: (error) => Deferred.succeed(termination, error).pipe(Effect.asVoid), + }); + const pending = yield* transport + .request("x/test", { hello: "world" }) + .pipe(Effect.flip, Effect.orDie, Effect.forkScoped); + yield* Queue.take(output); + yield* Queue.end(input); + + const error = yield* Deferred.await(termination); + assert.instanceOf(error, AcpError.AcpInputStreamEndedError); + assert.strictEqual(yield* Fiber.join(pending), error); + assert.strictEqual( + yield* transport.request("x/test", { hello: "later" }).pipe(Effect.flip, Effect.orDie), + error, + ); + assert.strictEqual( + yield* transport.notify("session/cancel", { sessionId: "session-1" }).pipe(Effect.flip), + error, + ); + }), + ); + it.effect("propagates the real child exit code when the input stream ends", () => Effect.gen(function* () { const handle = yield* makeHandle({ ACP_MOCK_EXIT_IMMEDIATELY_CODE: "7" }); diff --git a/packages/effect-acp/src/protocol.ts b/packages/effect-acp/src/protocol.ts index 00695c2587dd5..084e7752bda96 100644 --- a/packages/effect-acp/src/protocol.ts +++ b/packages/effect-acp/src/protocol.ts @@ -760,8 +760,7 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi handleTermination(() => { const ended = new AcpError.AcpInputStreamEndedError({}); if (!options.terminationError) return Effect.succeed(ended); - // An agent can close stdout and keep running. Bound the wait for its - // exit status, on the live clock so a test clock cannot stall it. + // Stdout can close without process exit; use a live-clock diagnostic grace period. return options.terminationError.pipe( Effect.timeoutOption("250 millis"), Effect.provideService(Clock.Clock, Clock.Clock.defaultValue()),