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
+2
View File
@@ -41,6 +41,7 @@ pub use codex_core::EnvironmentNetworkPolicy;
pub use codex_core::ForkSnapshot;
pub use codex_core::InputWaitOutcome;
pub use codex_core::LoadedAgentsMd;
pub use codex_core::LoadedSuspendedAgent;
pub use codex_core::McpManager;
pub use codex_core::NetworkDomainPermission;
pub use codex_core::NetworkDomainPermissionEntry;
@@ -59,6 +60,7 @@ pub use codex_core::StartupModels;
pub use codex_core::StateDbHandle;
pub use codex_core::SteerSubmission;
pub use codex_core::SuspendTurnOutcome;
pub use codex_core::SuspendedAgentTree;
pub use codex_core::ThreadManager;
pub use codex_core::ThreadShutdownReport;
pub use codex_core::ThreadStoreBuilder;