Pass inherited history visibility to the thread store (#62644)

## What changed

Add `InheritedHistoryVisibility` to `CreateThreadParams` and pass it through
prepared forks. `Full` is the default and remains the mode used by app-server
forks. `ModelContextOnly` requests that `list_turns` and `list_items` omit
inherited history. The local thread store rejects that mode as unsupported.

## Testing

Add a regression test that requests `ModelContextOnly` through a prepared fork
and checks that the local store's unsupported-operation error reaches the caller.

GitOrigin-RevId: de675d6b83ca610eca5a304b9622b312d64828f6
This commit is contained in:
Owen Lin
2026-11-20 02:02:55 +00:00
committed by copyberry
parent 983feef7a1
commit 10ca17496f
30 changed files with 121 additions and 5 deletions
@@ -500,6 +500,7 @@ impl ExternalAgentSessionImporter {
multi_agent_version: Some(MultiAgentVersion::V1),
history_mode: ThreadHistoryMode::Legacy,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
metadata: ThreadPersistenceMetadata {
@@ -5906,7 +5906,11 @@ impl ThreadRequestProcessor {
};
let new_thread = if let Some(prepared_fork) = prepared_fork {
self.thread_manager
.fork_prepared_thread(fork_options, prepared_fork)
.fork_prepared_thread(
fork_options,
prepared_fork,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await
} else {
self.thread_manager
@@ -139,6 +139,7 @@ async fn get_conversation_summary_by_thread_id_reads_pathless_store_thread() ->
multi_agent_version: None,
history_mode: Default::default(),
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -302,6 +302,7 @@ async fn thread_list_repeated_cursor_returns_internal_error() -> Result<()> {
multi_agent_version: None,
history_mode: Default::default(),
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -554,6 +555,7 @@ async fn thread_delete_with_non_local_thread_store_does_not_create_local_persist
multi_agent_version: None,
history_mode: Default::default(),
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -660,6 +660,7 @@ async fn thread_search_occurrences_reads_paginated_projection() -> Result<()> {
multi_agent_version: None,
history_mode: codex_protocol::protocol::ThreadHistoryMode::Paginated,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -3130,6 +3131,7 @@ async fn create_paginated_thread(
multi_agent_version: None,
history_mode: codex_protocol::protocol::ThreadHistoryMode::Paginated,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -3248,6 +3250,7 @@ async fn seed_pathless_store_thread(
multi_agent_version: None,
history_mode: Default::default(),
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -76,6 +76,7 @@ fn create_params(codex_home: &Path, thread_id: ThreadId) -> CreateThreadParams {
multi_agent_version: None,
history_mode: ThreadHistoryMode::Paginated,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -264,6 +264,7 @@ async fn thread_unarchive_preserves_pathless_store_metadata() -> Result<()> {
multi_agent_version: None,
history_mode: Default::default(),
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
+2
View File
@@ -191,6 +191,7 @@ use codex_sandboxing::policy_transforms::intersect_permission_profiles_with_cont
use codex_shell_command::parse_command::parse_command;
use codex_terminal_detection::user_agent;
use codex_thread_store::CreateThreadParams;
use codex_thread_store::InheritedHistoryVisibility;
use codex_thread_store::LiveThread;
use codex_thread_store::LiveThreadInitGuard;
use codex_thread_store::LocalThreadStore;
@@ -497,6 +498,7 @@ pub(crate) enum ForkPersistence {
Referenced {
history_base: Option<HistoryPosition>,
inherited_item_count: usize,
inherited_history_visibility: InheritedHistoryVisibility,
},
}
+9
View File
@@ -1148,6 +1148,15 @@ impl Session {
ForkPersistence::Copied | ForkPersistence::CopiedDeferred => None,
ForkPersistence::Referenced { history_base, .. } => *history_base,
},
inherited_history_visibility: match &fork_persistence {
ForkPersistence::Copied | ForkPersistence::CopiedDeferred => {
InheritedHistoryVisibility::Full
}
ForkPersistence::Referenced {
inherited_history_visibility,
..
} => *inherited_history_visibility,
},
subagent_history_start_ordinal: None,
initial_window_id: ids.initial_window_id.clone(),
runtime_workspace_roots: Some(config.workspace_roots.clone()),
+4
View File
@@ -4830,6 +4830,7 @@ async fn open_thread_persistence(session: &mut Session) -> PathBuf {
history_mode: Default::default(),
subagent_history_start_ordinal: None,
history_base: None,
inherited_history_visibility: Default::default(),
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
metadata: ThreadPersistenceMetadata {
@@ -8636,6 +8637,7 @@ async fn shutdown_complete_does_not_append_to_thread_store_after_shutdown() {
history_mode: Default::default(),
subagent_history_start_ordinal: None,
history_base: None,
inherited_history_visibility: Default::default(),
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
metadata: ThreadPersistenceMetadata {
@@ -8775,6 +8777,7 @@ async fn submission_loop_channel_close_runs_full_thread_teardown() -> anyhow::Re
history_mode: Default::default(),
subagent_history_start_ordinal: None,
history_base: None,
inherited_history_visibility: Default::default(),
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
metadata: ThreadPersistenceMetadata {
@@ -11773,6 +11776,7 @@ async fn attach_in_memory_thread_store(
history_mode: Default::default(),
subagent_history_start_ordinal: None,
history_base: None,
inherited_history_visibility: Default::default(),
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
metadata: ThreadPersistenceMetadata {
+3
View File
@@ -110,6 +110,7 @@ use codex_protocol::protocol::W3cTraceContext;
use codex_rollout::state_db::StateDbHandle;
use codex_runtime_agent_instance::RuntimeAuthManager;
use codex_skills_extension::HostSkillsService;
use codex_thread_store::InheritedHistoryVisibility;
use codex_thread_store::LoadThreadHistoryParams;
use codex_thread_store::LocalThreadStore;
use codex_thread_store::LocalThreadStoreConfig;
@@ -1919,6 +1920,7 @@ impl ThreadManager {
&self,
options: StartThreadOptions,
prepared: PreparedFork,
inherited_history_visibility: InheritedHistoryVisibility,
) -> CodexResult<NewThread> {
let history = InitialHistory::Resumed(ResumedHistory {
history_revision: None,
@@ -1929,6 +1931,7 @@ impl ThreadManager {
let fork_persistence = ForkPersistence::Referenced {
history_base: prepared.history_base,
inherited_item_count: prepared.model_context.len(),
inherited_history_visibility,
};
let result = self
.fork_thread_with_initial_history(
@@ -723,7 +723,11 @@ async fn hosted_child_persists_inherited_session_id(
})
.await?;
manager
.fork_prepared_thread(child_options, prepared)
.fork_prepared_thread(
child_options,
prepared,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await?
}
};
+5 -1
View File
@@ -1612,7 +1612,11 @@ async fn fork_preserves_thread_instructions(
})
.await?;
test.thread_manager
.fork_prepared_thread(options, prepared)
.fork_prepared_thread(
options,
prepared,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await?
}
};
+35
View File
@@ -8,6 +8,7 @@ use codex_history::InitialHistory;
use codex_history::ResumedHistory;
use codex_history::RolloutItem;
use codex_protocol::ThreadId;
use codex_protocol::error::CodexErrorDetails;
use codex_protocol::items::TurnItem;
use codex_protocol::mcp::ClientMcpExtensions;
use codex_protocol::protocol::EventMsg;
@@ -17,6 +18,8 @@ use codex_protocol::protocol::ThreadSettingsOverrides;
use codex_protocol::protocol::ThreadSettingsSnapshot;
use codex_protocol::user_input::UserInput;
use codex_thread_store::InMemoryThreadStore;
use codex_thread_store::InheritedHistoryVisibility;
use codex_thread_store::PreparedFork;
use core_test_support::responses::ev_completed;
use core_test_support::responses::ev_response_created;
use core_test_support::responses::sse;
@@ -31,6 +34,38 @@ use wiremock::ResponseTemplate;
use wiremock::matchers::method;
use wiremock::matchers::path;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn prepared_fork_passes_inherited_history_visibility_to_store() -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));
let server = MockServer::start().await;
let test = test_codex().build_with_auto_env(&server).await?;
let prepared = PreparedFork::with_source_revalidation(
test.session_configured.thread_id,
/*history_base*/ None,
Arc::new(Vec::new()),
);
let result = test
.thread_manager
.fork_prepared_thread(
test.start_thread_options().await,
prepared,
InheritedHistoryVisibility::ModelContextOnly,
)
.await;
match result {
Err(error) => assert!(matches!(
error.details(),
CodexErrorDetails::UnsupportedOperation(message)
if message == "model_context_only_inherited_history is not supported yet"
)),
Ok(_) => anyhow::bail!("expected local thread store to reject hidden inherited history"),
}
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn ephemeral_fork_skips_stored_title_lookup() -> anyhow::Result<()> {
skip_if_no_network!(Ok(()));
@@ -131,6 +131,7 @@ async fn guardian_history_survives_restart_and_user_fork(
.fork_prepared_thread(
codex_core::StartThreadOptions::new(initial.config.clone()),
prepared,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await?
} else {
@@ -984,6 +984,7 @@ async fn standalone_fork_retains_inherited_user_instructions(
.fork_prepared_thread(
codex_core::StartThreadOptions::new(test.config.clone()),
prepared,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await?
} else {
@@ -248,7 +248,11 @@ async fn stored_fork_sender_evidence_matches_live_sender() -> Result<()> {
.insert(RestrictRootCapabilities);
let sender = root
.thread_manager
.fork_prepared_thread(options, prepared)
.fork_prepared_thread(
options,
prepared,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await?;
responses::mount_sse_once(
&server,
@@ -90,6 +90,7 @@ async fn compressed_shared_fork_resume_preserves_checkpoint_and_frozen_history()
.fork_prepared_thread(
codex_core::StartThreadOptions::new(test.config.clone()),
prepared,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await?;
turn(
@@ -434,6 +434,7 @@ async fn exercise_harness(server_uri: String) -> Result<()> {
..StartThreadOptions::new(child_config.clone())
},
prepared,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await?;
turn(&child.thread, "child-assertion").await?;
+5 -1
View File
@@ -3558,7 +3558,11 @@ async fn attached_side_chat_preserves_model_context_on_cold_resume() -> Result<(
resume_options.environments = options.environments.clone();
let child = test
.thread_manager
.fork_prepared_thread(options, prepared)
.fork_prepared_thread(
options,
prepared,
codex_thread_store::InheritedHistoryVisibility::Full,
)
.await?;
child
.thread
@@ -66,6 +66,7 @@ async fn captures_originals_without_generated_context_or_later_appends() -> anyh
multi_agent_version: None,
history_mode: ThreadHistoryMode::Paginated,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
+2
View File
@@ -185,6 +185,7 @@ mod tests {
multi_agent_version: None,
history_mode: ThreadHistoryMode::Legacy,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -466,6 +467,7 @@ mod tests {
multi_agent_version: None,
history_mode,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
+1
View File
@@ -90,6 +90,7 @@ pub use types::DeleteThreadsParams;
pub use types::ExtraConfig;
pub use types::ForkBoundary;
pub use types::GitInfoPatch;
pub use types::InheritedHistoryVisibility;
pub use types::ItemPage;
pub use types::ItemSortKey;
pub use types::ListItemsParams;
@@ -16,6 +16,7 @@ use super::LocalThreadStore;
use super::create_thread;
use crate::AppendThreadItemsParams;
use crate::CreateThreadParams;
use crate::InheritedHistoryVisibility;
use crate::ResumeThreadParams;
use crate::ThreadStoreError;
use crate::ThreadStoreResult;
@@ -27,6 +28,11 @@ pub(super) async fn create_thread(
store: &LocalThreadStore,
params: CreateThreadParams,
) -> ThreadStoreResult<()> {
if params.inherited_history_visibility == InheritedHistoryVisibility::ModelContextOnly {
return Err(ThreadStoreError::Unsupported {
operation: "model_context_only_inherited_history",
});
}
let thread_id = params.thread_id;
let inherited_cursor = if params.initial_window_id.allocation().is_some()
&& let (Some(parent), Some(base)) = (params.forked_from_id, params.history_base)
+1
View File
@@ -2609,6 +2609,7 @@ mod tests {
multi_agent_version: None,
history_mode: ThreadHistoryMode::Legacy,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -656,6 +656,7 @@ fn create_thread_params(thread_id: ThreadId) -> CreateThreadParams {
multi_agent_version: None,
history_mode: ThreadHistoryMode::Legacy,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -367,6 +367,7 @@ async fn create_paginated_thread(store: &LocalThreadStore, thread_id: ThreadId)
multi_agent_version: None,
history_mode: ThreadHistoryMode::Paginated,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: Some(vec![store.config.codex_home.join("workspace").abs()]),
@@ -815,6 +815,7 @@ async fn paginated_realtime_items_materialize_separately_in_rollout_order() {
multi_agent_version: None,
history_mode: ThreadHistoryMode::Legacy,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -3167,6 +3168,7 @@ async fn create_paginated_subagent_thread(
multi_agent_version: None,
history_mode: ThreadHistoryMode::Paginated,
history_base,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
@@ -507,6 +507,7 @@ mod tests {
multi_agent_version: None,
history_mode: ThreadHistoryMode::Legacy,
history_base: None,
inherited_history_visibility: Default::default(),
subagent_history_start_ordinal: None,
initial_window_id: codex_protocol::ContextWindowId::new_uuid_v7(),
runtime_workspace_roots: None,
+14
View File
@@ -70,6 +70,17 @@ pub struct ThreadPersistenceMetadata {
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ExtraConfig {}
/// Controls whether history inherited from a fork's source thread is returned by `list_turns`
/// and `list_items`.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub enum InheritedHistoryVisibility {
/// Include inherited history in `list_turns` and `list_items`.
#[default]
Full,
/// Omit inherited history from `list_turns` and `list_items`.
ModelContextOnly,
}
/// Parameters required to create a persisted thread.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CreateThreadParams {
@@ -111,6 +122,9 @@ pub struct CreateThreadParams {
pub history_mode: ThreadHistoryMode,
/// Exclusive prefix of another paginated rollout inherited by this thread.
pub history_base: Option<HistoryPosition>,
/// Visibility of the history inherited through `history_base`.
#[serde(default)]
pub inherited_history_visibility: InheritedHistoryVisibility,
/// First rollout ordinal that belongs to this subagent's projected history.
pub subagent_history_start_ordinal: Option<u64>,
/// Initial context-window identity captured when the thread was created.