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 21, 17:15 UTC
fix(acp): bound unread notification retention by size (#23217)
Julius Marminge committed
Nov 13, 2026 at 08:43 UTC
3ac8b1f587ed34ed038030055a66e2ac52a35216
2 files changed
+53
-6
packages/effect-acp/src/protocol.test.ts
+42
@@ -239,6 +239,48 @@ it.layer(NodeServices.layer)("effect-acp protocol", (it) => {
239
}),
240
);
241
242
+ it.effect("evicts unread raw notifications while a slow reader handles an earlier one", () =>
243
+ Effect.gen(function* () {
244
+ const { stdio, input } = yield* makeInMemoryStdio();
245
+ const handled = yield* Queue.unbounded<number>();
246
+ const transport = yield* AcpProtocol.makeAcpPatchedProtocol({
247
+ stdio,
248
+ serverRequestMethods: new Set(),
249
+ onNotification: (notification) =>
250
+ Queue.offer(handled, decodeIndex(notification.params).index).pipe(Effect.asVoid),
251
+ });
252
+ const send = (index: number, textLength: number) =>
253
+ Queue.offer(input, largeNotification(index, textLength)).pipe(
254
+ Effect.andThen(Queue.take(handled)),
255
+ );
256
+
257
+ yield* send(1, 6 * MIB);
258
+ yield* send(2, 6 * MIB);
259
+ const entered = yield* Deferred.make<void>();
260
+ const release = yield* Deferred.make<void>();
261
+ const reader = yield* transport.incoming.pipe(
262
+ Stream.map((notification) => decodeIndex(notification.params).index),
263
+ Stream.tap((index) =>
264
+ index === 1
265
+ ? Deferred.succeed(entered, undefined).pipe(Effect.andThen(Deferred.await(release)))
266
+ : Effect.void,
267
+ ),
268
+ Stream.take(4),
269
+ Stream.runCollect,
270
+ Effect.forkScoped,
271
+ );
272
+ yield* Deferred.await(entered);
273
+
274
+ // Notification 2 is still unread, so 3 and 4 push it past the budget.
275
+ yield* send(3, 6 * MIB);
276
+ yield* send(4, 6 * MIB);
277
+ yield* send(5, 1);
278
+ yield* Deferred.succeed(release, undefined);
279
+
280
+ assert.deepEqual(yield* Fiber.join(reader), [1, 3, 4, 5]);
281
+ }),
282
+ );
283
+
284
it.effect("delivers every raw notification to a reader that keeps up, then ends", () =>
285
Effect.gen(function* () {
286
const { stdio, input } = yield* makeInMemoryStdio();
packages/effect-acp/src/protocol.ts
+11
-6
@@ -313,9 +313,8 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
313
const serverQueue = yield* Queue.unbounded<RpcMessage.FromClientEncoded>();
314
const clientQueue = yield* Queue.unbounded<RpcMessage.FromServerEncoded>();
315
const rawNotifications = yield* Queue.unbounded<AcpBufferedRawNotification, Cause.Done<void>>();
316
- // JSON length of the notifications offered since the queue was last empty.
317
- // `incoming` takes the whole backlog on every pull, so an empty queue holds
318
- // nothing, and a read can only make this an overestimate.
316
+ // JSON length of the notifications still in the queue. `incoming` takes one
317
+ // at a time, so a slow reader holds at most one outside this budget.
318
let rawNotificationsJsonLength = 0;
319
// Raw readers finish with the connection: termination ends the queue, and so
320
// does closing the scope, which interrupts the reader before it terminates.
@@ -494,7 +493,6 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
493
// so readers never see more than the limits allow.
494
const bufferRawNotification = (notification: AcpIncomingNotification, lineLength: number) =>
495
Effect.sync(() => {
497
- if (Queue.sizeUnsafe(rawNotifications) === 0) rawNotificationsJsonLength = 0;
496
if (!Queue.offerUnsafe(rawNotifications, { notification, lineLength })) return;
497
rawNotificationsJsonLength += lineLength;
498
while (
@@ -1101,8 +1099,15 @@ export const makeAcpPatchedProtocol = Effect.fn("makeAcpPatchedProtocol")(functi
1099
clientProtocol,
1100
serverProtocol,
1101
get incoming() {
1104
- return Stream.fromQueue(rawNotifications).pipe(
1105
- Stream.map(({ notification }) => notification),
1102
+ return Stream.fromPull(
1103
+ Effect.succeed(
1104
+ Queue.take(rawNotifications).pipe(
1105
+ Effect.map(({ notification, lineLength }) => {
1106
+ rawNotificationsJsonLength -= lineLength;
1107
+ return [notification] as const;
1108
+ }),
1109
+ ),
1110
+ ),
1111
);
1112
},
1113
request: sendRequest,