fix(codex): accept rate limit errors on thread resume (#8897)
This commit is contained in:
1 parent
b90898077e
commit
75ab5ab3fb
3 files changed
+86
-1
No files matched your search
@@ -194,6 +194,40 @@ const Codex0150DefinitionSchemas: Record<string, Schema.Json> = {
|
||||
},
|
||||
};
|
||||
|
||||
function applyCodex0151DefinitionCompatibility(
|
||||
exportName: string,
|
||||
definitionName: string,
|
||||
definitionSchema: Schema.Json,
|
||||
): Schema.Json {
|
||||
const isThreadResponse =
|
||||
exportName === "V2ThreadReadResponse" ||
|
||||
exportName === "V2ThreadResumeResponse" ||
|
||||
exportName === "V2ThreadRollbackResponse";
|
||||
if (
|
||||
!isThreadResponse ||
|
||||
definitionName !== "CodexErrorInfo" ||
|
||||
typeof definitionSchema !== "object"
|
||||
) {
|
||||
return definitionSchema;
|
||||
}
|
||||
|
||||
const schema = definitionSchema as {
|
||||
readonly oneOf?: ReadonlyArray<{ readonly enum?: ReadonlyArray<string> }>;
|
||||
};
|
||||
const [firstVariant, ...remainingVariants] = schema.oneOf ?? [];
|
||||
if (!firstVariant?.enum || firstVariant.enum.includes("rateLimitExceeded")) {
|
||||
return definitionSchema;
|
||||
}
|
||||
|
||||
return {
|
||||
...definitionSchema,
|
||||
oneOf: [
|
||||
{ ...firstVariant, enum: [...firstVariant.enum, "rateLimitExceeded"] },
|
||||
...remainingVariants,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
const getGeneratedPaths = Effect.fn("getGeneratedPaths")(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const generatedDir = path.join(import.meta.dirname, "..", "src", "_generated");
|
||||
@@ -660,7 +694,8 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
|
||||
|
||||
for (const [definitionName, definitionSchema] of Object.entries(parsed.definitions ?? {})) {
|
||||
const compatibleDefinitionSchema =
|
||||
Codex0150DefinitionSchemas[definitionName] ?? definitionSchema;
|
||||
Codex0150DefinitionSchemas[definitionName] ??
|
||||
applyCodex0151DefinitionCompatibility(file.exportName, definitionName, definitionSchema);
|
||||
aggregateSchemas[localDefinitionNames.get(definitionName)!] = stripNullDefaults(
|
||||
normalizeNullableTypes(
|
||||
rewriteExternalRefs(
|
||||
|
||||
@@ -16854,6 +16854,7 @@ export type V2ThreadReadResponse__CodexErrorInfo =
|
||||
| "badRequest"
|
||||
| "threadRollbackFailed"
|
||||
| "sandboxError"
|
||||
| "rateLimitExceeded"
|
||||
| "other"
|
||||
| { readonly httpConnectionFailed: { readonly httpStatusCode?: number | null } }
|
||||
| { readonly responseStreamConnectionFailed: { readonly httpStatusCode?: number | null } }
|
||||
@@ -16877,6 +16878,7 @@ export const V2ThreadReadResponse__CodexErrorInfo = Schema.Union(
|
||||
"badRequest",
|
||||
"threadRollbackFailed",
|
||||
"sandboxError",
|
||||
"rateLimitExceeded",
|
||||
"other",
|
||||
]),
|
||||
Schema.Struct({
|
||||
@@ -17207,6 +17209,7 @@ export type V2ThreadResumeResponse__CodexErrorInfo =
|
||||
| "badRequest"
|
||||
| "threadRollbackFailed"
|
||||
| "sandboxError"
|
||||
| "rateLimitExceeded"
|
||||
| "other"
|
||||
| { readonly httpConnectionFailed: { readonly httpStatusCode?: number | null } }
|
||||
| { readonly responseStreamConnectionFailed: { readonly httpStatusCode?: number | null } }
|
||||
@@ -17230,6 +17233,7 @@ export const V2ThreadResumeResponse__CodexErrorInfo = Schema.Union(
|
||||
"badRequest",
|
||||
"threadRollbackFailed",
|
||||
"sandboxError",
|
||||
"rateLimitExceeded",
|
||||
"other",
|
||||
]),
|
||||
Schema.Struct({
|
||||
@@ -17485,6 +17489,7 @@ export type V2ThreadRollbackResponse__CodexErrorInfo =
|
||||
| "badRequest"
|
||||
| "threadRollbackFailed"
|
||||
| "sandboxError"
|
||||
| "rateLimitExceeded"
|
||||
| "other"
|
||||
| { readonly httpConnectionFailed: { readonly httpStatusCode?: number | null } }
|
||||
| { readonly responseStreamConnectionFailed: { readonly httpStatusCode?: number | null } }
|
||||
@@ -17508,6 +17513,7 @@ export const V2ThreadRollbackResponse__CodexErrorInfo = Schema.Union(
|
||||
"badRequest",
|
||||
"threadRollbackFailed",
|
||||
"sandboxError",
|
||||
"rateLimitExceeded",
|
||||
"other",
|
||||
]),
|
||||
Schema.Struct({
|
||||
|
||||
@@ -4,6 +4,9 @@ import * as Schema from "effect/Schema";
|
||||
import * as CodexSchema from "./schema.ts";
|
||||
|
||||
const isGetAccountResponse = Schema.is(CodexSchema.V2GetAccountResponse);
|
||||
const isThreadReadResponse = Schema.is(CodexSchema.V2ThreadReadResponse);
|
||||
const isThreadResumeResponse = Schema.is(CodexSchema.V2ThreadResumeResponse);
|
||||
const isThreadRollbackResponse = Schema.is(CodexSchema.V2ThreadRollbackResponse);
|
||||
|
||||
it("keeps async questions in live notifications and thread history", () => {
|
||||
const item = {
|
||||
@@ -97,6 +100,47 @@ it("accepts Codex 0.150 multi-agent values", () => {
|
||||
assert.equal(Schema.is(CodexSchema.V2ThreadResumeResponse)(resumeResponse), true);
|
||||
});
|
||||
|
||||
it("accepts Codex rate limit errors for thread responses", () => {
|
||||
const failedThread = {
|
||||
cliVersion: "0.150.0",
|
||||
createdAt: 0,
|
||||
cwd: "/tmp/project",
|
||||
ephemeral: false,
|
||||
id: "thread-1",
|
||||
modelProvider: "openai",
|
||||
preview: "",
|
||||
sessionId: "session-1",
|
||||
source: "cli",
|
||||
status: { type: "idle" },
|
||||
turns: [
|
||||
{
|
||||
error: {
|
||||
codexErrorInfo: "rateLimitExceeded",
|
||||
message: "Rate limit exceeded",
|
||||
},
|
||||
id: "turn-1",
|
||||
items: [],
|
||||
status: "failed",
|
||||
},
|
||||
],
|
||||
updatedAt: 0,
|
||||
};
|
||||
assert.equal(isThreadReadResponse({ thread: failedThread }), true);
|
||||
assert.equal(
|
||||
isThreadResumeResponse({
|
||||
approvalPolicy: "never",
|
||||
approvalsReviewer: "user",
|
||||
cwd: "/tmp/project",
|
||||
model: "gpt-5.6-sol",
|
||||
modelProvider: "openai",
|
||||
sandbox: { type: "dangerFullAccess" },
|
||||
thread: failedThread,
|
||||
}),
|
||||
true,
|
||||
);
|
||||
assert.equal(isThreadRollbackResponse({ thread: failedThread }), true);
|
||||
});
|
||||
|
||||
it("accepts Codex 0.150 account plan values", () => {
|
||||
const planTypes = [
|
||||
"self_serve_business_prolite",
|
||||
|
||||
Reference in new issue
Block a user