mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Preserve known error classifications, including BioPolicy, while falling back to Other for unknown values so saved sessions can still be read. Add optional gateway OAuth settings to model provider configuration. Co-authored-by: Owen Lin <owen@openai.com> Co-authored-by: alexsong-oai <alexsong@openai.com> GitOrigin-RevId: 64bcf45ca042efca7645c798db3746375426b0fe
83 lines
2.3 KiB
Rust
83 lines
2.3 KiB
Rust
//! Decodes unknown error classifications as `Other` so enclosing records stay readable.
|
|
//! The wire definition keeps serialization exhaustive and known payload validation strict.
|
|
|
|
use crate::protocol::CodexErrorInfo;
|
|
use crate::protocol::NonSteerableTurnKind;
|
|
use serde::Deserialize;
|
|
use serde::Deserializer;
|
|
use serde::Serialize;
|
|
use serde::Serializer;
|
|
use serde::de::Error as _;
|
|
use serde_json::Value;
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
#[serde(
|
|
remote = "CodexErrorInfo",
|
|
rename = "CodexErrorInfo",
|
|
rename_all = "snake_case"
|
|
)]
|
|
enum CodexErrorInfoWire {
|
|
ContextWindowExceeded,
|
|
SessionBudgetExceeded,
|
|
UsageLimitExceeded,
|
|
RateLimitExceeded,
|
|
ServerOverloaded,
|
|
CyberPolicy,
|
|
BioPolicy,
|
|
MisalignmentPolicyViolation,
|
|
HttpConnectionFailed {
|
|
http_status_code: Option<u16>,
|
|
},
|
|
ResponseStreamConnectionFailed {
|
|
http_status_code: Option<u16>,
|
|
},
|
|
InternalServerError,
|
|
Unauthorized,
|
|
BadRequest,
|
|
SandboxError,
|
|
ResponseStreamDisconnected {
|
|
http_status_code: Option<u16>,
|
|
},
|
|
ResponseTooManyFailedAttempts {
|
|
http_status_code: Option<u16>,
|
|
},
|
|
ActiveTurnNotSteerable {
|
|
turn_kind: NonSteerableTurnKind,
|
|
},
|
|
ThreadRollbackFailed,
|
|
#[serde(other)]
|
|
Other,
|
|
}
|
|
|
|
impl Serialize for CodexErrorInfo {
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer,
|
|
{
|
|
CodexErrorInfoWire::serialize(self, serializer)
|
|
}
|
|
}
|
|
|
|
impl<'de> Deserialize<'de> for CodexErrorInfo {
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
let value = Value::deserialize(deserializer)?;
|
|
// Probe the tag first so only unknown payloads are discarded: `serde(other)`
|
|
// recognizes unknown tags, but its unit variant rejects their payloads.
|
|
if let Value::Object(fields) = &value
|
|
&& fields.len() == 1
|
|
&& let Some(kind) = fields.keys().next()
|
|
&& kind != "other"
|
|
&& matches!(
|
|
CodexErrorInfoWire::deserialize(Value::String(kind.clone())),
|
|
Ok(Self::Other)
|
|
)
|
|
{
|
|
return Ok(Self::Other);
|
|
}
|
|
CodexErrorInfoWire::deserialize(value).map_err(D::Error::custom)
|
|
}
|
|
}
|