The best way to control Claude Code, Codex and more from any computer or phone
fix(acp): preserve outgoing error data (#32390)
Co-authored-by: GPT 6.1 Sol <codex@openai.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Wout Stiens committed
Nov 12, 2026 at 00:05 UTC
1f6d9e789a4bbb7bf69674174f77d2b61ad0b604
4 files changed
+159
-3
packages/effect-acp/src/agent.test.ts
+4
-1
@@ -37,7 +37,10 @@ const ExtRequest = jsonRpcRequest("x/test", Schema.Struct({ hello: Schema.String
37
const ExtResponse = jsonRpcResponse(Schema.Struct({ ok: Schema.Boolean }));
38
const DieResponse = Schema.Struct({
39
id: Schema.Number,
40
- error: Schema.TaggedStruct("Cause", { data: Schema.Tuple([Schema.TaggedStruct("Die", {})]) }),
40
+ error: Schema.Struct({
41
+ code: Schema.Literal(-32603),
42
+ message: Schema.Literal("Internal error"),
43
+ }),
44
});
45
const decodeRequestPermissionRequest = Schema.decodeEffect(
46
Schema.fromJsonString(RequestPermissionRequest),
packages/effect-acp/src/client.test.ts
+4
-1
@@ -54,7 +54,10 @@ const PermissionResponse = jsonRpcResponse(AcpSchema.RequestPermissionResponse);
54
const ErrorResponse = Schema.Struct({ id: Schema.String, error: Schema.Unknown });
55
const DieResponse = Schema.Struct({
56
id: Schema.String,
57
- error: Schema.TaggedStruct("Cause", { data: Schema.Tuple([Schema.TaggedStruct("Die", {})]) }),
57
+ error: Schema.Struct({
58
+ code: Schema.Literal(-32603),
59
+ message: Schema.Literal("Internal error"),
60
+ }),
61
});
62
const decodePromptRequestLine = Schema.decodeEffect(Schema.fromJsonString(PromptRequest));
63
const XAiPromptCompleteNotification = jsonRpcNotification(
packages/effect-acp/src/protocol.test.ts
+119
@@ -653,6 +653,125 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => {
653
}),
654
);
655
656
+ it.effect("preserves application error data in outgoing extension responses", () =>
657
+ Effect.gen(function* () {
658
+ const { stdio, input, output } = yield* makeInMemoryStdio();
659
+ const acknowledged = yield* Deferred.make<string>();
660
+ yield* AcpProtocol.makeAcpPatchedProtocol({
661
+ stdio,
662
+ serverRequestMethods: new Set(),
663
+ onExtRequest: () =>
664
+ Effect.fail(AcpError.AcpRequestError.invalidParams("bad input", { field: "name" })),
665
+ onOutgoingResponse: (requestId) =>
666
+ Deferred.succeed(acknowledged, requestId).pipe(Effect.asVoid),
667
+ });
668
+
669
+ yield* Queue.offer(
670
+ input,
671
+ encoder.encode(
672
+ encodeUnknownJsonString({
673
+ jsonrpc: "2.0",
674
+ id: "peer-1",
675
+ method: "x/test",
676
+ params: {},
677
+ }) + "\n",
678
+ ),
679
+ );
680
+
681
+ assert.deepEqual(JSON.parse(yield* Queue.take(output)), {
682
+ jsonrpc: "2.0",
683
+ id: "peer-1",
684
+ error: { code: -32602, message: "bad input", data: { field: "name" } },
685
+ });
686
+ assert.equal(yield* Deferred.await(acknowledged), "peer-1");
687
+ }),
688
+ );
689
+
690
+ it.effect("completes a batch with successful and failed extension responses", () =>
691
+ Effect.gen(function* () {
692
+ const { stdio, input, output } = yield* makeInMemoryStdio();
693
+ const acknowledgements = yield* Queue.unbounded<string>();
694
+ yield* AcpProtocol.makeAcpPatchedProtocol({
695
+ stdio,
696
+ serverRequestMethods: new Set(),
697
+ onExtRequest: (method) =>
698
+ method === "x/success"
699
+ ? Effect.succeed({ ok: true })
700
+ : Effect.fail(AcpError.AcpRequestError.invalidParams("bad input", { field: "name" })),
701
+ onOutgoingResponse: (requestId) => Queue.offer(acknowledgements, requestId),
702
+ });
703
+
704
+ yield* Queue.offer(
705
+ input,
706
+ encoder.encode(
707
+ encodeUnknownJsonString([
708
+ { jsonrpc: "2.0", id: 0, method: "x/success", params: {} },
709
+ { jsonrpc: "2.0", id: "peer-1", method: "x/failure", params: {} },
710
+ ]) + "\n",
711
+ ),
712
+ );
713
+
714
+ assert.deepEqual(JSON.parse(yield* Queue.take(output)), [
715
+ { jsonrpc: "2.0", id: 0, result: { ok: true } },
716
+ {
717
+ jsonrpc: "2.0",
718
+ id: "peer-1",
719
+ error: { code: -32602, message: "bad input", data: { field: "name" } },
720
+ },
721
+ ]);
722
+ assert.equal(yield* Queue.take(acknowledgements), "peer-1");
723
+ }),
724
+ );
725
+
726
+ it.effect.each([
727
+ {
728
+ name: "typed failure",
729
+ cause: [{ _tag: "Fail", error: { code: -32602, message: "bad input", data: null } }],
730
+ error: { code: -32602, message: "bad input", data: null },
731
+ },
732
+ {
733
+ name: "typed failure with interruption",
734
+ cause: [
735
+ { _tag: "Fail", error: { code: -32602, message: "bad input", data: { field: "name" } } },
736
+ { _tag: "Interrupt", fiberId: null },
737
+ ],
738
+ error: { code: -32602, message: "bad input", data: { field: "name" } },
739
+ },
740
+ {
741
+ name: "defect",
742
+ cause: [{ _tag: "Die", defect: "private defect" }],
743
+ error: { code: -32603, message: "Internal error" },
744
+ },
745
+ {
746
+ name: "failure with a defect",
747
+ cause: [
748
+ { _tag: "Fail", error: { code: -32602, message: "bad input" } },
749
+ { _tag: "Die", defect: "private defect" },
750
+ ],
751
+ error: { code: -32603, message: "Internal error" },
752
+ },
753
+ ] as const)("emits a standard ACP error for a core $name", ({ cause, error }) =>
754
+ Effect.gen(function* () {
755
+ const { stdio, output } = yield* makeInMemoryStdio();
756
+ const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
757
+ stdio,
758
+ serverRequestMethods: new Set(),
759
+ });
760
+
761
+ yield* transport.serverProtocol.send(0, {
762
+ _tag: "Exit",
763
+ requestId: 0,
764
+ exit: { _tag: "Failure", cause },
765
+ });
766
+
767
+ assert.deepEqual(JSON.parse(yield* Queue.take(output)), {
768
+ jsonrpc: "2.0",
769
+ id: 0,
770
+ error,
771
+ });
772
+ }),
773
+ );
774
+
775
it.effect("answers an extension request whose handler also dies as an internal error", () =>
776
Effect.gen(function* () {
777
const { stdio, input, output } = yield* makeInMemoryStdio();
packages/effect-acp/src/protocol.ts
+32
-1
@@ -211,10 +211,41 @@ const makeStrictNdJsonRpcParser = () => {
211
},
212
encode: (response: Parameters<typeof codec.encode>[0]) => {
213
const encoded = codec.encode(response);
214
- return encoded === undefined ? undefined : `${encoded}\n`;
214
+ if (encoded === undefined) return undefined;
215
+ const json = typeof encoded === "string" ? encoded : new TextDecoder().decode(encoded);
216
+ if (!json.includes('"_tag":"Cause"')) return `${json}\n`;
217
+ return `${JSON.stringify(normalizeOutgoingFrame(JSON.parse(json)))}\n`;
218
},
219
};
220
};
221
+const isCauseResponse = Schema.is(
222
+ Schema.Struct({
223
+ error: Schema.TaggedStruct("Cause", { data: Schema.Array(Schema.Unknown) }),
224
+ }),
225
+);
226
+const isProtocolFailure = Schema.is(Schema.TaggedStruct("Fail", { error: AcpSchema.Error }));
227
+const isInterruptReason = Schema.is(Schema.TaggedStruct("Interrupt", {}));
228
+
229
+// Normalize only Effect's error envelope after the codec has completed batch tracking.
230
+function normalizeOutgoingFrame(frame: unknown): unknown {
231
+ if (Array.isArray(frame)) return frame.map(normalizeOutgoingFrame);
232
+ if (!isCauseResponse(frame)) return frame;
233
+ const reasons = frame.error.data.filter((reason) => !isInterruptReason(reason));
234
+ const [failure] = reasons;
235
+ const error =
236
+ reasons.length === 1 && isProtocolFailure(failure)
237
+ ? failure.error
238
+ : AcpError.AcpRequestError.internalError().toProtocolError();
239
+ return {
240
+ ...frame,
241
+ error: {
242
+ code: error.code,
243
+ message: error.message,
244
+ ...(error.data === undefined ? {} : { data: error.data }),
245
+ },
246
+ };
247
+}
248
+
249
// Unread raw notifications are best-effort. The newest is always kept; older
250
// ones are dropped once the backlog passes either limit. The length limit counts
251
// JSON line characters (UTF-16 code units), not bytes or heap size.