Add interrupted turn recovery (#38303)

## What changed

- Add `RecoverTurnRequest` and `CodexThread::recover_turn_if_idle` to resume an interrupted regular turn with its existing turn ID and updated thread settings.
- Treat recovery separately from automatic idle work so it can resume in Plan mode without injecting an empty user message.
- Reject recovery while another turn is active without applying settings or queuing input.

## Testing

- Cover successful Plan-mode recovery, turn ID preservation, and the absence of an empty user message.
- Cover active-turn rejection and verify that it leaves settings and pending input unchanged.

GitOrigin-RevId: 2376fdc78b5d48b571633981960741ba269ab1ef
This commit is contained in:
Owen Lin authored and copyberry committed 2026-08-13 03:27:19 +00:00
1 parent 357696c5e7
commit 363427b5e3
10 files changed
+228 -4

No files matched your search

+11
View File
@@ -38,6 +38,17 @@ pub struct TurnInputRequest {
pub trace: Option<W3cTraceContext>,
}
/// Request to resume sampling for an interrupted regular turn.
///
/// Sampling restarts under `turn_id`, which must be the ID already recorded
/// for that turn.
#[derive(Clone, Debug)]
pub struct RecoverTurnRequest {
pub turn_id: String,
pub thread_settings: ThreadSettingsOverrides,
pub trace: Option<W3cTraceContext>,
}
impl TurnInputRequest {
/// Creates turn input that can be passed to one of the submission methods.
pub fn new(input: TurnInput) -> Self {