mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Accept unknown Codex error variants in the app-server protocol (#49806)
## Why New error variants should not prevent older clients from handling app-server errors. ## What changed - Deserialize unknown `CodexErrorInfo` strings and objects as `Other` in Rust, while preserving known variants and the `"other"` serialization. - Allow arbitrary strings and objects in the exported JSON schemas and TypeScript type. - Update Python SDK generation and generated models to accept unknown error strings and object payloads. ## Testing Add Rust tests for `"other"` round trips, unknown string and object fallbacks, known structured variants, and rejection of null, boolean, numeric, and array values. GitOrigin-RevId: 40c17896019924b2ef7970ee2205ea0154d0d1b3
This commit is contained in:
committed by
copyberry
parent
e7798c9944
commit
a5d56d8120
@@ -654,8 +654,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -792,8 +791,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
+9
-3
@@ -8425,8 +8425,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -8563,8 +8562,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CodexResponseHandoffMode": {
|
||||
"enum": [
|
||||
|
||||
+9
-3
@@ -4261,8 +4261,7 @@
|
||||
"title": "ClientRequest"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -4399,8 +4398,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CodexResponseHandoffMode": {
|
||||
"enum": [
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"definitions": {
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -140,8 +139,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"MisalignmentErrorDetails": {
|
||||
"properties": {
|
||||
|
||||
@@ -52,8 +52,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -190,8 +189,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -133,8 +133,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -271,8 +270,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -55,8 +55,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -193,8 +192,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
+9
-3
@@ -55,8 +55,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -193,8 +192,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -55,8 +55,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -193,8 +192,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -133,8 +133,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -271,8 +270,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -55,8 +55,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -193,8 +192,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -133,8 +133,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -271,8 +270,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
+9
-3
@@ -55,8 +55,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -193,8 +192,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -52,8 +52,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -190,8 +189,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -55,8 +55,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -193,8 +192,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
+9
-3
@@ -52,8 +52,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -190,8 +189,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -52,8 +52,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -190,8 +189,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
@@ -52,8 +52,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"CodexErrorInfo": {
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.",
|
||||
"oneOf": [
|
||||
"anyOf": [
|
||||
{
|
||||
"enum": [
|
||||
"contextWindowExceeded",
|
||||
@@ -190,8 +189,15 @@
|
||||
],
|
||||
"title": "ActiveTurnNotSteerableCodexErrorInfo",
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"object"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"description": "This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
},
|
||||
"CollabAgentState": {
|
||||
"properties": {
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -9,4 +9,4 @@ import type { NonSteerableTurnKind } from "./NonSteerableTurnKind";
|
||||
* When an upstream HTTP status is available (for example, from the Responses API or a provider),
|
||||
* it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant.
|
||||
*/
|
||||
export type CodexErrorInfo = "contextWindowExceeded" | "sessionBudgetExceeded" | "usageLimitExceeded" | "rateLimitExceeded" | "flexUnavailable" | "serverOverloaded" | "cyberPolicy" | "misalignmentPolicyViolation" | "tooManyDenials" | { "httpConnectionFailed": { httpStatusCode: number | null, } } | { "responseStreamConnectionFailed": { httpStatusCode: number | null, } } | "internalServerError" | "unauthorized" | "badRequest" | "threadRollbackFailed" | "sandboxError" | { "responseStreamDisconnected": { httpStatusCode: number | null, } } | { "responseTooManyFailedAttempts": { httpStatusCode: number | null, } } | { "activeTurnNotSteerable": { turnKind: NonSteerableTurnKind, } } | "other";
|
||||
export type CodexErrorInfo = "contextWindowExceeded" | "sessionBudgetExceeded" | "usageLimitExceeded" | "rateLimitExceeded" | "flexUnavailable" | "serverOverloaded" | "cyberPolicy" | "misalignmentPolicyViolation" | "tooManyDenials" | { "httpConnectionFailed": { httpStatusCode: number | null, } } | { "responseStreamConnectionFailed": { httpStatusCode: number | null, } } | "internalServerError" | "unauthorized" | "badRequest" | "threadRollbackFailed" | "sandboxError" | { "responseStreamDisconnected": { httpStatusCode: number | null, } } | { "responseTooManyFailedAttempts": { httpStatusCode: number | null, } } | { "activeTurnNotSteerable": { turnKind: NonSteerableTurnKind, } } | "other" | string | { [key: string]: unknown };
|
||||
|
||||
@@ -1366,6 +1366,11 @@ where
|
||||
strip_v1_server_notification_variants_from_json_schema(&mut schema_value);
|
||||
add_server_notification_emitted_at_to_json_schema(&mut schema_value)?;
|
||||
}
|
||||
if let Some(Value::Object(error_schema)) =
|
||||
schema_value.pointer_mut("/definitions/CodexErrorInfo")
|
||||
{
|
||||
keep_enum_open_ended(error_schema);
|
||||
}
|
||||
enforce_numbered_definition_collision_overrides(file_stem, &mut schema_value);
|
||||
annotate_schema(&mut schema_value, Some(file_stem));
|
||||
}
|
||||
@@ -1397,6 +1402,13 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
fn keep_enum_open_ended(schema: &mut Map<String, Value>) {
|
||||
if let Some(Value::Array(mut variants)) = schema.remove("oneOf") {
|
||||
variants.push(serde_json::json!({ "type": ["string", "object"] }));
|
||||
schema.insert("anyOf".to_string(), Value::Array(variants));
|
||||
}
|
||||
}
|
||||
|
||||
fn add_server_notification_emitted_at_to_json_schema(schema: &mut Value) -> Result<()> {
|
||||
let schema = schema
|
||||
.as_object_mut()
|
||||
|
||||
@@ -19,7 +19,6 @@ use schemars::schema::Schema;
|
||||
use schemars::schema::SchemaObject;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
#[cfg(test)]
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
// Macro to declare a camelCased API v2 enum mirroring a core enum which
|
||||
@@ -119,9 +118,34 @@ pub enum CodexErrorInfo {
|
||||
#[ts(rename = "turnKind")]
|
||||
turn_kind: NonSteerableTurnKind,
|
||||
},
|
||||
#[serde(
|
||||
untagged,
|
||||
serialize_with = "serialize_other_codex_error_info",
|
||||
deserialize_with = "deserialize_other_codex_error_info"
|
||||
)]
|
||||
#[ts(type = "\"other\" | string | { [key: string]: unknown }")]
|
||||
Other,
|
||||
}
|
||||
|
||||
fn serialize_other_codex_error_info<S>(serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str("other")
|
||||
}
|
||||
|
||||
fn deserialize_other_codex_error_info<'de, D>(deserializer: D) -> Result<(), D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
match JsonValue::deserialize(deserializer)? {
|
||||
JsonValue::String(_) | JsonValue::Object(_) => Ok(()),
|
||||
_ => Err(serde::de::Error::custom(
|
||||
"expected an error string or object",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CoreCodexErrorInfo> for CodexErrorInfo {
|
||||
fn from(value: CoreCodexErrorInfo) -> Self {
|
||||
match value {
|
||||
|
||||
@@ -4781,6 +4781,67 @@ fn core_error_info_converts_to_camel_case() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The catchall must keep the existing `other` string stable in both directions.
|
||||
#[test]
|
||||
fn codex_error_info_other_round_trips_as_string() {
|
||||
assert_eq!(
|
||||
serde_json::to_value(CodexErrorInfo::Other).unwrap(),
|
||||
json!("other")
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::from_value::<CodexErrorInfo>(json!("other")).unwrap(),
|
||||
CodexErrorInfo::Other
|
||||
);
|
||||
}
|
||||
|
||||
/// Future unit variants must not prevent older clients from handling errors.
|
||||
#[test]
|
||||
fn codex_error_info_deserializes_unknown_string_as_other() {
|
||||
assert_eq!(
|
||||
serde_json::from_value::<CodexErrorInfo>(json!("futureError")).unwrap(),
|
||||
CodexErrorInfo::Other
|
||||
);
|
||||
}
|
||||
|
||||
/// Future structured variants must fall back without retaining their unknown payload.
|
||||
#[test]
|
||||
fn codex_error_info_deserializes_unknown_object_as_other() {
|
||||
assert_eq!(
|
||||
serde_json::from_value::<CodexErrorInfo>(json!({
|
||||
"futureError": {
|
||||
"detail": "unknown",
|
||||
"retryAfterSeconds": 30,
|
||||
}
|
||||
}))
|
||||
.unwrap(),
|
||||
CodexErrorInfo::Other
|
||||
);
|
||||
}
|
||||
|
||||
/// The catchall must not replace known structured variants with `Other`.
|
||||
#[test]
|
||||
fn codex_error_info_deserializes_known_object_without_falling_back() {
|
||||
assert_eq!(
|
||||
serde_json::from_value::<CodexErrorInfo>(json!({
|
||||
"httpConnectionFailed": {
|
||||
"httpStatusCode": 503,
|
||||
}
|
||||
}))
|
||||
.unwrap(),
|
||||
CodexErrorInfo::HttpConnectionFailed {
|
||||
http_status_code: Some(503),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// Only the two supported error wire shapes may reach the catchall.
|
||||
#[test]
|
||||
fn codex_error_info_rejects_unsupported_wire_shapes() {
|
||||
for value in [json!(null), json!(true), json!(42), json!([])] {
|
||||
assert!(serde_json::from_value::<CodexErrorInfo>(value).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codex_error_info_serializes_active_turn_not_steerable_turn_kind_in_camel_case() {
|
||||
let value = CodexErrorInfo::ActiveTurnNotSteerable {
|
||||
|
||||
@@ -286,6 +286,18 @@ def _flatten_string_enum_one_of(definition: dict[str, Any]) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def _normalize_open_ended_enum(definition: dict[str, Any]) -> None:
|
||||
variants = definition.pop("oneOf", definition.get("anyOf", []))
|
||||
definition["anyOf"] = [
|
||||
variant
|
||||
for variant in variants
|
||||
if "enum" in variant or variant.get("type") not in ("string", ["string", "object"])
|
||||
]
|
||||
object_fallback = {"type": "object", "additionalProperties": {}}
|
||||
if object_fallback not in definition["anyOf"]:
|
||||
definition["anyOf"].append(object_fallback)
|
||||
|
||||
|
||||
DISCRIMINATOR_KEYS = ("type", "method", "mode", "state", "status", "role", "reason")
|
||||
|
||||
|
||||
@@ -522,8 +534,10 @@ def _normalized_schema_bundle_text(schema_dir: Path) -> str:
|
||||
_preserve_guardian_approval_path_wrappers(schema)
|
||||
definitions = schema.get("definitions", {})
|
||||
if isinstance(definitions, dict):
|
||||
for definition in definitions.values():
|
||||
for name, definition in definitions.items():
|
||||
if isinstance(definition, dict):
|
||||
if name == "CodexErrorInfo":
|
||||
_normalize_open_ended_enum(definition)
|
||||
_flatten_string_enum_one_of(definition)
|
||||
# Normalize the schema into something datamodel-code-generator can map to
|
||||
# stable class names instead of anonymous numbered helpers.
|
||||
@@ -580,9 +594,10 @@ def generate_v2_all(schema_dir: Path) -> None:
|
||||
_require_nullable_field(
|
||||
out_path, "McpResourceReadTarget", r"link_id: Annotated\[\n(?: .*\n)+ \]"
|
||||
)
|
||||
_preserve_open_enum(out_path, "CodexErrorInfoValue", allow_empty=True)
|
||||
_preserve_reasoning_effort_enum(out_path)
|
||||
_preserve_thread_source_enum(out_path)
|
||||
_preserve_plan_type_enum(out_path)
|
||||
_preserve_open_enum(out_path, "PlanType")
|
||||
_normalize_generated_timestamps(out_path)
|
||||
|
||||
|
||||
@@ -687,27 +702,30 @@ def _preserve_thread_source_enum(out_path: Path) -> None:
|
||||
out_path.write_text(source[:class_start] + open_enum + source[class_end:])
|
||||
|
||||
|
||||
def _preserve_plan_type_enum(out_path: Path) -> None:
|
||||
"""Keep the public plan constants while accepting values from newer runtimes."""
|
||||
def _preserve_open_enum(out_path: Path, name: str, *, allow_empty: bool = False) -> None:
|
||||
"""Keep generated enum constants while accepting values from newer runtimes."""
|
||||
source = out_path.read_text()
|
||||
class_start = source.find("class PlanType(Enum):")
|
||||
class_start = source.find(f"class {name}(Enum):")
|
||||
if class_start == -1:
|
||||
raise RuntimeError("Generated SDK is missing PlanType")
|
||||
raise RuntimeError(f"Generated SDK is missing {name}")
|
||||
class_end = source.find("\n\nclass ", class_start)
|
||||
if class_end == -1:
|
||||
class_end = len(source)
|
||||
|
||||
class_source = source[class_start:class_end]
|
||||
class_source = class_source.replace(
|
||||
"class PlanType(Enum):",
|
||||
"class PlanType(str, Enum):",
|
||||
f"class {name}(Enum):",
|
||||
f"class {name}(str, Enum):",
|
||||
1,
|
||||
).rstrip()
|
||||
class_source += """
|
||||
invalid_value = "not isinstance(value, str)"
|
||||
if not allow_empty:
|
||||
invalid_value += " or not value"
|
||||
class_source += f"""
|
||||
|
||||
@classmethod
|
||||
def _missing_(cls, value: object) -> PlanType | None:
|
||||
if not isinstance(value, str) or not value:
|
||||
def _missing_(cls, value: object) -> {name} | None:
|
||||
if {invalid_value}:
|
||||
return None
|
||||
member = str.__new__(cls, value)
|
||||
member._name_ = value
|
||||
|
||||
@@ -538,7 +538,7 @@ class ClientInfo(BaseModel):
|
||||
version: str
|
||||
|
||||
|
||||
class CodexErrorInfoValue(Enum):
|
||||
class CodexErrorInfoValue(str, Enum):
|
||||
context_window_exceeded = "contextWindowExceeded"
|
||||
session_budget_exceeded = "sessionBudgetExceeded"
|
||||
usage_limit_exceeded = "usageLimitExceeded"
|
||||
@@ -555,6 +555,15 @@ class CodexErrorInfoValue(Enum):
|
||||
sandbox_error = "sandboxError"
|
||||
other = "other"
|
||||
|
||||
@classmethod
|
||||
def _missing_(cls, value: object) -> CodexErrorInfoValue | None:
|
||||
if not isinstance(value, str):
|
||||
return None
|
||||
member = str.__new__(cls, value)
|
||||
member._name_ = value
|
||||
member._value_ = value
|
||||
return member
|
||||
|
||||
|
||||
class HttpConnectionFailed(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
@@ -7669,6 +7678,7 @@ class CodexErrorInfo(
|
||||
| ResponseStreamDisconnectedCodexErrorInfo
|
||||
| ResponseTooManyFailedAttemptsCodexErrorInfo
|
||||
| ActiveTurnNotSteerableCodexErrorInfo
|
||||
| dict[str, Any]
|
||||
]
|
||||
):
|
||||
model_config = ConfigDict(
|
||||
@@ -7680,7 +7690,8 @@ class CodexErrorInfo(
|
||||
| ResponseStreamConnectionFailedCodexErrorInfo
|
||||
| ResponseStreamDisconnectedCodexErrorInfo
|
||||
| ResponseTooManyFailedAttemptsCodexErrorInfo
|
||||
| ActiveTurnNotSteerableCodexErrorInfo,
|
||||
| ActiveTurnNotSteerableCodexErrorInfo
|
||||
| dict[str, Any],
|
||||
Field(
|
||||
description="This translation layer make sure that we expose codex error code in camel case.\n\nWhen an upstream HTTP status is available (for example, from the Responses API or a provider), it is forwarded in `httpStatusCode` on the relevant `codexErrorInfo` variant."
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user