pub struct InferenceSession<E: InferenceEngine> { /* private fields */ }Expand description
One live generation. Constructing it requires a LoadPermit, so a model
that has not passed the provenance gate (ADR-006) cannot reach the runtime —
the Conformist relationship is enforced in the type system.
Implementations§
Source§impl<E: InferenceEngine> InferenceSession<E>
impl<E: InferenceEngine> InferenceSession<E>
pub fn new( id: SessionId, config: SessionConfig, engine: E, permit: LoadPermit, ) -> Self
pub fn phase(&self) -> Phase
pub fn output(&self) -> &[Token] ⓘ
pub fn kv_len(&self) -> u32
pub fn config(&self) -> &SessionConfig
Sourcepub fn permit(&self) -> LoadPermit
pub fn permit(&self) -> LoadPermit
The load permit this session was constructed with — evidence the model passed the provenance gate (ADR-006).
Sourcepub fn drain_events(&mut self) -> Vec<EventEnvelope>
pub fn drain_events(&mut self) -> Vec<EventEnvelope>
Take the buffered domain events (a real build would stream these to the Telemetry subscriber).
Sourcepub fn load_prompt(&mut self, ports: &Ports, prompt: &[Token]) -> Result<()>
pub fn load_prompt(&mut self, ports: &Ports, prompt: &[Token]) -> Result<()>
Compress (optional) → prefill → build KV. Valid only from Initialized.
Sourcepub fn generate(&mut self, ports: &Ports, max_tokens: u32) -> Result<StopReason>
pub fn generate(&mut self, ports: &Ports, max_tokens: u32) -> Result<StopReason>
Run the decode loop until EOS or max_tokens, deriving the rollback
policy from the session’s device tier and safety mode (ADR-005/ADR-012).
Sourcepub fn generate_with_policy(
&mut self,
ports: &Ports,
max_tokens: u32,
policy: RollbackPolicy,
) -> Result<StopReason>
pub fn generate_with_policy( &mut self, ports: &Ports, max_tokens: u32, policy: RollbackPolicy, ) -> Result<StopReason>
The checkpointed-rollback safety control loop (ADR-012).
Every step preserves the invariant order grammar mask → safety adjust →
sample → commit (ADR-005). When a ChunkGuard
is wired and the policy enables guarding, the loop additionally captures a
checkpoint at each guard-verified-safe boundary, scores recent output
every guard_every tokens, and on a hard-threshold breach rolls the KV
cache and the committed output back to the last safe checkpoint —
banning the offending token through the grammar mask so the resumed
decode necessarily diverges. Rollbacks are bounded by max_rollbacks; on
exhaustion — or with no checkpoint (e.g. under memory pressure) — the loop
fails closed with a deterministic refusal (StopReason::Stopped).
Termination (EOS or max_tokens) is gated behind a mandatory final
guard check: the loop scores the trailing chunk before honouring either
stop condition, so no completion is ever returned unscored — including one
shorter than guard_every or whose unsafe tail ends in EOS. A final check
coincident with a cadence boundary is idempotent (re-scoring identical
output yields the same verdict).
Sourcepub fn consult_relay(
&mut self,
ports: &Ports,
query: &[Token],
) -> Result<Vec<Token>>
pub fn consult_relay( &mut self, ports: &Ports, query: &[Token], ) -> Result<Vec<Token>>
Consult the opt-in LAN relay. Hard-fails with EdgeError::AirGapViolation
unless hybrid_mode is enabled AND a relay is wired (ADR-004).