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
This commit is contained in:
Owen Lin
2026-11-04 17:56:42 +00:00
committed by copyberry
parent ba057e4375
commit 9ff072db8a
2 changed files with 24 additions and 5 deletions
@@ -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),
+23 -4
View File
@@ -244,13 +244,17 @@ pub struct PreparedFork {
pub history_base: Option<HistoryPosition>,
/// Bounded model context selected by the requested fork boundary.
pub model_context: Arc<Vec<RolloutItem>>,
/// Blocks source deletion until the child's history reference is durable.
_source_reservation: Box<dyn std::fmt::Debug + Send>,
/// 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<Box<dyn std::fmt::Debug + Send>>,
}
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<HistoryPosition>,
model_context: Arc<Vec<RolloutItem>>,
@@ -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<HistoryPosition>,
model_context: Arc<Vec<RolloutItem>>,
) -> Self {
Self {
source_thread_id,
history_base,
model_context,
_source_reservation: None,
}
}
}