From 4496ba3fd5645af57779fc6a468c270a0b23cfb7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 11 Aug 2026 16:10:09 +0000 Subject: [PATCH] Use session metadata to validate thread history paths (#38033) ## What changed Validate a SQLite thread's rollout path by reading its `SessionMetaLine` and comparing the recorded thread ID directly. This avoids constructing a `StoredThread` solely to decide whether the path can supply the requested history. GitOrigin-RevId: 8eb1e329514cefc056e44ab4a76d58ff50314a97 --- codex-rs/thread-store/src/local/read_thread.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/codex-rs/thread-store/src/local/read_thread.rs b/codex-rs/thread-store/src/local/read_thread.rs index 548ce9d31a..d99ad6d42f 100644 --- a/codex-rs/thread-store/src/local/read_thread.rs +++ b/codex-rs/thread-store/src/local/read_thread.rs @@ -42,12 +42,8 @@ pub(super) async fn read_thread( metadata.rollout_path.as_path(), ))) && (!params.include_history - || sqlite_rollout_path_can_load_history_for_thread( - store, - &metadata.rollout_path, - thread_id, - ) - .await) + || sqlite_rollout_path_can_load_history_for_thread(&metadata.rollout_path, thread_id) + .await) { let metadata_sandbox_policy = metadata.sandbox_policy.clone(); let mut thread = stored_thread_from_sqlite_metadata(store, metadata).await?; @@ -101,7 +97,6 @@ pub(super) async fn read_thread( } async fn sqlite_rollout_path_can_load_history_for_thread( - store: &LocalThreadStore, path: &std::path::Path, thread_id: codex_protocol::ThreadId, ) -> bool { @@ -111,9 +106,9 @@ async fn sqlite_rollout_path_can_load_history_for_thread( // SQLite metadata can outlive a moved/recreated rollout path. When history is // requested, verify the path still resolves to the requested thread before // trusting it as the source replay. - read_thread_from_rollout_path(store, path.to_path_buf()) + read_session_meta_line(path) .await - .is_ok_and(|thread| thread.thread_id == thread_id) + .is_ok_and(|metadata| metadata.meta.id == thread_id) } pub(super) async fn read_thread_by_rollout_path(