Files
codex/codex-rs/protocol/src/codex_error_info.rs
T
Won Park d7748e1185 Add opt-in structured errors for Guardian circuit-breaker interruptions (#48796)
## Why

Guardian denial-limit interruptions lack a structured error identifying the cause. Make this opt-in because older clients may not recognize the new error in shared history.

## What changed

- Add `auto_review.circuit_break_action = "strict"` to attach `TooManyDenials` to the interrupted turn. The default leaves the error unset.
- Expose `turn.error.codexErrorInfo = "tooManyDenials"` in app-server notifications and saved history, and update protocol schemas and generated types.
- Preserve the warning, denial limit, and interrupted status without emitting a separate error notification.

## Testing

Add an integration test covering omitted, `default`, and `strict` settings, checking warnings, live turn errors, the absence of separate error notifications, and persisted turn errors after restart.

GitOrigin-RevId: cb5d379e64728d4d7b9daf834c13756e4a70db31
2026-09-27 22:05:19 +00:00

86 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,
FlexUnavailable,
ServerOverloaded,
CyberPolicy,
BioPolicy,
MisalignmentPolicyViolation,
TooManyDenials,
HttpConnectionFailed {
http_status_code: Option<u16>,
},
ResponseStreamConnectionFailed {
http_status_code: Option<u16>,
},
InternalServerError,
Unauthorized,
BadRequest,
InvalidPrompt,
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)
}
}