mirror of
https://github.com/openai/codex.git
synced 2026-10-19 17:28:46 +00:00
## What changed - Wrap `CodexErrorDetails` and an optional retry delay in `CodexErr`, allowing any mapped error to preserve server-provided retry timing. - Generate the payload-free `CodexErrKind` classification alongside the error details and reuse it for analytics. - Update error handling sites to inspect `CodexErr::details()` while preserving existing display, debug, protocol mapping, and retryability behavior. ## Testing - Add coverage for legacy debug formatting, error-specific retryability, and retry-delay propagation through API error mapping. GitOrigin-RevId: d3ab8a305f2a2ee21d0c0a8c8c388b06dda9c59a
87 lines
2.8 KiB
Rust
87 lines
2.8 KiB
Rust
use std::sync::Arc;
|
|
|
|
use super::SessionTask;
|
|
use super::SessionTaskContext;
|
|
use super::SessionTaskResult;
|
|
use super::emit_compact_metric;
|
|
use crate::session::TurnInput;
|
|
use crate::session::turn_context::TurnContext;
|
|
use crate::state::TaskKind;
|
|
use codex_features::Feature;
|
|
use codex_protocol::error::CodexErrorDetails;
|
|
use codex_protocol::user_input::UserInput;
|
|
use tokio_util::sync::CancellationToken;
|
|
|
|
#[derive(Clone, Copy, Default)]
|
|
pub(crate) struct CompactTask;
|
|
|
|
impl SessionTask for CompactTask {
|
|
fn kind(&self) -> TaskKind {
|
|
TaskKind::Compact
|
|
}
|
|
|
|
fn span_name(&self) -> &'static str {
|
|
"session_task.compact"
|
|
}
|
|
|
|
async fn run(
|
|
self: Arc<Self>,
|
|
session: Arc<SessionTaskContext>,
|
|
ctx: Arc<TurnContext>,
|
|
_input: Vec<TurnInput>,
|
|
_cancellation_token: CancellationToken,
|
|
) -> SessionTaskResult {
|
|
let session = session.clone_session();
|
|
let _profile_guard = ctx.turn_timing_state.begin_compaction();
|
|
if ctx.config.features.enabled(Feature::TokenBudget) {
|
|
crate::compact_token_budget::run_manual_compact_task(session, ctx).await?;
|
|
return Ok(None);
|
|
}
|
|
|
|
let result = if crate::compact::should_use_remote_compact_task(ctx.provider.info()) {
|
|
if ctx
|
|
.config
|
|
.features
|
|
.enabled(codex_features::Feature::RemoteCompactionV2)
|
|
{
|
|
emit_compact_metric(
|
|
&session.services.session_telemetry,
|
|
"remote_v2",
|
|
/*manual*/ true,
|
|
);
|
|
crate::compact_remote_v2::run_remote_compact_task(session.clone(), ctx).await
|
|
} else {
|
|
emit_compact_metric(
|
|
&session.services.session_telemetry,
|
|
"remote",
|
|
/*manual*/ true,
|
|
);
|
|
crate::compact_remote::run_remote_compact_task(session.clone(), ctx).await
|
|
}
|
|
} else {
|
|
emit_compact_metric(
|
|
&session.services.session_telemetry,
|
|
"local",
|
|
/*manual*/ true,
|
|
);
|
|
let input = vec![UserInput::Text {
|
|
text: ctx
|
|
.config
|
|
.compact_prompt
|
|
.as_deref()
|
|
.unwrap_or(crate::compact::SUMMARIZATION_PROMPT)
|
|
.to_string(),
|
|
// Compaction prompt is synthesized; no UI element ranges to preserve.
|
|
text_elements: Vec::new(),
|
|
}];
|
|
crate::compact::run_compact_task(session.clone(), ctx, input).await
|
|
};
|
|
if let Err(err) = result
|
|
&& matches!(err.details(), CodexErrorDetails::TurnAborted)
|
|
{
|
|
return Err(err);
|
|
}
|
|
Ok(None)
|
|
}
|
|
}
|