@devries-cameron20 / t3code-1 / commits / 82503ccf2e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(acp): fail requests when stdout closes before the agent exits (#21323)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Oct 31, 2026 at 03:37 UTC 82503ccf2e20fbfdf7e6637215d233c5bb63acd5
2 files changed +41 -4
packages/effect-acp/src/protocol.test.ts
+30
@@ -868,6 +868,36 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => {
868 }),
869 );
870
871 + it.effect("fails pending and later requests when input ends before the process exits", () =>
872 + Effect.gen(function* () {
873 + const { stdio, input, output } = yield* makeInMemoryStdio();
874 + const termination = yield* Deferred.make<AcpError.AcpError>();
875 + const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
876 + stdio,
877 + terminationError: Effect.never,
878 + serverRequestMethods: new Set(),
879 + onTermination: (error) => Deferred.succeed(termination, error).pipe(Effect.asVoid),
880 + });
881 + const pending = yield* transport
882 + .request("x/test", { hello: "world" })
883 + .pipe(Effect.flip, Effect.orDie, Effect.forkScoped);
884 + yield* Queue.take(output);
885 + yield* Queue.end(input);
886 +
887 + const error = yield* Deferred.await(termination);
888 + assert.instanceOf(error, AcpError.AcpInputStreamEndedError);
889 + assert.strictEqual(yield* Fiber.join(pending), error);
890 + assert.strictEqual(
891 + yield* transport.request("x/test", { hello: "later" }).pipe(Effect.flip, Effect.orDie),
892 + error,
893 + );
894 + assert.strictEqual(
895 + yield* transport.notify("session/cancel", { sessionId: "session-1" }).pipe(Effect.flip),
896 + error,
897 + );
898 + }),
899 + );
900 +
901 it.effect("propagates the real child exit code when the input stream ends", () =>
902 Effect.gen(function* () {
903 const handle = yield* makeHandle({ ACP_MOCK_EXIT_IMMEDIATELY_CODE: "7" });
packages/effect-acp/src/protocol.ts
+11 -4
@@ -1,5 +1,6 @@
1 import type * as AcpCompat from "./compat.ts";
2 import * as Cause from "effect/Cause";
3 +import * as Clock from "effect/Clock";
4 import * as Effect from "effect/Effect";
5 import * as Deferred from "effect/Deferred";
6 import * as Exit from "effect/Exit";
@@ -756,10 +757,16 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
757 return handleTermination(() => Effect.succeed(normalized));
758 },
759 onSuccess: () =>
759 - handleTermination(
760 - () =>
761 - options.terminationError ?? Effect.succeed(new AcpError.AcpInputStreamEndedError({})),
762 - ),
760 + handleTermination(() => {
761 + const ended = new AcpError.AcpInputStreamEndedError({});
762 + if (!options.terminationError) return Effect.succeed(ended);
763 + // Stdout can close without process exit; use a live-clock diagnostic grace period.
764 + return options.terminationError.pipe(
765 + Effect.timeoutOption("250 millis"),
766 + Effect.provideService(Clock.Clock, Clock.Clock.defaultValue()),
767 + Effect.map(Option.getOrElse(() => ended)),
768 + );
769 + }),
770 }),
771 Effect.forkScoped,
772 );