From 985e59537dc6f509b6d422ed405ac40786c59fac Mon Sep 17 00:00:00 2001 From: anais Date: Mon, 22 Jun 2026 13:21:45 -0700 Subject: [PATCH] fix legacy thread metadata updates --- codex-rs/state/src/runtime/threads.rs | 43 ++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/codex-rs/state/src/runtime/threads.rs b/codex-rs/state/src/runtime/threads.rs index 1910f90294..3c0d473420 100644 --- a/codex-rs/state/src/runtime/threads.rs +++ b/codex-rs/state/src/runtime/threads.rs @@ -659,11 +659,13 @@ ON CONFLICT(id) DO NOTHING name: Option<&str>, ) -> anyhow::Result { let result = match name { - Some(name) => sqlx::query("UPDATE threads SET name = ? WHERE id = ?") - .bind(name) - .bind(thread_id.to_string()) - .execute(self.pool.as_ref()) - .await?, + Some(name) => sqlx::query( + "UPDATE threads SET title = CASE WHEN name IS NOT NULL AND title = name THEN '' ELSE title END, name = ? WHERE id = ?", + ) + .bind(name) + .bind(thread_id.to_string()) + .execute(self.pool.as_ref()) + .await?, None => sqlx::query( "UPDATE threads SET title = CASE WHEN name IS NOT NULL AND title = name THEN '' ELSE title END, name = '' WHERE id = ?", ) @@ -682,11 +684,11 @@ ON CONFLICT(id) DO NOTHING cwd: &Path, archive_state: crate::ThreadArchiveState, ) -> anyhow::Result { + let rollout_path = rollout_path.display().to_string(); + let cwd = cwd.display().to_string(); let mut builder = QueryBuilder::::new("UPDATE threads SET rollout_path = "); - builder.push_bind(rollout_path.display().to_string()); - builder - .push(", cwd = ") - .push_bind(cwd.display().to_string()); + builder.push_bind(rollout_path.clone()); + builder.push(", cwd = ").push_bind(cwd.clone()); match archive_state { crate::ThreadArchiveState::Preserve => {} crate::ThreadArchiveState::Active => { @@ -699,6 +701,21 @@ ON CONFLICT(id) DO NOTHING builder .push(" WHERE id = ") .push_bind(thread_id.to_string()); + builder + .push(" AND (rollout_path <> ") + .push_bind(rollout_path) + .push(" OR cwd <> ") + .push_bind(cwd); + match archive_state { + crate::ThreadArchiveState::Preserve => {} + crate::ThreadArchiveState::Active => { + builder.push(" OR archived <> 0 OR archived_at IS NOT NULL"); + } + crate::ThreadArchiveState::Archived => { + builder.push(" OR archived <> 1 OR archived_at IS NULL"); + } + } + builder.push(")"); let result = builder.build().execute(self.pool.as_ref()).await?; Ok(result.rows_affected() > 0) } @@ -898,8 +915,14 @@ ON CONFLICT(id) DO UPDATE SET reasoning_effort = excluded.reasoning_effort, cwd = excluded.cwd, cli_version = excluded.cli_version, + name = COALESCE( + threads.name, + CASE + WHEN threads.title <> '' AND threads.title <> excluded.title THEN threads.title + ELSE excluded.name + END + ), title = excluded.title, - name = COALESCE(threads.name, excluded.name), preview = COALESCE(NULLIF(excluded.preview, ''), threads.preview), sandbox_policy = excluded.sandbox_policy, approval_mode = excluded.approval_mode,