diff --git a/codex-rs/thread-store/src/local/helpers.rs b/codex-rs/thread-store/src/local/helpers.rs index a10686acb5..c3def5e245 100644 --- a/codex-rs/thread-store/src/local/helpers.rs +++ b/codex-rs/thread-store/src/local/helpers.rs @@ -181,7 +181,6 @@ pub(super) fn permission_profile_to_metadata_value( pub(super) enum ThreadMetadataName { Explicit(String), Legacy(String), - Cleared, } pub(super) fn thread_metadata_name(metadata: &ThreadMetadata) -> Option { @@ -189,7 +188,7 @@ pub(super) fn thread_metadata_name(metadata: &ThreadMetadata) -> Option { return Some(ThreadMetadataName::Explicit(name.clone())); } - ThreadName::Unnamed => return Some(ThreadMetadataName::Cleared), + ThreadName::Unnamed => return None, ThreadName::LegacyUnknown => {} } @@ -208,7 +207,6 @@ pub(super) fn apply_thread_metadata_name(thread: &mut StoredThread, name: Thread match name { ThreadMetadataName::Explicit(name) => thread.name = Some(name), ThreadMetadataName::Legacy(name) => set_thread_name_from_title(thread, name), - ThreadMetadataName::Cleared => thread.name = None, } } diff --git a/codex-rs/thread-store/src/local/read_thread.rs b/codex-rs/thread-store/src/local/read_thread.rs index ec7de2361c..aa92408b5d 100644 --- a/codex-rs/thread-store/src/local/read_thread.rs +++ b/codex-rs/thread-store/src/local/read_thread.rs @@ -310,7 +310,6 @@ async fn stored_thread_from_sqlite_metadata( ) -> StoredThread { let name = match thread_metadata_name(&metadata) { Some(ThreadMetadataName::Explicit(name) | ThreadMetadataName::Legacy(name)) => Some(name), - Some(ThreadMetadataName::Cleared) => None, None => find_thread_name_by_id(store.config.codex_home.as_path(), &metadata.id) .await .ok() @@ -899,10 +898,28 @@ mod tests { #[tokio::test] async fn read_thread_uses_legacy_thread_name_when_sqlite_title_is_missing() { let home = TempDir::new().expect("temp dir"); - let store = LocalThreadStore::new(test_config(home.path()), /*state_db*/ None); + let config = test_config(home.path()); + let runtime = codex_state::StateRuntime::init( + config.sqlite_home.clone(), + config.default_model_provider_id.clone(), + ) + .await + .expect("state db should initialize"); + let store = LocalThreadStore::new(config.clone(), Some(runtime.clone())); let uuid = Uuid::from_u128(213); let thread_id = ThreadId::from_string(&uuid.to_string()).expect("valid thread id"); - write_session_file(home.path(), "2025-01-03T12-00-00", uuid).expect("session file"); + let rollout_path = + write_session_file(home.path(), "2025-01-03T12-00-00", uuid).expect("session file"); + let mut builder = + ThreadMetadataBuilder::new(thread_id, rollout_path, Utc::now(), SessionSource::Cli); + builder.model_provider = Some(config.default_model_provider_id.clone()); + builder.cwd = home.path().to_path_buf(); + let mut metadata = builder.build(config.default_model_provider_id.as_str()); + metadata.first_user_message = Some("Hello from user".to_string()); + runtime + .upsert_thread(&metadata) + .await + .expect("state db upsert should succeed"); codex_rollout::append_thread_name(home.path(), thread_id, "Legacy title") .await .expect("append legacy thread name");