The best way to control Claude Code, Codex and more from any computer or phone
fix(pi): log oversized RPC records instead of dropping them silently (#23947)
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 21:29 UTC
c3303fb7dce9fc7432ec91bd13783690252898f2
2 files changed
+49
-9
packages/provider-pi/src/server/adapter.test.ts
+28
-5
@@ -27,6 +27,7 @@ import * as Exit from "effect/Exit";
27
import * as Fiber from "effect/Fiber";
28
import * as FileSystem from "effect/FileSystem";
29
import * as Layer from "effect/Layer";
30
+import * as Logger from "effect/Logger";
31
import * as Queue from "effect/Queue";
32
import * as Schema from "effect/Schema";
33
import * as Sink from "effect/Sink";
@@ -4295,8 +4296,16 @@ describe("PiAdapterV2", () => {
4296
});
4297
4298
describe("PiRpc framing", () => {
4298
- it.effect("reassembles records across chunk boundaries and strips CR", () =>
4299
- Effect.gen(function* () {
4299
+ it.effect("reassembles records and warns when dropping oversized records", () => {
4300
+ const warnings: Array<ReadonlyArray<unknown>> = [];
4301
+ const warned = Deferred.makeUnsafe<void>();
4302
+ const logCapture = Logger.make<unknown, void>(({ logLevel, message }) => {
4303
+ if (logLevel === "Warn" && Array.isArray(message)) {
4304
+ warnings.push(message);
4305
+ Deferred.doneUnsafe(warned, Effect.void);
4306
+ }
4307
+ });
4308
+ return Effect.gen(function* () {
4309
const stdout = yield* Queue.unbounded<Uint8Array>();
4310
const spawner = ChildProcessSpawner.make(() =>
4311
Effect.succeed(
@@ -4327,9 +4336,11 @@ describe("PiRpc framing", () => {
4336
yield* push('{"type":"agent_');
4337
yield* push('start"}\r\n{"type":"agent_settled"}\nnot json\n{"type":"queue_update"}\n');
4338
4330
- yield* push('{"type":"must_not_emit","text":"');
4339
+ const head = '{"type":"must_not_emit","text":"';
4340
+ yield* push(head);
4341
const chunk = new TextEncoder().encode("x".repeat(8 * 1024 * 1024));
4342
for (let index = 0; index < 32; index++) yield* Queue.offer(stdout, chunk);
4343
+ yield* Deferred.await(warned);
4344
yield* push('"}\n{"type":"after_oversized"}\n');
4345
4346
const first = yield* Queue.take(connection.events);
@@ -4339,8 +4350,20 @@ describe("PiRpc framing", () => {
4350
const third = yield* Queue.take(connection.events);
4351
assert.equal(third["type"], "queue_update");
4352
assert.equal((yield* Queue.take(connection.events))["type"], "after_oversized");
4342
- }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
4343
- );
4353
+ assert.lengthOf(warnings, 1);
4354
+ const [text, annotations] = warnings[0] ?? [];
4355
+ assert.equal(text, "Dropping oversized pi stdout record.");
4356
+ assert.deepEqual(annotations, {
4357
+ recordLength: head.length + 28 * chunk.length,
4358
+ maxRecordLength: 232084864,
4359
+ });
4360
+ }).pipe(
4361
+ Effect.scoped,
4362
+ Effect.provide(
4363
+ Layer.merge(NodeServices.layer, Logger.layer([logCapture], { mergeWithExisting: false })),
4364
+ ),
4365
+ );
4366
+ });
4367
});
4368
4369
describe("PiRpc early process exit", () => {
packages/provider-pi/src/server/rpc.ts
+21
-4
@@ -96,14 +96,16 @@ const MAX_PI_RECORD_CHARS =
96
function makeJsonlFramer() {
97
let buffer = "";
98
let dropping = false;
99
- return (chunk: string): ReadonlyArray<string> => {
99
+ return (chunk: string) => {
100
const lines: string[] = [];
101
+ const droppedLengths: number[] = [];
102
let start = 0;
103
while (start < chunk.length) {
104
const newline = chunk.indexOf("\n", start);
105
const end = newline < 0 ? chunk.length : newline;
106
if (!dropping) {
107
if (buffer.length + end - start > MAX_PI_RECORD_CHARS) {
108
+ droppedLengths.push(buffer.length + end - start);
109
buffer = "";
110
dropping = true;
111
} else {
@@ -118,10 +120,22 @@ function makeJsonlFramer() {
120
dropping = false;
121
start = newline + 1;
122
}
121
- return lines;
123
+ return { lines, droppedLengths };
124
};
125
}
126
127
+// Report the observed length before LF arrives; an unterminated response can time out first.
128
+const logDroppedPiRecords = (droppedLengths: ReadonlyArray<number>) =>
129
+ Effect.forEach(
130
+ droppedLengths,
131
+ (recordLength) =>
132
+ Effect.logWarning("Dropping oversized pi stdout record.", {
133
+ recordLength,
134
+ maxRecordLength: MAX_PI_RECORD_CHARS,
135
+ }),
136
+ { discard: true },
137
+ );
138
+
139
const UnknownFromJsonString = Schema.fromJsonString(Schema.Unknown);
140
const decodeJsonLine = Schema.decodeSync(UnknownFromJsonString);
141
const encodeJsonLine = Schema.encodeSync(UnknownFromJsonString);
@@ -294,7 +308,8 @@ export const makePiRpcConnection = Effect.fnUntraced(function* (options: PiRpcSp
308
Stream.decodeText(),
309
Stream.runForEach((chunk) =>
310
Effect.gen(function* () {
297
- const lines = frame(chunk);
311
+ const { lines, droppedLengths } = frame(chunk);
312
+ yield* logDroppedPiRecords(droppedLengths);
313
for (const line of lines) {
314
const record = parsePiRecord(line);
315
if (record === undefined) {
@@ -308,7 +323,9 @@ export const makePiRpcConnection = Effect.fnUntraced(function* (options: PiRpcSp
323
}),
324
),
325
);
311
- for (const line of frame("\n")) {
326
+ const flushed = frame("\n");
327
+ yield* logDroppedPiRecords(flushed.droppedLengths);
328
+ for (const line of flushed.lines) {
329
const trailing = parsePiRecord(line);
330
if (trailing !== undefined) yield* routeRecord(trailing);
331
}