diff --git a/codex-rs/rollout/src/recorder.rs b/codex-rs/rollout/src/recorder.rs index ad9f54a779..23b05b9def 100644 --- a/codex-rs/rollout/src/recorder.rs +++ b/codex-rs/rollout/src/recorder.rs @@ -48,6 +48,7 @@ use crate::default_client::originator; use crate::state_db; use crate::state_db::StateDbHandle; use codex_git_utils::collect_git_info; +use codex_git_utils::get_git_repo_root; use codex_protocol::protocol::GitInfo as ProtocolGitInfo; use codex_protocol::protocol::InitialHistory; use codex_protocol::protocol::ResumedHistory; @@ -1580,11 +1581,15 @@ async fn write_session_meta( session_meta: SessionMeta, cwd: &Path, ) -> std::io::Result<()> { - let git_info = collect_git_info(cwd).await.map(|info| ProtocolGitInfo { - commit_hash: info.commit_hash, - branch: info.branch, - repository_url: info.repository_url, - }); + let git_info = if get_git_repo_root(cwd).is_some() { + collect_git_info(cwd).await.map(|info| ProtocolGitInfo { + commit_hash: info.commit_hash, + branch: info.branch, + repository_url: info.repository_url, + }) + } else { + None + }; let session_meta_line = SessionMetaLine { meta: session_meta, git: git_info, diff --git a/codex-rs/thread-store/src/thread_metadata_sync.rs b/codex-rs/thread-store/src/thread_metadata_sync.rs index 38a1293a7b..e40ae64217 100644 --- a/codex-rs/thread-store/src/thread_metadata_sync.rs +++ b/codex-rs/thread-store/src/thread_metadata_sync.rs @@ -5,6 +5,7 @@ use chrono::DateTime; use chrono::NaiveDateTime; use chrono::Utc; use codex_git_utils::collect_git_info; +use codex_git_utils::get_git_repo_root; use codex_protocol::ThreadId; use codex_protocol::protocol::EventMsg; use codex_protocol::protocol::GitInfo; @@ -51,11 +52,15 @@ impl ThreadMetadataSync { pub(crate) async fn for_create(params: &CreateThreadParams) -> Self { let created_at = Utc::now(); let cwd = params.metadata.cwd.clone().unwrap_or_default(); - let git_info = collect_git_info(cwd.as_path()).await.map(|info| GitInfo { - commit_hash: info.commit_hash, - branch: info.branch, - repository_url: info.repository_url, - }); + let git_info = if get_git_repo_root(cwd.as_path()).is_some() { + collect_git_info(cwd.as_path()).await.map(|info| GitInfo { + commit_hash: info.commit_hash, + branch: info.branch, + repository_url: info.repository_url, + }) + } else { + None + }; let dynamic_tools = (!params.dynamic_tools.is_empty()).then(|| params.dynamic_tools.clone()); let update = ThreadMetadataPatch {