mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Add diagnostic reasons to MCP attribution errors (#47899)
## Why The `attribution_error` status does not explain why MCP attribution is incomplete. Preserve a diagnostic reason so callers can distinguish history and recorder errors from request serialization failures. ## What changed - Add optional `error_reason` diagnostics to `McpAttribution`, retaining the first recorder error through checkpoints, compaction, resume, and fork. - Identify missing or invalid checkpoints, conflicting sources, invalid sources, and poisoned recorder state. Use `restored_error_unknown` for older error checkpoints without a reason. - Distinguish `payload_too_large` from `serialization_failed` in request metadata fallbacks. - Tolerate missing, unknown, or malformed diagnostic reasons when reading history, without letting diagnostics determine attribution status. ## Testing Add coverage for reason preservation, recorder poisoning, backward-compatible checkpoint decoding, resume and cold-fork restoration, and request metadata serialization, including oversized payloads. GitOrigin-RevId: 389b9446fae119f793978f3e7e4a926677e84d8c
This commit is contained in:
committed by
Ian MacLeod
parent
b7add4df3d
commit
0d7f10b874
@@ -5,6 +5,7 @@
|
||||
//! `schemars`) so they can be embedded in Codex's own protocol structures.
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Deserializer;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use ts_rs::TS;
|
||||
@@ -62,6 +63,27 @@ pub enum McpAttributionStatus {
|
||||
AttributionError,
|
||||
}
|
||||
|
||||
/// Bounded diagnostics for an attribution error, never a policy decision.
|
||||
///
|
||||
/// Recorder reasons identify the first observed error and survive checkpoints.
|
||||
/// Payload reasons describe a request-serialization fallback and are not checkpointed.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[non_exhaustive]
|
||||
pub enum McpAttributionErrorReason {
|
||||
HistoryMissingCheckpoint,
|
||||
CheckpointInvalid,
|
||||
CheckpointSourceConflict,
|
||||
SourceInvalid,
|
||||
RecorderPoisoned,
|
||||
/// An earlier error checkpoint did not retain its cause.
|
||||
RestoredErrorUnknown,
|
||||
PayloadTooLarge,
|
||||
SerializationFailed,
|
||||
#[serde(other)]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
/// One source and the first runtime turn in which Codex recorded it.
|
||||
///
|
||||
/// Server and tool names are retained when no stable identifier is available;
|
||||
@@ -84,10 +106,27 @@ pub struct McpAttributionSource {
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct McpAttribution {
|
||||
pub status: McpAttributionStatus,
|
||||
/// First observed attribution error, absent for non-error states.
|
||||
#[serde(
|
||||
default,
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_mcp_attribution_error_reason"
|
||||
)]
|
||||
pub error_reason: Option<McpAttributionErrorReason>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub sources: Vec<McpAttributionSource>,
|
||||
}
|
||||
|
||||
fn deserialize_mcp_attribution_error_reason<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<McpAttributionErrorReason>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let value = serde_json::Value::deserialize(deserializer)?;
|
||||
Ok(serde_json::from_value(value).ok())
|
||||
}
|
||||
|
||||
/// Bounded app-resource provenance retained across a compaction checkpoint.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct McpResourceOriginCheckpoint {
|
||||
|
||||
Reference in New Issue
Block a user