Expand description
el-runtime — the Core: inference session lifecycle, the port traits that
the collaborator contexts plug into, and the decode-loop orchestrator
(ADR-001). Air-gap is structural (ADR-004): this crate has no network
dependency, and the only outbound seam is the opt-in ports::HybridRelay.
The decode step composes collaborators in a fixed, invariant order
(docs/ddd/domain-events.md): grammar mask → safety adjust → sample →
commit, so safety steering only ever operates over already-legal tokens.
Structs§
- Allow
AllMasker - Allow-all grammar — every token legal (used when no schema is registered).
- Anchor
Guard SafetyMode::Lightweightchunk guard — training-free token-anchor heuristics (no weights), theChunkGuardcounterpart ofLightweightFilter. Each pattern is an unsafe token-id n-gram; the guard addsper_hitmilli-units for every pattern that occurs as a contiguous subslice of the scored window, saturating atSafetyScore::MAX.- Checkpoint
- A safe-prefix snapshot for rollback (ADR-012). Stores only indices: rollback
truncates KV descriptors (
KvRegion::truncate) and never replays prefill, and the KV payload is never copied (ADR-002/ADR-003). - Checkpoint
Manager - A bounded ring of guard-verified safe-prefix checkpoints. Fixed memory: the
oldest checkpoint is dropped once
capis reached (ADR-003). Acapof0(ordisable) retains nothing — the loop then has no rollback target and fails closed on a breach. - Contrastive
Steerer SafetyMode::SecDecoding(or model-backedLightweight) steerer (ADR-013): a hard-ban layer applied every step plus contrastive soft steering from anExpertLogitssource applied only when the runtime supplies base logits (i.e. inside the early-token window). With no expert divergence it reduces to the hard-ban behaviour ofLightweightFilter; with no bans and a flat expert it is a no-op.- Identity
Compressor - Identity compressor — passes the prompt through unchanged.
- Inference
Session - 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. - Lightweight
Filter SafetyMode::Lightweight— a training-free blacklist filter (real). Banned tokens receive a very large negative logit so they cannot be sampled.- Logit
Adjustment - A vector subtracted from target logits to steer away from unsafe output. Sparse and integer (milli-logits) for deterministic, allocation-light steps.
- NoSafety
SafetyMode::Off— a no-op steerer.- Null
Engine - A trivial engine that emits EOS immediately after prefill. Lets you exercise the full session lifecycle without the Candle adapter (ADR-002 is the real engine). Not for production inference.
- Ports
- The collaborator ports bound to a session.
relayisNoneby default — air-gapped. - Rollback
Policy - Cadence and bounds for the checkpointed-rollback control loop (ADR-012), chosen per device tier so cost scales with the hardware budget (ADR-003).
- Safety
Mode Selector - Chooses the affordable mode for the device (ADR-005).
- Safety
Score - Risk score in milli-units,
0(safe) ..=1000(max). Integer for deterministic, float-free safety decisions (ADR-008).
Traits§
- Chunk
Guard - Scores recent generated output for risk (ADR-012 chunk guard). Reuses the active tier’s safety model; like every safety path it is deterministic and never touches the network (ADR-004).
- Expert
Logits - Safety-tuned next-token logits for the committed context, in integer milli-logits over the same vocabulary and tokenizer as the base generator (the ADR-012 shared-tokenizer invariant — the contrastive direction is only meaningful when base and expert share a token set). The expert weights are integrity-gated on load (ADR-006) by the adapter that constructs the implementor; like every safety path this is deterministic and never touches the network (ADR-004).
- Grammar
Masker - Grammar Constraint port (llguidance — context 4). Returns a per-token allow
mask of length
vocab;true= legal this step. - Hybrid
Relay - Opt-in LAN relay (ADR-004 HybridMode). Implementations MUST stay on the local network — there is no cloud variant.
- Inference
Engine - The inference engine adapter (
RuntimeAcl). Implemented for real by Candle in the excluded adapterel-engine-candle(ADR-002). - Prompt
Compressor - Prompt Compression port (LLMLingua-2 — context 2).
- Safety
Steerer - Per-step safety intervention. The runtime applies this after the grammar mask and before sampling.
Functions§
- contrastive_
adjustment - SafeDecoding-style contrastive adjustment (ADR-013): steer toward the
safety expert and away from the base —
final = base + α·(expert − base)— returned as additive milli-logit penalties consumed after the grammar mask, before sampling (the ADR-005 order is unchanged).