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
This commit is contained in:
Adam Perry @ OpenAI
2026-11-24 03:55:05 +00:00
committed by copyberry
parent 98835f5eba
commit 94772d9fb6
7 changed files with 32 additions and 9 deletions
@@ -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<Arc<dyn codex_state::SessionModelIdStore>> {
self.inner.model_ids()
}
fn as_any(&self) -> &dyn Any {
self
}
@@ -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<Arc<dyn codex_state::SessionModelIdStore>> {
self.inner.model_ids()
}
fn as_any(&self) -> &dyn Any {
self
}
@@ -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<Arc<dyn codex_state::SessionModelIdStore>> {
self.inner.model_ids()
}
fn as_any(&self) -> &dyn Any {
self
}
@@ -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<Arc<dyn codex_state::SessionModelIdStore>> {
self.inner.model_ids()
}
fn as_any(&self) -> &dyn Any {
self
}
+2 -2
View File
@@ -936,8 +936,8 @@ impl InMemoryThreadStore {
}
impl ThreadStore for InMemoryThreadStore {
fn model_ids(&self) -> Option<Arc<dyn codex_state::SessionModelIdStore>> {
Some(self.model_ids.clone())
fn model_ids(&self) -> ThreadStoreResult<Arc<dyn codex_state::SessionModelIdStore>> {
Ok(self.model_ids.clone())
}
fn as_any(&self) -> &dyn std::any::Any {
+7 -3
View File
@@ -566,10 +566,14 @@ impl ThreadStore for LocalThreadStore {
)
}
fn model_ids(&self) -> Option<Arc<dyn codex_state::SessionModelIdStore>> {
self.state_db
fn model_ids(&self) -> ThreadStoreResult<Arc<dyn codex_state::SessionModelIdStore>> {
let state_db = self
.state_db
.clone()
.map(|db| db as Arc<dyn codex_state::SessionModelIdStore>)
.ok_or_else(|| ThreadStoreError::Internal {
message: "session model IDs require an initialized state database".into(),
})?;
Ok(state_db)
}
fn default_history_mode(&self) -> ThreadHistoryMode {
+3 -4
View File
@@ -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<std::sync::Arc<dyn codex_state::SessionModelIdStore>> {
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<Arc<dyn codex_state::SessionModelIdStore>>;
/// Returns the history mode to use when history does not carry a persisted mode.
///