From 94772d9fb6cd2d49bb7a96685a84c95345f419b1 Mon Sep 17 00:00:00 2001 From: "Adam Perry @ OpenAI" Date: Tue, 24 Nov 2026 00:32:10 +0000 Subject: [PATCH] Require thread stores to provide a session model ID store (#63525) ## What changed Make `ThreadStore::model_ids` return a `ThreadStoreResult` and require persistent backends to preserve alias assignments across restarts for the lifetime of the session. The local store returns an explicit error if its state database is uninitialized. The in-memory store returns its shared alias store, and the core test wrappers delegate to their underlying stores. GitOrigin-RevId: ca0d4bcf1c7dfa96f1a877b421760483b0cf3acc --- .../core/tests/suite/guardian_persistence_tests.rs | 5 +++++ codex-rs/core/tests/suite/multi_agent_restore_tests.rs | 5 +++++ codex-rs/core/tests/suite/pending_input_persistence.rs | 5 +++++ codex-rs/core/tests/suite/realtime_history_store.rs | 5 +++++ codex-rs/thread-store/src/in_memory.rs | 4 ++-- codex-rs/thread-store/src/local/mod.rs | 10 +++++++--- codex-rs/thread-store/src/store.rs | 7 +++---- 7 files changed, 32 insertions(+), 9 deletions(-) diff --git a/codex-rs/core/tests/suite/guardian_persistence_tests.rs b/codex-rs/core/tests/suite/guardian_persistence_tests.rs index f1eeee36b3..b48f2fbcf5 100644 --- a/codex-rs/core/tests/suite/guardian_persistence_tests.rs +++ b/codex-rs/core/tests/suite/guardian_persistence_tests.rs @@ -30,6 +30,7 @@ use codex_thread_store::StoredThreadHistory; use codex_thread_store::ThreadPage; use codex_thread_store::ThreadStore; use codex_thread_store::ThreadStoreFuture; +use codex_thread_store::ThreadStoreResult; use codex_thread_store::UpdateThreadMetadataParams; use core_test_support::responses; use core_test_support::streaming_sse::StreamingSseChunk; @@ -73,6 +74,10 @@ macro_rules! delegate_store_methods { } impl ThreadStore for GatedReviewerStore { + fn model_ids(&self) -> ThreadStoreResult> { + self.inner.model_ids() + } + fn as_any(&self) -> &dyn Any { self } diff --git a/codex-rs/core/tests/suite/multi_agent_restore_tests.rs b/codex-rs/core/tests/suite/multi_agent_restore_tests.rs index 0c9167da37..7c19369b86 100644 --- a/codex-rs/core/tests/suite/multi_agent_restore_tests.rs +++ b/codex-rs/core/tests/suite/multi_agent_restore_tests.rs @@ -33,6 +33,7 @@ use codex_thread_store::ThreadPage; use codex_thread_store::ThreadStore; use codex_thread_store::ThreadStoreError; use codex_thread_store::ThreadStoreFuture; +use codex_thread_store::ThreadStoreResult; use codex_thread_store::UpdateThreadMetadataParams; use core_test_support::responses::ev_completed; use core_test_support::responses::mount_sse_once_match; @@ -71,6 +72,10 @@ macro_rules! delegate_store_methods { } impl ThreadStore for GatedChildMetadataStore { + fn model_ids(&self) -> ThreadStoreResult> { + self.inner.model_ids() + } + fn as_any(&self) -> &dyn Any { self } diff --git a/codex-rs/core/tests/suite/pending_input_persistence.rs b/codex-rs/core/tests/suite/pending_input_persistence.rs index 277f32cce2..2fe00bca56 100644 --- a/codex-rs/core/tests/suite/pending_input_persistence.rs +++ b/codex-rs/core/tests/suite/pending_input_persistence.rs @@ -45,6 +45,7 @@ use codex_thread_store::StoredThreadHistory; use codex_thread_store::ThreadPage; use codex_thread_store::ThreadStore; use codex_thread_store::ThreadStoreFuture; +use codex_thread_store::ThreadStoreResult; use codex_thread_store::UpdateThreadMetadataParams; use core_test_support::responses; use core_test_support::streaming_sse::StreamingSseChunk; @@ -112,6 +113,10 @@ macro_rules! delegate_store_methods { } impl ThreadStore for GatedCheckpointStore { + fn model_ids(&self) -> ThreadStoreResult> { + self.inner.model_ids() + } + fn as_any(&self) -> &dyn Any { self } diff --git a/codex-rs/core/tests/suite/realtime_history_store.rs b/codex-rs/core/tests/suite/realtime_history_store.rs index 5add0f9dba..79a2fcbf88 100644 --- a/codex-rs/core/tests/suite/realtime_history_store.rs +++ b/codex-rs/core/tests/suite/realtime_history_store.rs @@ -22,6 +22,7 @@ use codex_thread_store::ThreadPage; use codex_thread_store::ThreadStore; use codex_thread_store::ThreadStoreError; use codex_thread_store::ThreadStoreFuture; +use codex_thread_store::ThreadStoreResult; use codex_thread_store::UpdateThreadMetadataParams; use std::any::Any; use std::collections::HashSet; @@ -104,6 +105,10 @@ macro_rules! delegate_store_methods { } impl ThreadStore for HostedClockStore { + fn model_ids(&self) -> ThreadStoreResult> { + self.inner.model_ids() + } + fn as_any(&self) -> &dyn Any { self } diff --git a/codex-rs/thread-store/src/in_memory.rs b/codex-rs/thread-store/src/in_memory.rs index de4a4844e5..befc4281bc 100644 --- a/codex-rs/thread-store/src/in_memory.rs +++ b/codex-rs/thread-store/src/in_memory.rs @@ -936,8 +936,8 @@ impl InMemoryThreadStore { } impl ThreadStore for InMemoryThreadStore { - fn model_ids(&self) -> Option> { - Some(self.model_ids.clone()) + fn model_ids(&self) -> ThreadStoreResult> { + Ok(self.model_ids.clone()) } fn as_any(&self) -> &dyn std::any::Any { diff --git a/codex-rs/thread-store/src/local/mod.rs b/codex-rs/thread-store/src/local/mod.rs index 44c67c94b5..6f725e4244 100644 --- a/codex-rs/thread-store/src/local/mod.rs +++ b/codex-rs/thread-store/src/local/mod.rs @@ -566,10 +566,14 @@ impl ThreadStore for LocalThreadStore { ) } - fn model_ids(&self) -> Option> { - self.state_db + fn model_ids(&self) -> ThreadStoreResult> { + let state_db = self + .state_db .clone() - .map(|db| db as Arc) + .ok_or_else(|| ThreadStoreError::Internal { + message: "session model IDs require an initialized state database".into(), + })?; + Ok(state_db) } fn default_history_mode(&self) -> ThreadHistoryMode { diff --git a/codex-rs/thread-store/src/store.rs b/codex-rs/thread-store/src/store.rs index 8b511d7b92..31eb852fc6 100644 --- a/codex-rs/thread-store/src/store.rs +++ b/codex-rs/thread-store/src/store.rs @@ -159,10 +159,9 @@ pub trait ThreadStore: Any + Send + Sync { /// Return this store as [`Any`] for implementation-owned escape hatches. fn as_any(&self) -> &dyn Any; - /// Returns the authority for session aliases when this backend supports them. - fn model_ids(&self) -> Option> { - None - } + /// Returns the shared store for session aliases. Persistent backends must preserve assignments + /// across restarts for the lifetime of the session. + fn model_ids(&self) -> ThreadStoreResult>; /// Returns the history mode to use when history does not carry a persisted mode. ///