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 22, 10:45 UTC
fix(codex): warn when a Codex notification fails to decode (#23766)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Victor Vogel committed
Oct 30, 2026 at 15:59 UTC
060c332c4e40ba6922281334fec3233def766b97
2 files changed
+78
-1
packages/effect-codex-app-server/src/client.test.ts
+54
-1
@@ -1,15 +1,20 @@
1
+import * as Deferred from "effect/Deferred";
2
import * as Exit from "effect/Exit";
3
import * as Layer from "effect/Layer";
4
+import * as Logger from "effect/Logger";
5
import * as Path from "effect/Path";
6
import * as Effect from "effect/Effect";
7
+import * as Queue from "effect/Queue";
8
import * as Ref from "effect/Ref";
9
+import * as References from "effect/References";
10
import * as Scope from "effect/Scope";
11
import { ChildProcess, ChildProcessSpawner } from "effect/process";
12
13
import * as NodeServices from "@effect/platform-node/NodeServices";
10
-import { assert, it } from "@effect/vitest";
14
+import { assert, expect, it } from "@effect/vitest";
15
16
import * as CodexClient from "./client.ts";
17
+import { makeInMemoryStdio } from "./_internal/stdio.ts";
18
19
const mockPeerPath = Effect.map(Effect.service(Path.Path), (path) =>
20
path.join(import.meta.dirname, "../test/fixtures/codex-app-server-mock-peer.ts"),
@@ -155,4 +160,52 @@ it.layer(NodeServices.layer)("effect-codex-app-server client", (it) => {
160
assert.equal(initialized.userAgent, "mock-codex-app-server");
161
}),
162
);
163
+
164
+ it.effect("warns once about a notification that fails to decode and keeps dispatching", () =>
165
+ Effect.gen(function* () {
166
+ const secret = "codex-notification-secret-sentinel";
167
+ const { stdio, input } = yield* makeInMemoryStdio();
168
+ const warnings: Array<unknown> = [];
169
+ const client = yield* CodexClient.make(stdio).pipe(
170
+ Effect.provide(
171
+ Logger.layer([
172
+ Logger.make(({ logLevel, fiber }) => {
173
+ if (logLevel === "Warn")
174
+ warnings.push(fiber.getRef(References.CurrentLogAnnotations));
175
+ }),
176
+ ]),
177
+ ),
178
+ );
179
+ const delivered = yield* Deferred.make<unknown>();
180
+ yield* client.handleServerNotification("item/agentMessage/delta", (payload) =>
181
+ Deferred.succeed(delivered, payload).pipe(Effect.asVoid),
182
+ );
183
+
184
+ const send = (params: unknown) =>
185
+ Queue.offer(
186
+ input,
187
+ new TextEncoder().encode(
188
+ `${JSON.stringify({ method: "item/agentMessage/delta", params })}\n`,
189
+ ),
190
+ );
191
+ const malformed = { itemId: "item-1", threadId: "thread-1", turnId: secret };
192
+ yield* send(malformed);
193
+ yield* send(malformed);
194
+ yield* send({ delta: "ok", itemId: "item-1", threadId: "thread-1", turnId: "turn-1" });
195
+
196
+ assert.deepEqual(yield* Deferred.await(delivered), {
197
+ delta: "ok",
198
+ itemId: "item-1",
199
+ threadId: "thread-1",
200
+ turnId: "turn-1",
201
+ });
202
+ assert.lengthOf(warnings, 1);
203
+ expect(warnings[0]).toMatchObject({
204
+ operation: "decode-notification-payload",
205
+ method: "item/agentMessage/delta",
206
+ issueKinds: expect.arrayContaining(["MissingKey"]),
207
+ });
208
+ assert.notInclude(JSON.stringify(warnings), secret);
209
+ }),
210
+ );
211
});
packages/effect-codex-app-server/src/client.ts
+24
@@ -153,6 +153,29 @@ export const make = Effect.fn("effect-codex-app-server/CodexAppServerClient.make
153
>
154
| undefined => CodexRpc.CLIENT_NOTIFICATION_PARAMS[method] as never;
155
156
+ // A notification the schema rejects has no reply to fail, so it is dropped.
157
+ // A Codex build that drifted from the generated schema repeats the bad shape
158
+ // on every frame, so each distinct failure is warned about once per client.
159
+ const warnedDecodeFailures = new Set<string>();
160
+ const warnUndecodableNotification = (error: CodexError.CodexAppServerProtocolParseError) => {
161
+ const key = `${error.method}\n${error.issueKinds?.join(",")}`;
162
+ if (warnedDecodeFailures.has(key)) {
163
+ return Effect.void;
164
+ }
165
+ warnedDecodeFailures.add(key);
166
+ return Effect.logWarning("Dropped a Codex App Server notification that failed to decode").pipe(
167
+ Effect.annotateLogs({
168
+ operation: error.operation,
169
+ ...(error.method === undefined ? {} : { method: error.method }),
170
+ ...(error.issueCount === undefined ? {} : { issueCount: error.issueCount }),
171
+ ...(error.issueKinds === undefined ? {} : { issueKinds: error.issueKinds }),
172
+ ...(error.maximumPathDepth === undefined
173
+ ? {}
174
+ : { maximumPathDepth: error.maximumPathDepth }),
175
+ }),
176
+ );
177
+ };
178
+
179
const dispatchNotification = (
180
notification: CodexProtocol.CodexAppServerIncomingNotification,
181
): Effect.Effect<void, never> => {
@@ -166,6 +189,7 @@ export const make = Effect.fn("effect-codex-app-server/CodexAppServerClient.make
189
190
if (schema) {
191
return decodeNotificationPayload(notification.method, schema, notification.params).pipe(
192
+ Effect.tapError(warnUndecodableNotification),
193
Effect.flatMap((decoded) =>
194
Effect.forEach(handlers, (handler) => handler(decoded), { discard: true }),
195
),