From 4cf7633db9db0fd3624b121da55deb2df2bfcd9d Mon Sep 17 00:00:00 2001 From: Joey Trasatti Date: Mon, 27 Apr 2026 11:38:42 -0700 Subject: [PATCH] [codex-backend] Apply git metadata overlay on list fallback --- codex-rs/rollout/src/recorder.rs | 11 +++++------ codex-rs/thread-store/src/local/helpers.rs | 4 ---- codex-rs/thread-store/src/local/read_thread.rs | 18 +++++++++--------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/codex-rs/rollout/src/recorder.rs b/codex-rs/rollout/src/recorder.rs index be0404e961..252a7717f4 100644 --- a/codex-rs/rollout/src/recorder.rs +++ b/codex-rs/rollout/src/recorder.rs @@ -552,12 +552,11 @@ impl RolloutRecorder { // If SQLite listing still fails, return the filesystem page rather than failing the list. tracing::error!("Falling back on rollout system"); tracing::warn!("state db discrepancy during list_threads_with_db_fallback: falling_back"); - Ok(page_from_filesystem_scan( - fs_page, - sort_direction, - page_size, - sort_key, - )) + let page = page_from_filesystem_scan(fs_page, sort_direction, page_size, sort_key); + Ok( + overlay_thread_item_metadata_from_state_db(exact_lookup_state_db_ctx.as_ref(), page) + .await, + ) } /// Find the newest recorded thread path, optionally filtering to a matching cwd. diff --git a/codex-rs/thread-store/src/local/helpers.rs b/codex-rs/thread-store/src/local/helpers.rs index a933cf326a..4e4794b258 100644 --- a/codex-rs/thread-store/src/local/helpers.rs +++ b/codex-rs/thread-store/src/local/helpers.rs @@ -178,10 +178,6 @@ fn git_info_from_fields(fields: ThreadGitInfoFields) -> Option { }) } -pub(super) fn git_info_from_metadata(metadata: &ThreadMetadata) -> Option { - git_info_from_fields(metadata.git_info_fields()) -} - pub(super) fn apply_metadata_git_info(thread: &mut StoredThread, metadata: &ThreadMetadata) { let mut git_info = git_info_fields_from_git_info(thread.git_info.as_ref()); git_info.overlay_non_null(&metadata.git_info_fields()); diff --git a/codex-rs/thread-store/src/local/read_thread.rs b/codex-rs/thread-store/src/local/read_thread.rs index 8c6b4489aa..1240a5dffc 100644 --- a/codex-rs/thread-store/src/local/read_thread.rs +++ b/codex-rs/thread-store/src/local/read_thread.rs @@ -14,7 +14,7 @@ use codex_state::ThreadMetadata; use super::LocalThreadStore; use super::helpers::apply_metadata_git_info; -use super::helpers::git_info_from_metadata; +use super::helpers::git_info_from_parts; use super::helpers::stored_thread_from_rollout_item; use crate::ReadThreadParams; use crate::StoredThread; @@ -86,7 +86,9 @@ pub(super) async fn read_thread_by_rollout_path( message: format!("thread {} is archived", thread.thread_id), }); } - apply_sqlite_git_info_if_present(store, &mut thread).await; + if let Some(metadata) = read_sqlite_metadata(store, thread.thread_id).await { + apply_metadata_git_info(&mut thread, &metadata); + } attach_history_if_requested(&mut thread, include_history).await?; Ok(thread) } @@ -206,12 +208,6 @@ async fn read_sqlite_metadata( .flatten() } -async fn apply_sqlite_git_info_if_present(store: &LocalThreadStore, thread: &mut StoredThread) { - if let Some(metadata) = read_sqlite_metadata(store, thread.thread_id).await { - apply_metadata_git_info(thread, &metadata); - } -} - async fn stored_thread_from_sqlite_metadata( store: &LocalThreadStore, metadata: ThreadMetadata, @@ -227,7 +223,11 @@ async fn stored_thread_from_sqlite_metadata( .await .ok() .and_then(|meta_line| meta_line.meta.forked_from_id); - let git_info = git_info_from_metadata(&metadata); + let git_info = git_info_from_parts( + metadata.git_sha.clone(), + metadata.git_branch.clone(), + metadata.git_origin_url.clone(), + ); StoredThread { thread_id: metadata.id, rollout_path: Some(metadata.rollout_path),