@devries-cameron20 / t3code-1 / commits / 13c7de296c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(codex): approvals still appear after many stopped Codex turns (#23234)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Victor Vogel committed Oct 30, 2026 at 15:45 UTC 13c7de296c3e761b824dda3a6819421bf77ca06b
2 files changed +84 -2
packages/effect-codex-app-server/src/protocol.test.ts
+69
@@ -418,6 +418,75 @@ it.layer(NodeServices.layer)("effect-codex-app-server protocol", (it) => {
418 }),
419 );
420
421 + it.effect("releases a waiting request handler when Codex resolves its request", () =>
422 + Effect.gen(function* () {
423 + const { stdio, input, output } = yield* makeInMemoryStdio();
424 + yield* CodexProtocol.makeCodexAppServerPatchedProtocol({
425 + stdio,
426 + onRequest: (request) =>
427 + request.id === 33 ? Effect.succeed({ decision: "accept" }) : Effect.never,
428 + });
429 +
430 + const messages = Array.from({ length: 32 }, (_, index) =>
431 + encodeUnknownJsonString({
432 + id: index + 1,
433 + method: "item/commandExecution/requestApproval",
434 + params: {},
435 + }),
436 + );
437 + for (let requestId = 1; requestId <= 32; requestId++) {
438 + messages.push(
439 + encodeUnknownJsonString({
440 + method: "serverRequest/resolved",
441 + params: { threadId: "thread-1", requestId },
442 + }),
443 + );
444 + }
445 + messages.push(
446 + encodeUnknownJsonString({
447 + id: 33,
448 + method: "item/commandExecution/requestApproval",
449 + params: {},
450 + }),
451 + );
452 + yield* Queue.offer(input, encoder.encode(`${messages.join("\n")}\n`));
453 +
454 + assert.deepEqual(yield* decodeJson(yield* Queue.take(output)), {
455 + id: 33,
456 + result: { decision: "accept" },
457 + });
458 + }),
459 + );
460 +
461 + it.effect("keeps numeric and string request ids apart when Codex resolves one", () =>
462 + Effect.gen(function* () {
463 + const { stdio, input, output } = yield* makeInMemoryStdio();
464 + const interrupted: Array<string | number> = [];
465 + yield* CodexProtocol.makeCodexAppServerPatchedProtocol({
466 + stdio,
467 + onRequest: (request) =>
468 + request.id === 2
469 + ? Effect.sync(() => ({ interrupted }))
470 + : Effect.never.pipe(
471 + Effect.onInterrupt(() => Effect.sync(() => interrupted.push(request.id))),
472 + ),
473 + });
474 +
475 + const messages = [
476 + { id: 1, method: "item/commandExecution/requestApproval", params: {} },
477 + { id: "1", method: "item/commandExecution/requestApproval", params: {} },
478 + { method: "serverRequest/resolved", params: { threadId: "thread-1", requestId: "1" } },
479 + { id: 2, method: "item/commandExecution/requestApproval", params: {} },
480 + ].map((message) => encodeUnknownJsonString(message));
481 + yield* Queue.offer(input, encoder.encode(`${messages.join("\n")}\n`));
482 +
483 + assert.deepEqual(yield* decodeJson(yield* Queue.take(output)), {
484 + id: 2,
485 + result: { interrupted: ["1"] },
486 + });
487 + }),
488 + );
489 +
490 it.effect("interrupts pending request handlers when the protocol terminates", () =>
491 Effect.gen(function* () {
492 const { stdio, input } = yield* makeInMemoryStdio();
packages/effect-codex-app-server/src/protocol.ts
+15 -2
@@ -2,6 +2,7 @@ import * as Cause from "effect/Cause";
2 import * as Deferred from "effect/Deferred";
3 import * as Effect from "effect/Effect";
4 import * as Exit from "effect/Exit";
5 +import * as FiberMap from "effect/FiberMap";
6 import * as Option from "effect/Option";
7 import * as Queue from "effect/Queue";
8 import * as Ref from "effect/Ref";
@@ -176,6 +177,9 @@ export const makeCodexAppServerPatchedProtocol = Effect.fn("makeCodexAppServerPa
177 const terminationFailure = yield* Ref.make(Option.none<CodexError.CodexAppServerError>());
178 const terminationSignal = yield* Deferred.make<void>();
179 const activeRequestHandlers = yield* Ref.make(0);
180 + const requestHandlers = yield* FiberMap.make<string | number>().pipe(
181 + Scope.provide(requestHandlerScope),
182 + );
183
184 const logProtocol = (event: CodexAppServerProtocolLogEvent) => {
185 if (event.direction === "incoming" && !options.logIncoming) {
@@ -343,7 +347,7 @@ export const makeCodexAppServerPatchedProtocol = Effect.fn("makeCodexAppServerPa
347 Effect.asVoid,
348 ),
349 ),
346 - Effect.forkIn(requestHandlerScope, { startImmediately: true }),
350 + FiberMap.run(requestHandlers, request.id),
351 Effect.asVoid,
352 );
353 }),
@@ -352,8 +356,17 @@ export const makeCodexAppServerPatchedProtocol = Effect.fn("makeCodexAppServerPa
356 Effect.asVoid,
357 );
358
359 + // Codex settles requests itself when their turn ends; a handler still waiting would hold its slot.
360 + const releaseResolvedRequest = (notification: CodexAppServerIncomingNotification) =>
361 + notification.method === "serverRequest/resolved" &&
362 + isObject(notification.params) &&
363 + isJsonRpcId(notification.params.requestId)
364 + ? FiberMap.remove(requestHandlers, notification.params.requestId)
365 + : Effect.void;
366 +
367 const handleNotification = (notification: CodexAppServerIncomingNotification) =>
356 - Queue.offer(incomingNotifications, notification).pipe(
368 + releaseResolvedRequest(notification).pipe(
369 + Effect.andThen(Queue.offer(incomingNotifications, notification)),
370 Effect.andThen(options.onNotification ? options.onNotification(notification) : Effect.void),
371 Effect.asVoid,
372 );