mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Add app-server support for reverting paginated threads (#38440)
## What changed - Add the experimental `thread/revert` request, which replaces a loaded paginated thread's durable history with the prefix before `beforeTurnId` while preserving the thread ID. - Interrupt any active turn, reload the replacement history without unloading the thread, preserve mutable thread settings, and emit `thread/reverted`. - Return backward pagination cursors for the retained turns and items, reject stale rollout paths after a revert, and document that local file changes are unaffected. ## Testing - Cover history replacement, pagination, stale paths, missing turns, subsequent turns, active-turn interruption, and preserved thread settings. GitOrigin-RevId: 435a8163ad4f310cc47219b436f6bdde21f2b83a
This commit is contained in:
@@ -20,6 +20,7 @@ use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::error::CodexErr;
|
||||
use codex_protocol::error::Result as CodexResult;
|
||||
use codex_protocol::mcp::CallToolResult;
|
||||
use codex_protocol::mcp::ClientMcpExtensions;
|
||||
use codex_protocol::models::ActivePermissionProfile;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::PermissionProfile;
|
||||
@@ -125,6 +126,22 @@ impl ThreadConfigSnapshot {
|
||||
collaboration_mode: self.collaboration_mode,
|
||||
}
|
||||
}
|
||||
|
||||
fn into_thread_settings_overrides(self) -> CodexThreadSettingsOverrides {
|
||||
CodexThreadSettingsOverrides {
|
||||
environments: Some(self.environments),
|
||||
profile_workspace_roots: Some(self.profile_workspace_roots),
|
||||
approval_policy: Some(self.approval_policy),
|
||||
approvals_reviewer: Some(self.approvals_reviewer),
|
||||
permission_profile: Some(self.permission_profile),
|
||||
active_permission_profile: self.active_permission_profile,
|
||||
summary: self.reasoning_summary,
|
||||
service_tier: Some(self.service_tier),
|
||||
collaboration_mode: Some(self.collaboration_mode),
|
||||
personality: self.personality,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Thread settings overrides that app-server validates before starting a turn.
|
||||
@@ -406,6 +423,20 @@ impl CodexThread {
|
||||
self.session.preview_settings(&updates).await
|
||||
}
|
||||
|
||||
/// Restores effective mutable settings captured from another loaded runtime.
|
||||
///
|
||||
/// Runtime replacement uses this after resume so clients keep their current thread settings
|
||||
/// rather than reverting to the original layer-backed config.
|
||||
pub async fn restore_thread_settings(
|
||||
&self,
|
||||
snapshot: ThreadConfigSnapshot,
|
||||
) -> ConstraintResult<()> {
|
||||
let updates = self
|
||||
.thread_settings_update(snapshot.into_thread_settings_overrides())
|
||||
.await;
|
||||
self.session.update_settings(updates).await
|
||||
}
|
||||
|
||||
async fn thread_settings_update(
|
||||
&self,
|
||||
overrides: CodexThreadSettingsOverrides,
|
||||
@@ -617,6 +648,11 @@ impl CodexThread {
|
||||
self.session.thread_config_snapshot().await
|
||||
}
|
||||
|
||||
/// Returns the MCP extensions declared by the client that created this runtime.
|
||||
pub fn client_mcp_extensions(&self) -> ClientMcpExtensions {
|
||||
self.session.services.client_mcp_extensions.clone()
|
||||
}
|
||||
|
||||
/// Returns the files that supplied the thread's loaded model instructions.
|
||||
pub async fn instruction_sources(&self) -> Vec<PathUri> {
|
||||
self.session.instruction_sources().await
|
||||
|
||||
Reference in New Issue
Block a user