@devries-cameron20 / t3code-1 / commits / 95139254ba
Fork 0

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

fix(codex): accept misalignment policy errors on thread resume (#10373)

Bakari Mustafa committed Sep 7, 2026 at 09:49 UTC 95139254ba98fb8ad12a001ebcbc9d4b833ead19
3 files changed +107 -10
packages/effect-codex-app-server/scripts/generate.ts
+33 -10
@@ -194,17 +194,28 @@ const Codex0150DefinitionSchemas: Record<string, Schema.Json> = {
194 },
195 };
196
197 +// Pinned protocol JSON omits later CodexErrorInfo variants. Keep historical
198 +// thread payloads decodable; do not fold unknown values into "other".
199 +const CodexErrorInfoCompatibilityValues = [
200 + "rateLimitExceeded",
201 + "misalignmentPolicyViolation",
202 +] as const;
203 +
204 +const CodexErrorInfoCompatibilityExports = new Set([
205 + "V2ThreadReadResponse",
206 + "V2ThreadResumeResponse",
207 + "V2ThreadRollbackResponse",
208 + "V2ThreadForkResponse",
209 + "V2TurnCompletedNotification",
210 +]);
211 +
212 function applyCodex0151DefinitionCompatibility(
213 exportName: string,
214 definitionName: string,
215 definitionSchema: Schema.Json,
216 ): Schema.Json {
202 - const isThreadResponse =
203 - exportName === "V2ThreadReadResponse" ||
204 - exportName === "V2ThreadResumeResponse" ||
205 - exportName === "V2ThreadRollbackResponse";
217 if (
207 - !isThreadResponse ||
218 + !CodexErrorInfoCompatibilityExports.has(exportName) ||
219 definitionName !== "CodexErrorInfo" ||
220 typeof definitionSchema !== "object"
221 ) {
@@ -215,16 +226,28 @@ function applyCodex0151DefinitionCompatibility(
226 readonly oneOf?: ReadonlyArray<{ readonly enum?: ReadonlyArray<string> }>;
227 };
228 const [firstVariant, ...remainingVariants] = schema.oneOf ?? [];
218 - if (!firstVariant?.enum || firstVariant.enum.includes("rateLimitExceeded")) {
229 + const currentEnum = firstVariant?.enum;
230 + if (!currentEnum) {
231 + return definitionSchema;
232 + }
233 +
234 + const missingValues = CodexErrorInfoCompatibilityValues.filter(
235 + (value) => !currentEnum.includes(value),
236 + );
237 + if (missingValues.length === 0) {
238 return definitionSchema;
239 }
240
241 + const enumValues = [...currentEnum];
242 + const otherIndex = enumValues.indexOf("other");
243 + const nextEnum =
244 + otherIndex === -1
245 + ? [...enumValues, ...missingValues]
246 + : [...enumValues.slice(0, otherIndex), ...missingValues, ...enumValues.slice(otherIndex)];
247 +
248 return {
249 ...definitionSchema,
224 - oneOf: [
225 - { ...firstVariant, enum: [...firstVariant.enum, "rateLimitExceeded"] },
226 - ...remainingVariants,
227 - ],
250 + oneOf: [{ ...firstVariant, enum: nextEnum }, ...remainingVariants],
251 };
252 }
253
packages/effect-codex-app-server/src/_generated/schema.gen.ts
+14
@@ -15947,6 +15947,8 @@ export type V2ThreadForkResponse__CodexErrorInfo =
15947 | "badRequest"
15948 | "threadRollbackFailed"
15949 | "sandboxError"
15950 + | "rateLimitExceeded"
15951 + | "misalignmentPolicyViolation"
15952 | "other"
15953 | { readonly httpConnectionFailed: { readonly httpStatusCode?: number | null } }
15954 | { readonly responseStreamConnectionFailed: { readonly httpStatusCode?: number | null } }
@@ -15970,6 +15972,8 @@ export const V2ThreadForkResponse__CodexErrorInfo = Schema.Union(
15972 "badRequest",
15973 "threadRollbackFailed",
15974 "sandboxError",
15975 + "rateLimitExceeded",
15976 + "misalignmentPolicyViolation",
15977 "other",
15978 ]),
15979 Schema.Struct({
@@ -16855,6 +16859,7 @@ export type V2ThreadReadResponse__CodexErrorInfo =
16859 | "threadRollbackFailed"
16860 | "sandboxError"
16861 | "rateLimitExceeded"
16862 + | "misalignmentPolicyViolation"
16863 | "other"
16864 | { readonly httpConnectionFailed: { readonly httpStatusCode?: number | null } }
16865 | { readonly responseStreamConnectionFailed: { readonly httpStatusCode?: number | null } }
@@ -16879,6 +16884,7 @@ export const V2ThreadReadResponse__CodexErrorInfo = Schema.Union(
16884 "threadRollbackFailed",
16885 "sandboxError",
16886 "rateLimitExceeded",
16887 + "misalignmentPolicyViolation",
16888 "other",
16889 ]),
16890 Schema.Struct({
@@ -17210,6 +17216,7 @@ export type V2ThreadResumeResponse__CodexErrorInfo =
17216 | "threadRollbackFailed"
17217 | "sandboxError"
17218 | "rateLimitExceeded"
17219 + | "misalignmentPolicyViolation"
17220 | "other"
17221 | { readonly httpConnectionFailed: { readonly httpStatusCode?: number | null } }
17222 | { readonly responseStreamConnectionFailed: { readonly httpStatusCode?: number | null } }
@@ -17234,6 +17241,7 @@ export const V2ThreadResumeResponse__CodexErrorInfo = Schema.Union(
17241 "threadRollbackFailed",
17242 "sandboxError",
17243 "rateLimitExceeded",
17244 + "misalignmentPolicyViolation",
17245 "other",
17246 ]),
17247 Schema.Struct({
@@ -17490,6 +17498,7 @@ export type V2ThreadRollbackResponse__CodexErrorInfo =
17498 | "threadRollbackFailed"
17499 | "sandboxError"
17500 | "rateLimitExceeded"
17501 + | "misalignmentPolicyViolation"
17502 | "other"
17503 | { readonly httpConnectionFailed: { readonly httpStatusCode?: number | null } }
17504 | { readonly responseStreamConnectionFailed: { readonly httpStatusCode?: number | null } }
@@ -17514,6 +17523,7 @@ export const V2ThreadRollbackResponse__CodexErrorInfo = Schema.Union(
17523 "threadRollbackFailed",
17524 "sandboxError",
17525 "rateLimitExceeded",
17526 + "misalignmentPolicyViolation",
17527 "other",
17528 ]),
17529 Schema.Struct({
@@ -18713,6 +18723,8 @@ export type V2TurnCompletedNotification__CodexErrorInfo =
18723 | "badRequest"
18724 | "threadRollbackFailed"
18725 | "sandboxError"
18726 + | "rateLimitExceeded"
18727 + | "misalignmentPolicyViolation"
18728 | "other"
18729 | { readonly httpConnectionFailed: { readonly httpStatusCode?: number | null } }
18730 | { readonly responseStreamConnectionFailed: { readonly httpStatusCode?: number | null } }
@@ -18736,6 +18748,8 @@ export const V2TurnCompletedNotification__CodexErrorInfo = Schema.Union(
18748 "badRequest",
18749 "threadRollbackFailed",
18750 "sandboxError",
18751 + "rateLimitExceeded",
18752 + "misalignmentPolicyViolation",
18753 "other",
18754 ]),
18755 Schema.Struct({
packages/effect-codex-app-server/src/schema.test.ts
+60
@@ -7,6 +7,9 @@ const isGetAccountResponse = Schema.is(CodexSchema.V2GetAccountResponse);
7 const isThreadReadResponse = Schema.is(CodexSchema.V2ThreadReadResponse);
8 const isThreadResumeResponse = Schema.is(CodexSchema.V2ThreadResumeResponse);
9 const isThreadRollbackResponse = Schema.is(CodexSchema.V2ThreadRollbackResponse);
10 +const isThreadForkResponse = Schema.is(CodexSchema.V2ThreadForkResponse);
11 +const isTurnCompletedNotification = Schema.is(CodexSchema.V2TurnCompletedNotification);
12 +const decodeThreadResumeResponse = Schema.decodeUnknownSync(CodexSchema.V2ThreadResumeResponse);
13
14 it("keeps async questions in live notifications and thread history", () => {
15 const item = {
@@ -141,6 +144,63 @@ it("accepts Codex rate limit errors for thread responses", () => {
144 assert.equal(isThreadRollbackResponse({ thread: failedThread }), true);
145 });
146
147 +it("accepts Codex misalignment policy errors for thread responses", () => {
148 + const failedThread = {
149 + cliVersion: "0.150.0",
150 + createdAt: 0,
151 + cwd: "/tmp/project",
152 + ephemeral: false,
153 + id: "thread-1",
154 + modelProvider: "openai",
155 + preview: "",
156 + sessionId: "session-1",
157 + source: "cli",
158 + status: { type: "idle" },
159 + turns: [
160 + {
161 + error: {
162 + codexErrorInfo: "misalignmentPolicyViolation",
163 + message: "Misalignment policy violation",
164 + },
165 + id: "turn-1",
166 + items: [],
167 + status: "failed",
168 + },
169 + ],
170 + updatedAt: 0,
171 + };
172 + const resumeLikeResponse = {
173 + approvalPolicy: "never",
174 + approvalsReviewer: "user",
175 + cwd: "/tmp/project",
176 + model: "gpt-5.6-sol",
177 + modelProvider: "openai",
178 + sandbox: { type: "dangerFullAccess" },
179 + thread: failedThread,
180 + };
181 + assert.equal(isThreadReadResponse({ thread: failedThread }), true);
182 + assert.equal(isThreadResumeResponse(resumeLikeResponse), true);
183 + assert.equal(isThreadRollbackResponse({ thread: failedThread }), true);
184 + assert.equal(isThreadForkResponse(resumeLikeResponse), true);
185 + const decodedResume = decodeThreadResumeResponse(resumeLikeResponse);
186 + assert.equal(decodedResume.thread.turns[0]?.error?.codexErrorInfo, "misalignmentPolicyViolation");
187 + assert.equal(
188 + isTurnCompletedNotification({
189 + threadId: "thread-1",
190 + turn: {
191 + error: {
192 + codexErrorInfo: "misalignmentPolicyViolation",
193 + message: "Misalignment policy violation",
194 + },
195 + id: "turn-1",
196 + items: [],
197 + status: "failed",
198 + },
199 + }),
200 + true,
201 + );
202 +});
203 +
204 it("accepts Codex 0.150 account plan values", () => {
205 const planTypes = [
206 "self_serve_business_prolite",