Centralize app-server turn error conversion (#62096)

## What changed

Add a shared `From<ErrorEvent>` implementation for `TurnError` and reuse it in thread history, rollout projection, and live event handling. Preserve the existing field mappings and keep `additional_details` unset.

Parameterize the compaction replay test by error code and recoverability, retaining the existing `server_error` case, and document retry expectations for WebSocket closes.

GitOrigin-RevId: 3afcc23e9fdc314477febe6b4a4aeb680efafd5a
This commit is contained in:
adi-oai
2026-11-17 18:56:05 +00:00
committed by copyberry
parent cb64621bf3
commit 0122b120cd
6 changed files with 47 additions and 65 deletions
@@ -1427,12 +1427,7 @@ impl ThreadHistoryBuilder {
let tracking_changes = self.is_tracking_changes();
let changed_turn = if let Some(turn) = self.current_turn.as_mut() {
turn.status = TurnStatus::Failed;
turn.error = Some(V2TurnError {
misalignment: payload.misalignment.clone().map(Into::into),
message: payload.message.clone(),
codex_error_info: payload.codex_error_info.clone().map(Into::into),
additional_details: None,
});
turn.error = Some(V2TurnError::from(payload.clone()));
tracking_changes.then(|| ThreadHistoryTurnMetadata::from_pending_turn(turn))
} else {
None
@@ -1443,12 +1438,7 @@ impl ThreadHistoryBuilder {
}
fn handle_turn_aborted(&mut self, payload: &TurnAbortedEvent) {
let terminal_error = payload.error.as_ref().map(|error| V2TurnError {
message: error.message.clone(),
codex_error_info: error.codex_error_info.clone().map(Into::into),
misalignment: error.misalignment.clone().map(Into::into),
additional_details: None,
});
let terminal_error = payload.error.clone().map(V2TurnError::from);
let apply_abort = |turn: &mut PendingTurn| {
turn.status = TurnStatus::Interrupted;
if let Some(error) = terminal_error.as_ref() {
@@ -1497,12 +1487,7 @@ impl ThreadHistoryBuilder {
}
fn handle_turn_complete(&mut self, payload: &TurnCompleteEvent) {
let terminal_error = payload.error.as_ref().map(|error| V2TurnError {
misalignment: error.misalignment.clone().map(Into::into),
message: error.message.clone(),
codex_error_info: error.codex_error_info.clone().map(Into::into),
additional_details: None,
});
let terminal_error = payload.error.clone().map(V2TurnError::from);
let apply_completion = |turn: &mut PendingTurn| {
if let Some(error) = terminal_error.as_ref() {
turn.status = TurnStatus::Failed;
@@ -41,12 +41,7 @@ pub fn project_rollout_line(line: &RolloutLine) -> ThreadHistoryChangeSet {
} else {
TurnStatus::Completed
},
error: event.error.as_ref().map(|error| TurnError {
misalignment: error.misalignment.clone().map(Into::into),
message: error.message.clone(),
codex_error_info: error.codex_error_info.clone().map(Into::into),
additional_details: None,
}),
error: event.error.clone().map(TurnError::from),
started_at: event.started_at,
completed_at: event.completed_at,
duration_ms: event.duration_ms,
@@ -62,12 +57,7 @@ pub fn project_rollout_line(line: &RolloutLine) -> ThreadHistoryChangeSet {
turn_id: turn_id.clone(),
root_turn_id: event.root_turn_id.clone(),
status: TurnStatus::Interrupted,
error: event.error.as_ref().map(|error| TurnError {
message: error.message.clone(),
codex_error_info: error.codex_error_info.clone().map(Into::into),
misalignment: error.misalignment.clone().map(Into::into),
additional_details: None,
}),
error: event.error.clone().map(TurnError::from),
started_at: event.started_at,
completed_at: event.completed_at,
duration_ms: event.duration_ms,
@@ -451,6 +451,18 @@ pub struct TurnError {
pub misalignment: Option<MisalignmentErrorDetails>,
}
impl From<codex_protocol::protocol::ErrorEvent> for TurnError {
fn from(error: codex_protocol::protocol::ErrorEvent) -> Self {
let additional_details = None;
Self {
message: error.message,
codex_error_info: error.codex_error_info.map(Into::into),
additional_details,
misalignment: error.misalignment.map(Into::into),
}
}
}
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]