From 2eada6a0f2a22a41ff06933b0550690b475441eb Mon Sep 17 00:00:00 2001 From: anais Date: Tue, 23 Jun 2026 15:35:34 -0700 Subject: [PATCH] fix legacy thread name writes --- codex-rs/state/migrations/0040_threads_name.sql | 11 +++++++++++ codex-rs/state/src/runtime/threads.rs | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/codex-rs/state/migrations/0040_threads_name.sql b/codex-rs/state/migrations/0040_threads_name.sql index 9419e74302..d824591802 100644 --- a/codex-rs/state/migrations/0040_threads_name.sql +++ b/codex-rs/state/migrations/0040_threads_name.sql @@ -15,3 +15,14 @@ WHERE title <> '' UPDATE threads SET title_snapshot = title WHERE name_state = 'legacy_unknown'; + +CREATE TRIGGER threads_title_snapshot_after_insert +AFTER INSERT ON threads +WHEN NEW.title_snapshot = '' + AND NEW.title <> '' + AND NEW.title_state = 'legacy_unknown' +BEGIN + UPDATE threads + SET title_snapshot = NEW.title + WHERE id = NEW.id; +END; diff --git a/codex-rs/state/src/runtime/threads.rs b/codex-rs/state/src/runtime/threads.rs index 852f8bec13..08639b7017 100644 --- a/codex-rs/state/src/runtime/threads.rs +++ b/codex-rs/state/src/runtime/threads.rs @@ -946,13 +946,16 @@ ON CONFLICT(id) DO UPDATE SET cli_version = excluded.cli_version, name = CASE WHEN threads.title <> threads.title_snapshot THEN NULLIF(threads.title, '') - WHEN threads.name_state <> 'legacy_unknown' THEN threads.name + WHEN excluded.name_state = 'explicit' THEN excluded.name + WHEN excluded.name_state = 'cleared' THEN NULL + WHEN threads.name_state IN ('explicit', 'cleared') THEN threads.name WHEN excluded.name_state = 'legacy_unknown' THEN NULL ELSE excluded.name END, name_state = CASE WHEN threads.title <> threads.title_snapshot THEN CASE WHEN threads.title = '' THEN 'cleared' ELSE 'explicit' END - WHEN threads.name_state <> 'legacy_unknown' THEN threads.name_state + WHEN excluded.name_state IN ('explicit', 'cleared') THEN excluded.name_state + WHEN threads.name_state IN ('explicit', 'cleared') THEN threads.name_state WHEN excluded.name_state = 'legacy_unknown' THEN 'unnamed' ELSE excluded.name_state END,