Continue interrupted work after managed daemon restarts (#45820)

## Why

Daemon recovery reloads threads but leaves interrupted work unfinished. Resume eligible work automatically from the saved conversation, even without a connected client.

## What changed

- Attempt one new continuation turn immediately after restoration, including in Plan mode. Mark the old turn interrupted and supply recovery context without creating a user message or granting new authorization.
- Require an idle thread, matching permissions, and the same single local environment configured by the thread. Skip completed, aborted, or superseded work and snapshots without environment identity.
- Add `continue_turn_if_idle` with an atomic previous-turn check so newer tasks or standalone settings changes invalidate pending continuation.
- Preserve the output schema, service tier, and root turn ID, and emit a “Resuming interrupted work” warning when continuation starts.

## Testing

Add daemon restart coverage for continuation without a client, Plan mode, permission and environment mismatches, and legacy snapshots. Add core coverage for preserved continuation metadata, absence of user-message events, rejection of superseded continuations, and exclusion of remote execution from recovery snapshots.

GitOrigin-RevId: 2b290b75d9399fc58258bcda2e85c74e9b5b3b09
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-16 00:54:58 +00:00
1 parent 7c709f0ffd
commit f2b5b81f39
21 files changed
+641 -55

No files matched your search

+20 -1
View File
@@ -357,6 +357,23 @@ impl CodexThread {
}
}
/// Starts a new internal continuation turn when idle, including in Plan mode.
/// Rejects if a newer task has started, even if it has already finished.
/// The input must be a response item; it is never treated as user authorization.
pub async fn continue_turn_if_idle(
&self,
request: TurnInputRequest,
expected_previous_turn_id: String,
) -> CodexResult<TurnInputSubmission> {
self.submit_turn_input_with_mode(
request,
TurnInputMode::ContinueIfIdle {
expected_previous_turn_id,
},
)
.await
}
/// Resumes an interrupted regular turn only when the thread is idle.
///
/// Recovery starts no new user input and preserves the turn ID that was
@@ -498,7 +515,9 @@ impl CodexThread {
}
/// 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)> {
pub async fn interrupted_turn(
&self,
) -> Option<(String, TurnStartOptions, TurnEnvironmentSelection)> {
self.session.interrupted_turn().await
}