From 71cf244137e9a8e0dc1c47f9ccd374819106d581 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 25 Nov 2026 17:34:38 +0000 Subject: [PATCH] Avoid cloning thread metadata during rollout read repair (#63994) When the stored rollout path matches, compare the normalized working directory and computed archive timestamp with the stored values. Return early if both match. Otherwise, reuse the existing metadata to build the updated row. GitOrigin-RevId: 2c5d3e98851f2c8f72414bd688ccc99b2219adeb --- codex-rs/rollout/src/state_db.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/codex-rs/rollout/src/state_db.rs b/codex-rs/rollout/src/state_db.rs index efb49de592..deb09e7a56 100644 --- a/codex-rs/rollout/src/state_db.rs +++ b/codex-rs/rollout/src/state_db.rs @@ -580,21 +580,21 @@ pub async fn read_repair_rollout_path( return; } saw_existing_metadata = true; - let mut repaired = metadata.clone(); - repaired.rollout_path = rollout_path.to_path_buf(); - repaired.cwd = normalize_cwd_for_state_db(&repaired.cwd); - match archived_only { - Some(true) if repaired.archived_at.is_none() => { - repaired.archived_at = Some(repaired.updated_at); - } - Some(false) => { - repaired.archived_at = None; - } - Some(true) | None => {} - } - if repaired == metadata { + let cwd = normalize_cwd_for_state_db(&metadata.cwd); + let archived_at = match archived_only { + Some(true) => Some(metadata.archived_at.unwrap_or(metadata.updated_at)), + Some(false) => None, + None => metadata.archived_at, + }; + if cwd == metadata.cwd && archived_at == metadata.archived_at { return; } + let repaired = codex_state::ThreadMetadata { + rollout_path: rollout_path.to_path_buf(), + cwd, + archived_at, + ..metadata + }; warn!("state db discrepancy during read_repair_rollout_path: upsert_needed (fast path)"); if let Err(err) = ctx.upsert_thread(&repaired).await { warn!(