From 9ff072db8ae43d413c8d205ebf22b54b83c72cef Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Wed, 4 Nov 2026 17:42:07 +0000 Subject: [PATCH] Allow prepared forks to use source revalidation (#59468) ## What changed Add `PreparedFork::with_source_revalidation` for backends that revalidate the source when making the child's history reference durable, allowing the source reservation to be omitted. Rename the reservation-backed constructor to `with_source_reservation` and update the local thread store to use it, preserving its source deletion protection. GitOrigin-RevId: 659c23aaf83a3856eb628ea37f1b0a153d376516 --- .../thread-store/src/local/paginated_fork.rs | 2 +- codex-rs/thread-store/src/types.rs | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/codex-rs/thread-store/src/local/paginated_fork.rs b/codex-rs/thread-store/src/local/paginated_fork.rs index 018c9852e7..b76ec3e282 100644 --- a/codex-rs/thread-store/src/local/paginated_fork.rs +++ b/codex-rs/thread-store/src/local/paginated_fork.rs @@ -51,7 +51,7 @@ pub(super) async fn prepare( read_fork_history(store, thread_id, boundary, lineage) }) .await?; - Ok(PreparedFork::new( + Ok(PreparedFork::with_source_reservation( thread_id, history_base, Arc::new(model_context), diff --git a/codex-rs/thread-store/src/types.rs b/codex-rs/thread-store/src/types.rs index 024554c2b9..ebeff03117 100644 --- a/codex-rs/thread-store/src/types.rs +++ b/codex-rs/thread-store/src/types.rs @@ -244,13 +244,17 @@ pub struct PreparedFork { pub history_base: Option, /// Bounded model context selected by the requested fork boundary. pub model_context: Arc>, - /// Blocks source deletion until the child's history reference is durable. - _source_reservation: Box, + /// Prevents the source thread from being deleted until the child's history reference is + /// finalized. + /// + /// If absent, the backend must revalidate the prepared fork as part of finalizing that + /// reference. + _source_reservation: Option>, } impl PreparedFork { /// Creates a frozen fork snapshot while retaining a backend-owned source reservation. - pub fn new( + pub fn with_source_reservation( source_thread_id: ThreadId, history_base: Option, model_context: Arc>, @@ -260,7 +264,22 @@ impl PreparedFork { source_thread_id, history_base, model_context, - _source_reservation: Box::new(source_reservation), + _source_reservation: Some(Box::new(source_reservation)), + } + } + + /// Creates a frozen fork snapshot for a backend that revalidates the source while making the + /// child's history reference durable. + pub fn with_source_revalidation( + source_thread_id: ThreadId, + history_base: Option, + model_context: Arc>, + ) -> Self { + Self { + source_thread_id, + history_base, + model_context, + _source_reservation: None, } } }