The best way to control Claude Code, Codex and more from any computer or phone
fix(acp): a final agent message without a trailing newline is no longer dropped (#29605)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:15 UTC
6d80df55bba5994c3d5faccb1dfc618c0f712520
2 files changed
+45
packages/effect-acp/src/protocol.test.ts
+22
@@ -884,6 +884,7 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => {
884
.request("x/test", { hello: "world" })
885
.pipe(Effect.flip, Effect.orDie, Effect.forkScoped);
886
yield* Queue.take(output);
887
+ yield* Queue.offer(input, encoder.encode('{"jsonrpc":"2.0","id":1,"result":'));
888
yield* Queue.end(input);
889
890
const error = yield* Deferred.await(termination);
@@ -900,6 +901,27 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => {
901
}),
902
);
903
904
+ it.effect("answers a pending request from a final response without a trailing newline", () =>
905
+ Effect.gen(function* () {
906
+ const { stdio, input, output } = yield* makeInMemoryStdio();
907
+ const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
908
+ stdio,
909
+ serverRequestMethods: new Set(),
910
+ });
911
+ const pending = yield* transport
912
+ .request("x/test", { hello: "world" })
913
+ .pipe(Effect.forkScoped);
914
+ yield* Queue.take(output);
915
+ yield* Queue.offer(
916
+ input,
917
+ encoder.encode(encodeUnknownJsonString({ jsonrpc: "2.0", id: 1, result: { ok: true } })),
918
+ );
919
+ yield* Queue.end(input);
920
+
921
+ assert.deepEqual(yield* Fiber.join(pending), { ok: true });
922
+ }),
923
+ );
924
+
925
it.effect("propagates the real child exit code when the input stream ends", () =>
926
Effect.gen(function* () {
927
const handle = yield* makeHandle({ ACP_MOCK_EXIT_IMMEDIATELY_CODE: "7" });
packages/effect-acp/src/protocol.ts
+23
@@ -180,6 +180,16 @@ const makeStrictNdJsonRpcParser = () => {
180
buffer = chunk.slice(lastNewline + 1);
181
return lines.flatMap((line) => codec.decode(line));
182
},
183
+ // A truncated final line is left to the exit status, which explains a crash better.
184
+ end: (): ReadonlyArray<unknown> => {
185
+ const line = buffer + decoder.decode();
186
+ buffer = "";
187
+ try {
188
+ return line.trim() === "" ? [] : codec.decode(line);
189
+ } catch {
190
+ return [];
191
+ }
192
+ },
193
encode: (response: Parameters<typeof codec.encode>[0]) => {
194
const encoded = codec.encode(response);
195
return encoded === undefined ? undefined : `${encoded}\n`;
@@ -748,6 +758,19 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
758
),
759
),
760
),
761
+ Effect.andThen(
762
+ Effect.suspend(() =>
763
+ Effect.forEach(
764
+ (
765
+ parser.end() as ReadonlyArray<
766
+ RpcMessage.FromClientEncoded | RpcMessage.FromServerEncoded
767
+ >
768
+ ).map(normalizeAcpJsonRpcError),
769
+ routeDecodedMessage,
770
+ { discard: true },
771
+ ),
772
+ ),
773
+ ),
774
// Anything that ends the reader, including a defect in a callback it runs,
775
// terminates the connection so pending requests fail instead of hanging.
776
Effect.matchCauseEffect({