mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Record interrupted turns in managed daemon recovery snapshots (#45807)
## Why Managed daemon recovery snapshots previously saved only loaded thread IDs, without identifying active turns or preserving their turn-specific options. ## What changed - Capture regular, uncanceled turns after their input is recorded, saving the turn ID, output schema, service tier, and cyber access program alongside persisted thread IDs. - Store interruption metadata atomically in the existing candidate array format so older servers can still read thread candidates. - Begin snapshotting once admitted operations drain, while turns may still be running. Run snapshot collection and thread listener attachment independently of the event loop to keep forced shutdown responsive. ## Testing Add coverage for running, completed, canceled, and compacting turns; recovery readiness for automatic and user turns; admitted resumes during shutdown; forced shutdown with a blocked rollout writer and child listener attachment; and legacy candidate-array compatibility. GitOrigin-RevId: ed46342c3a5c71b09c48fa9acece2f15ae748e2f
This commit is contained in:
@@ -497,6 +497,11 @@ impl CodexThread {
|
||||
self.session.inject_if_running(items).await
|
||||
}
|
||||
|
||||
/// Captures a regular turn only after its input is recorded. The caller must flush the rollout.
|
||||
pub async fn interrupted_turn(&self) -> Option<(String, TurnStartOptions)> {
|
||||
self.session.interrupted_turn().await
|
||||
}
|
||||
|
||||
/// Returns the trusted root when the expected turn is currently active.
|
||||
pub async fn active_turn_root(&self, expected_turn_id: &str) -> Option<String> {
|
||||
let active = self.session.active_turn.lock().await;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//! Captures recorded, uncanceled regular turns for managed daemon recovery.
|
||||
//! Callers must flush the rollout after capture before persisting the snapshot.
|
||||
|
||||
use super::Session;
|
||||
|
||||
/// Turn input and turn-start injections have entered the rollout writer.
|
||||
pub(super) struct RecordedTurnInput;
|
||||
|
||||
impl Session {
|
||||
/// Captures a regular turn only after its input is recorded. The caller must flush the rollout.
|
||||
pub(crate) async fn interrupted_turn(&self) -> Option<(String, crate::TurnStartOptions)> {
|
||||
let active = self.active_turn.lock().await;
|
||||
let task = active.as_ref()?.task.as_ref()?;
|
||||
if task.kind != crate::state::TaskKind::Regular || task.cancellation_token.is_cancelled() {
|
||||
return None;
|
||||
}
|
||||
let context = &task.turn_context;
|
||||
context.extension_data.get::<RecordedTurnInput>()?;
|
||||
Some((
|
||||
context.sub_id.clone(),
|
||||
crate::TurnStartOptions {
|
||||
final_output_json_schema: context.final_output_json_schema.clone(),
|
||||
service_tier: Some(
|
||||
context
|
||||
.current_settings
|
||||
.load()
|
||||
.service_tier
|
||||
.clone()
|
||||
.unwrap_or_else(|| {
|
||||
codex_protocol::config_types::SERVICE_TIER_DEFAULT_REQUEST_VALUE
|
||||
.to_string()
|
||||
}),
|
||||
),
|
||||
cyber_access_program: context.cyber_access_program,
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -227,6 +227,7 @@ use codex_protocol::exec_output::StreamOutput;
|
||||
|
||||
mod code_mode_warning;
|
||||
pub(crate) mod context_window;
|
||||
mod daemon_recovery;
|
||||
mod environment;
|
||||
mod extension_interruption;
|
||||
pub(crate) mod extension_metrics;
|
||||
|
||||
@@ -35,6 +35,7 @@ use crate::responses_retry::ResponsesStreamRetryState;
|
||||
use crate::responses_retry::handle_retryable_response_stream_error;
|
||||
use crate::session::PreviousTurnSettings;
|
||||
use crate::session::TurnInput;
|
||||
use crate::session::daemon_recovery::RecordedTurnInput;
|
||||
use crate::session::session::Session;
|
||||
use crate::session::step_context::StepContext;
|
||||
use crate::session::turn_context::TurnContext;
|
||||
@@ -445,6 +446,8 @@ pub(crate) async fn run_turn(
|
||||
break;
|
||||
}
|
||||
|
||||
// Input and turn-start injections are recorded before recovery can continue this turn.
|
||||
turn_context.extension_data.insert(RecordedTurnInput);
|
||||
let window_id = sess.current_window_id().await;
|
||||
super::rollout_budget::maybe_record_reminder(
|
||||
sess.as_ref(),
|
||||
|
||||
Reference in New Issue
Block a user