From d93909a939e40c3c1031f5a713bacad8c0d9afe6 Mon Sep 17 00:00:00 2001 From: Keyan Zhang <2268452+keyz@users.noreply.github.com> Date: Tue, 22 Sep 2026 18:45:22 +0000 Subject: [PATCH] Skip stored title lookups for ephemeral forks (#47342) ## What changed Skip the thread store title lookup when initializing an ephemeral fork, leaving its thread name unset. ## Testing Add a regression test that forks an ephemeral thread from history and verifies that the in-memory thread store's `read_thread` count does not increase. GitOrigin-RevId: 81180c4a836c932584d2cb94c0816eae33b04af3 --- codex-rs/core/src/session/session.rs | 18 ++++++++----- codex-rs/core/tests/suite/fork_thread.rs | 32 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/codex-rs/core/src/session/session.rs b/codex-rs/core/src/session/session.rs index 917acf1577..cc52c2bf93 100644 --- a/codex-rs/core/src/session/session.rs +++ b/codex-rs/core/src/session/session.rs @@ -1432,12 +1432,18 @@ impl Session { "session_init.plugin_skill_warmup", otel.name = "session_init.plugin_skill_warmup", )); - let thread_name_lookup = - thread_title_from_thread_store(live_thread.as_ref(), &thread_store, thread_id) - .instrument(info_span!( - "session_init.thread_name_lookup", - otel.name = "session_init.thread_name_lookup", - )); + let thread_name_lookup = async { + if config.ephemeral && matches!(&initial_history, InitialHistory::Forked(_)) { + None + } else { + thread_title_from_thread_store(live_thread.as_ref(), &thread_store, thread_id) + .await + } + } + .instrument(info_span!( + "session_init.thread_name_lookup", + otel.name = "session_init.thread_name_lookup", + )); let (instruction_refresh, plugin_skill_errors, thread_name) = tokio::join!( agents_md_manager.refresh(config.as_ref(), &resolved_environments), plugin_skill_warmup, diff --git a/codex-rs/core/tests/suite/fork_thread.rs b/codex-rs/core/tests/suite/fork_thread.rs index a51aa68d07..078bfd311b 100644 --- a/codex-rs/core/tests/suite/fork_thread.rs +++ b/codex-rs/core/tests/suite/fork_thread.rs @@ -16,6 +16,7 @@ use codex_protocol::protocol::ThreadSettingsAppliedEvent; use codex_protocol::protocol::ThreadSettingsOverrides; use codex_protocol::protocol::ThreadSettingsSnapshot; use codex_protocol::user_input::UserInput; +use codex_thread_store::InMemoryThreadStore; use core_test_support::responses::ev_completed; use core_test_support::responses::ev_response_created; use core_test_support::responses::sse; @@ -23,12 +24,43 @@ use core_test_support::skip_if_no_network; use core_test_support::submit_thread_settings; use core_test_support::test_codex::test_codex; use core_test_support::wait_for_event; +use pretty_assertions::assert_eq; use wiremock::Mock; use wiremock::MockServer; use wiremock::ResponseTemplate; use wiremock::matchers::method; use wiremock::matchers::path; +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn ephemeral_fork_skips_stored_title_lookup() -> anyhow::Result<()> { + skip_if_no_network!(Ok(())); + + let server = MockServer::start().await; + let store = Arc::new(InMemoryThreadStore::default()); + let test = test_codex() + .with_thread_store(store.clone()) + .build_with_auto_env(&server) + .await?; + let mut config = test.config.clone(); + config.ephemeral = true; + let reads_before = store.calls().await.read_thread; + + test.thread_manager + .fork_thread_from_history( + ForkSnapshot::Interrupted, + codex_core::StartThreadOptions::new(config), + InitialHistory::Resumed(ResumedHistory { + conversation_id: test.session_configured.thread_id, + history: Arc::new(Vec::new()), + rollout_path: None, + }), + ) + .await?; + + assert_eq!(store.calls().await.read_thread, reads_before); + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn fork_thread_twice_drops_to_first_message() { skip_if_no_network!();