The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 08:15 UTC
fix(codex): a failed write to the app-server no longer leaves requests hanging (#27924)
Co-authored-by: Trevor Edwards <9443483+trevoedwards@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Trevor committed
Oct 31, 2026 at 19:43 UTC
34cfd24849419dc07df51e828809e5659f15b6e1
3 files changed
+54
-1
packages/effect-codex-app-server/src/errors.ts
+1
@@ -109,6 +109,7 @@ export type CodexAppServerProtocolParseOperation = typeof CodexAppServerProtocol
109
110
export const CodexAppServerTransportOperation = Schema.Literals([
111
"read-input-stream",
112
+ "write-output-stream",
113
"read-process-exit-status",
114
]);
115
export type CodexAppServerTransportOperation = typeof CodexAppServerTransportOperation.Type;
packages/effect-codex-app-server/src/protocol.test.ts
+39
@@ -1,8 +1,10 @@
1
import * as Deferred from "effect/Deferred";
2
import * as Effect from "effect/Effect";
3
import * as Fiber from "effect/Fiber";
4
+import * as PlatformError from "effect/PlatformError";
5
import * as Queue from "effect/Queue";
6
import * as Schema from "effect/Schema";
7
+import * as Sink from "effect/Sink";
8
import * as Stdio from "effect/Stdio";
9
import * as Stream from "effect/Stream";
10
import * as TestClock from "effect/testing/TestClock";
@@ -740,6 +742,43 @@ it.layer(NodeServices.layer)("effect-codex-app-server protocol", (it) => {
742
}),
743
);
744
745
+ it.effect("fails pending requests when a write fails while input stays open", () =>
746
+ Effect.gen(function* () {
747
+ const { stdio: baseStdio } = yield* makeInMemoryStdio();
748
+ const writeFailure = PlatformError.systemError({
749
+ _tag: "Unknown",
750
+ module: "Stdio",
751
+ method: "stdout",
752
+ cause: new Error("EPIPE"),
753
+ });
754
+ const terminated = yield* Deferred.make<CodexError.CodexAppServerError>();
755
+ const transport = yield* CodexProtocol.makeCodexAppServerPatchedProtocol({
756
+ stdio: Stdio.make({
757
+ args: baseStdio.args,
758
+ stdin: baseStdio.stdin,
759
+ stdout: () => Sink.forEach(() => Effect.fail(writeFailure)),
760
+ stderr: baseStdio.stderr,
761
+ }),
762
+ onTermination: (error) => Deferred.succeed(terminated, error).pipe(Effect.asVoid),
763
+ });
764
+ const pending = yield* transport.request("thread/read", {}).pipe(Effect.forkScoped);
765
+
766
+ const failure = yield* Deferred.await(terminated);
767
+ assert.instanceOf(failure, CodexError.CodexAppServerTransportError);
768
+ assert.equal(failure.operation, "write-output-stream");
769
+ assert.strictEqual(failure.cause, writeFailure);
770
+ for (const request of [Fiber.join(pending), transport.request("thread/read", {})]) {
771
+ const requestFailure = yield* request.pipe(
772
+ Effect.match({
773
+ onFailure: (error) => error,
774
+ onSuccess: () => assert.fail("Expected the broken transport to reject the request"),
775
+ }),
776
+ );
777
+ assert.strictEqual(requestFailure, failure);
778
+ }
779
+ }),
780
+ );
781
+
782
it.effect("reports a process exit that follows input end", () =>
783
Effect.gen(function* () {
784
const { stdio, input } = yield* makeInMemoryStdio();
packages/effect-codex-app-server/src/protocol.ts
+14
-1
@@ -479,7 +479,20 @@ export const makeCodexAppServerPatchedProtocol = Effect.fn("makeCodexAppServerPa
479
Effect.forkScoped,
480
);
481
482
- yield* Stream.fromQueue(outgoing).pipe(Stream.run(options.stdio.stdout()), Effect.forkScoped);
482
+ yield* Stream.fromQueue(outgoing).pipe(
483
+ Stream.run(options.stdio.stdout()),
484
+ Effect.catch((cause) =>
485
+ handleTermination(() =>
486
+ Effect.succeed(
487
+ new CodexError.CodexAppServerTransportError({
488
+ operation: "write-output-stream",
489
+ cause,
490
+ }),
491
+ ),
492
+ ),
493
+ ),
494
+ Effect.forkScoped,
495
+ );
496
497
const request = Effect.fn("CodexAppServerProtocol.request")(function* (
498
method: string,