Promote rollout path read to store trait

This commit is contained in:
Meta Vens 2026-05-17 23:47:07 +01:00
commit ef4f1e1a52
11 changed files with 66 additions and 65 deletions

View file

@ -24,6 +24,7 @@ pub use types::GitInfoPatch;
pub use types::ListThreadsParams;
pub use types::LoadThreadHistoryParams;
pub use types::OptionalStringPatch;
pub use types::ReadThreadByRolloutPathParams;
pub use types::ReadThreadParams;
pub use types::ResumeThreadRecorderParams;
pub use types::SortDirection;

View file

@ -16,6 +16,7 @@ use crate::ArchiveThreadParams;
use crate::CreateThreadParams;
use crate::ListThreadsParams;
use crate::LoadThreadHistoryParams;
use crate::ReadThreadByRolloutPathParams;
use crate::ReadThreadParams;
use crate::ResumeThreadRecorderParams;
use crate::StoredThread;
@ -38,30 +39,10 @@ impl LocalThreadStore {
pub fn new(config: RolloutConfig) -> Self {
Self { config }
}
/// Read a local rollout-backed thread by path.
pub async fn read_thread_by_rollout_path(
&self,
rollout_path: std::path::PathBuf,
include_archived: bool,
include_history: bool,
) -> ThreadStoreResult<StoredThread> {
read_thread::read_thread_by_rollout_path(
self,
rollout_path,
include_archived,
include_history,
)
.await
}
}
#[async_trait]
impl ThreadStore for LocalThreadStore {
fn as_any(&self) -> &dyn std::any::Any {
self
}
async fn create_thread(
&self,
_params: CreateThreadParams,
@ -91,6 +72,19 @@ impl ThreadStore for LocalThreadStore {
read_thread::read_thread(self, params).await
}
async fn read_thread_by_rollout_path(
&self,
params: ReadThreadByRolloutPathParams,
) -> ThreadStoreResult<StoredThread> {
read_thread::read_thread_by_rollout_path(
self,
params.rollout_path,
params.include_archived,
params.include_history,
)
.await
}
async fn list_threads(&self, params: ListThreadsParams) -> ThreadStoreResult<ThreadPage> {
list_threads::list_threads(self, params).await
}

View file

@ -393,14 +393,16 @@ mod tests {
.expect("path should be under codex home")
.to_path_buf();
let thread = store
.read_thread_by_rollout_path(
relative_path,
/*include_archived*/ false,
/*include_history*/ false,
)
.await
.expect("read thread by rollout path");
let thread = crate::ThreadStore::read_thread_by_rollout_path(
&store,
crate::ReadThreadByRolloutPathParams {
rollout_path: relative_path,
include_archived: false,
include_history: false,
},
)
.await
.expect("read thread by rollout path");
assert_eq!(thread.thread_id, thread_id);
assert_eq!(

View file

@ -8,6 +8,7 @@ use crate::ArchiveThreadParams;
use crate::CreateThreadParams;
use crate::ListThreadsParams;
use crate::LoadThreadHistoryParams;
use crate::ReadThreadByRolloutPathParams;
use crate::ReadThreadParams;
use crate::ResumeThreadRecorderParams;
use crate::StoredThread;
@ -48,10 +49,6 @@ impl RemoteThreadStore {
#[async_trait]
impl ThreadStore for RemoteThreadStore {
fn as_any(&self) -> &dyn std::any::Any {
self
}
async fn create_thread(
&self,
_params: CreateThreadParams,
@ -81,6 +78,15 @@ impl ThreadStore for RemoteThreadStore {
Err(not_implemented("read_thread"))
}
async fn read_thread_by_rollout_path(
&self,
_params: ReadThreadByRolloutPathParams,
) -> ThreadStoreResult<StoredThread> {
Err(ThreadStoreError::InvalidRequest {
message: "rollout path queries are only supported by local thread stores".to_string(),
})
}
async fn list_threads(&self, params: ListThreadsParams) -> ThreadStoreResult<ThreadPage> {
list_threads::list_threads(self, params).await
}

View file

@ -1,5 +1,3 @@
use std::any::Any;
use async_trait::async_trait;
use crate::AppendThreadItemsParams;
@ -7,6 +5,7 @@ use crate::ArchiveThreadParams;
use crate::CreateThreadParams;
use crate::ListThreadsParams;
use crate::LoadThreadHistoryParams;
use crate::ReadThreadByRolloutPathParams;
use crate::ReadThreadParams;
use crate::ResumeThreadRecorderParams;
use crate::StoredThread;
@ -18,11 +17,7 @@ use crate::UpdateThreadMetadataParams;
/// Storage-neutral thread persistence boundary.
#[async_trait]
pub trait ThreadStore: Any + Send + Sync {
/// Return this store as [`Any`] so callers at API boundaries can reject requests that only
/// make sense for a concrete store implementation.
fn as_any(&self) -> &dyn Any;
pub trait ThreadStore: Send + Sync {
/// Creates a new thread and returns a live recorder for future appends.
async fn create_thread(
&self,
@ -47,6 +42,12 @@ pub trait ThreadStore: Any + Send + Sync {
/// Reads a thread summary and optionally its persisted history.
async fn read_thread(&self, params: ReadThreadParams) -> ThreadStoreResult<StoredThread>;
/// Reads a thread summary by rollout path when the backing store exposes local paths.
async fn read_thread_by_rollout_path(
&self,
params: ReadThreadByRolloutPathParams,
) -> ThreadStoreResult<StoredThread>;
/// Lists stored threads matching the supplied filters.
async fn list_threads(&self, params: ListThreadsParams) -> ThreadStoreResult<ThreadPage>;

View file

@ -92,6 +92,17 @@ pub struct ReadThreadParams {
pub include_history: bool,
}
/// Parameters for reading a thread summary by local rollout path.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ReadThreadByRolloutPathParams {
/// Rollout file path to read.
pub rollout_path: PathBuf,
/// Whether archived threads are eligible.
pub include_archived: bool,
/// Whether persisted rollout items should be included in the response.
pub include_history: bool,
}
/// The sort key to use when listing stored threads.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum ThreadSortKey {