Skip to main content

ferrum_interfaces/model_executor/
prefix_capture.rs

1//! Optional interest in a future, exact completed prefix. This is not admission
2//! authority and does not reserve device capacity.
3
4use ferrum_types::{RequestId, TokenId};
5use std::{any::Any, fmt::Debug, time::Instant};
6
7#[derive(Debug, Clone, Copy)]
8pub struct PrefixCapturePlan {
9    pub boundary: usize,
10    /// Constraint on executed span lengths, not absolute token positions.
11    pub span: crate::vnext::CheckpointTokenSpanConstraint,
12}
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum PrefixCaptureStatus {
16    Pending,
17    Ready,
18    /// Cancellation, pressure, expiry, or an unsupported/overshot boundary.
19    /// The untouched follower may proceed through ordinary cold admission.
20    Unavailable,
21}
22
23/// Executor-owned interest in one source incarnation. Ready retains immutable
24/// checkpoint ownership independently of cache-index membership. Implementations
25/// must not retain the source merely to keep a cancelled computation alive.
26pub trait PrefixCaptureLease: Debug + Send + Sync {
27    fn boundary(&self) -> usize;
28    fn status(&self) -> PrefixCaptureStatus;
29    fn as_any(&self) -> &dyn Any;
30}
31
32#[derive(Debug, Clone, Copy)]
33pub struct PrefixCaptureRequest<'a> {
34    pub source_request_id: &'a RequestId,
35    pub source_tokens: &'a [TokenId],
36    pub maximum_sequence_tokens: usize,
37    pub boundary: usize,
38    pub expires_at: Instant,
39}
40
41/// Token lengths are only a boundary-planning hint. The caller must establish
42/// exact token equality; capture and restore independently validate full input
43/// and native source/target identity before making state available.
44#[derive(Debug, Clone, Copy)]
45pub struct PrefixCaptureBoundary<'a> {
46    pub processed_tokens: usize,
47    pub source_prompt_tokens: usize,
48    pub common_prefix_tokens: usize,
49    pub follower_prompt_tokens: &'a [usize],
50}