Skip to main content

SamplerIdentity

Struct SamplerIdentity 

Source
pub struct SamplerIdentity { /* private fields */ }
Expand description

SESSION-RESUME SAMPLER IDENTITY (lane/session-resume-sampler-predicate-20260820; receipts research/spec-cache-20260818/SESSION-RESUME-PREDICATE.md).

The canonical form of a request’s sampler, for exactly one question: may this request resume a parked whole session that some OTHER request’s sampler shaped? The spec pool’s resume probe compared prompts and never samplers — that omission is how a filtered request inherited a draft graph captured unfiltered (memra-engine SampledGraphKey, lane/graph-s-key-exactness- 20260819). Keying the graph closed the exactness hole; it did not make cross-sampler resume SOUND, and the house posture in that situation is refuse-on-ambiguity with the refusal naming itself. This type is that predicate.

CANONICALIZATION, and why each rule is safe. Two encodings that name the same program must compare equal, or the predicate refuses resumes that cost nothing to allow:

  • temperature <= 0.0 is GREEDY — -1.0 and 0.0 are one program, so temp_bits is pinned to 0.0 in that regime and greedy carries the distinction. The greedy/sampled flip is itself a refusal: the two arms consume a parked next_pred/pending_tok differently and engage different captured draft graphs.
  • top_k == 0, top_p >= 1.0, min_p <= 0.0 are each the OFF sentinel (matching is_spec_sampling and SampledGraphKey::pure_temp), canonicalized so top_p 1.5 and top_p 1.0 do not look like a change.
  • Penalties are OFF as a group iff penalty_last_n == 0 or all three coefficients are neutral — the same pen_on predicate spec.rs computes. Off canonicalizes to the whole disabled tuple, so penalty_last_n 64 with neutral coefficients equals penalties absent.

Float fields compare by BITS after canonicalization (no NaN/-0.0 surprise), the same discipline SampledGraphKey uses.

seed IS carried and DELIBERATELY NOT COMPARED — see SamplerIdentity::mismatch.

Implementations§

Source§

impl SamplerIdentity

Source

pub fn of(cfg: &SamplerConfig) -> Self

Canonical identity of a sampler configuration.

Source

pub fn seed(&self) -> u64

The seed this identity was built from (logging/receipts only — never compared).

Source

pub fn mismatch(&self, parked: &Self) -> Option<&'static str>

The FIRST field on which self (an incoming request) differs from parked (the sampler that shaped a parked session), as a stable name for the refusal line — None when the two samplers are equivalent and the resume is legal. A refusal that does not say why is indistinguishable from an unwired mechanism, so the name is the deliverable, not a nicety.

Order is fixed and coarsest-first (regime before the field that only exists inside one regime), so the reported name is the most informative one rather than an artifact of struct layout.

seed IS NOT COMPARED, deliberately. It is the one sampler field a resume may change, for two reasons that are both mechanical:

  • The only parked state that BAKES the seed is the sampled draft graph, and SampledGraphKey already carries seed: a seed change drops the parked graph and recaptures. (memra-engine spec.rs; pinned by seed_alone_still_rekeys_the_draft_graph in that crate’s sampled_graph_key tests.)
  • The session’s persisted Philox counters (SpecSession::sctr/uctr) are counter-based: philox(seed', ctr) continued from another seed’s counter position is an independent stream, not a repeated one. Reproducibility is already scoped per (seed, session) rather than per seed (memra-server worker.rs, the spec-burst sampling note), so a changed seed costs nothing that same-seed resume was not already costing.

Comparing it would refuse essentially ALL sampled traffic: omitting seed on a serve request draws fresh per-request entropy, so every turn of every seed-omitting conversation would carry a “changed” seed. That is a cost with no soundness gain, which is exactly the trade this predicate exists to make explicitly rather than by accident.

Source

pub fn legacy_admits(&self, _parked: &Self) -> bool

THE PRE-LANE PREDICATE, RESTATED (teeth, not production). The spec pool-resume probe applied no sampler test at all — it compared prompts and nothing else — so every sampler pair was admitted. Restating it here keeps the refusal tests DECISIVE instead of tautological: the same pair that mismatch names must be admitted by this, or the test is asserting against a mechanism that never existed.

It is also what MEMRA_SPEC_RESUME_SAMPLER=0 selects at runtime (the rollback door and the A/B arm the cost measurement needs), so this function is the single definition of “legacy” for both the tests and the server.

Trait Implementations§

Source§

impl Clone for SamplerIdentity

Source§

fn clone(&self) -> SamplerIdentity

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SamplerIdentity

Source§

impl Debug for SamplerIdentity

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SamplerIdentity

Source§

impl PartialEq for SamplerIdentity

Source§

fn eq(&self, other: &SamplerIdentity) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SamplerIdentity

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.