Add graceful agent-tree suspension and recovery (#61198)

## Why

Suspending a locally controlled agent tree must preserve unfinished turns and child results that arrive during teardown so they remain available after recovery.

## What changed

- Add `ThreadManager::suspend_agent_tree` to stop durable trees, close their writers, and return unfinished root and named V2 child turn IDs plus any pending root wake.
- Persist terminal child results before suspension succeeds, including results queued for evicted parents. Report failed or unconfirmed writes.
- Add `load_suspended_agent` to restore named V2 descendants through their recorded ancestors without starting model turns.
- Allow empty `continue_turn_if_idle` input to wake on saved results, guarded by the preceding turn ID. Keep mail queued until task registration so suspension can preserve it.

## Testing

Add coverage for completion and wake races, child errors, parent writer failures, evicted parents, descendant restoration, repeated suspension after caller cancellation, and ephemeral roots remaining active.

GitOrigin-RevId: 3041791f51bff2555210f6b2d2443f9f05f68330
This commit is contained in:
Bryan Ashley
2026-11-12 22:43:14 +00:00
committed by copyberry
parent cdfcc18dba
commit fae87361f4
30 changed files with 1480 additions and 320 deletions
+3 -1
View File
@@ -587,7 +587,9 @@ 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.
/// Supply an internal response item, or empty input to wake on a result already
/// saved in history. An empty wake inherits the preceding turn's attribution
/// and adds no message or user authorization.
pub async fn continue_turn_if_idle(
&self,
request: impl Into<WithTurnExtensionData<TurnInputRequest>>,