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:
Eric Traut authored and copyberry committed 2026-09-15 23:31:44 +00:00
1 parent 7f83d4922d
commit 4d2807023a
12 files changed
+407 -38

No files matched your search

@@ -832,3 +832,36 @@ async fn start_or_steer_turn_requires_matching_active_output_schema() {
assert!(!second_request.contains("rejected steer"));
server.shutdown().await;
}
#[test_case(Vec::new(); "automatic")]
#[test_case(vec![UserInput::Text { text: "Do the work".into(), text_elements: Vec::new() }]; "user")]
#[tokio::test]
async fn sampling_is_ready_for_daemon_recovery(input: Vec<UserInput>) -> anyhow::Result<()> {
let (release, gate) = oneshot::channel();
let (server, _completions) = start_streaming_sse_server(vec![vec![StreamingSseChunk {
gate: Some(gate),
body: responses::sse_completed("automatic"),
}]])
.await;
let test = test_codex().build_with_streaming_server(&server).await?;
let StartIfIdleSubmission::Started { turn_id } = test
.codex
.start_turn_if_idle(TurnInputRequest::user_input(input))
.await?
else {
panic!("sampling should start");
};
timeout(
Duration::from_secs(5),
server.wait_for_request_count(/*count*/ 1),
)
.await?;
let active = test.codex.interrupted_turn().await;
assert_eq!(active.map(|(id, _)| id), Some(turn_id));
release.send(()).expect("sampling is waiting");
wait_for_event(&test.codex, |event| {
matches!(event, EventMsg::TurnComplete(_))
})
.await;
Ok(())
}