Add experimental prediction forks that inherit parent context (#51884)

## Why

Prediction forks need to preserve the parent's effective context and request settings to maximize prompt-cache reuse.

## What changed

- Add `experimentalPredictionMode` to `thread/fork` for ephemeral forks of loaded, persisted parents. Reject configuration overrides, `path`, `lastTurnId`, and `beforeTurnId` in this mode.
- Inherit the parent's effective configuration, tools, environments, collaboration settings, disabled plugins, and persisted history.
- Enable `features.reasoning_effort_override` on the fork while preserving the parent's request-effort baseline, including when overrides were disabled on the parent.
- Report the fork's effective model, service tier, and reasoning effort in the response.

## Testing

Add coverage for matching parent and fork requests and prompt-cache keys across legacy and paginated history, invalid fork parameters, and reasoning-effort inheritance. Add a context snapshot for identical parent and fork continuations.

GitOrigin-RevId: 46b41f2ac331562b441dadff1a0a9f926c94880d
This commit is contained in:
liame-oai
2026-10-08 00:09:03 +00:00
committed by copyberry
parent f73a478c87
commit ec8251c545
14 changed files with 1021 additions and 161 deletions
+31
View File
@@ -9,6 +9,7 @@ pub use shutdown::AgentTreeShutdownReport;
pub(crate) use shutdown::thread_store_error_kind;
use crate::CodexAppsToolsCache;
use crate::CodexThreadSettingsOverrides;
use crate::agent::LocalAgentControl;
use crate::agent::api::AgentConfigUpdate;
use crate::agent::api::AgentControl;
@@ -1436,6 +1437,36 @@ impl ThreadManager {
report
}
/// Captures the parent's current settings for a persisted-history fork.
/// Apply the returned settings to the new thread before starting its first turn.
pub async fn fork_options_from_parent(
&self,
source_thread_id: ThreadId,
) -> CodexResult<(StartThreadOptions, CodexThreadSettingsOverrides)> {
let parent = self.get_thread(source_thread_id).await?;
let (config, settings, windows_sandbox_level, environments, reasoning_effort_pin) =
parent.session.fork_config().await;
let mut thread_extension_init = ExtensionDataInit::default();
thread_extension_init.insert(reasoning_effort_pin);
Ok((
StartThreadOptions {
history_mode: Some(settings.history_mode),
environments: Some(settings.environments.into_requests().environment_requests),
inherited_environments: Some(environments),
client_mcp_extensions: parent.client_mcp_extensions(),
disabled_plugin_ids: Some(settings.disabled_plugin_ids),
thread_extension_init,
turn_extension_init: settings.turn_extension_init,
..StartThreadOptions::new(config)
},
CodexThreadSettingsOverrides {
collaboration_mode: Some(settings.collaboration_mode),
windows_sandbox_level: Some(windows_sandbox_level),
..Default::default()
},
))
}
/// Fork a legacy thread by snapshotting its full rollout history according to
/// `snapshot` and starting a new thread with identical configuration
/// (unless overridden by the caller's options). The new thread has a fresh id.