[ABI][KN][LD][CC][RT][LAB][SP][NT][TM][GW][Proofs][Docs] M0.5: realign workspace to vetta-infer-* microkernel architecture
Dissolve the M0 crates (core/io/proto/telemetry/hip/cli) into the approved service layout abi/kn/ld/cc/rt/lab/sp/nt/tm/gw (docs/ARCHITECTURE.md). - kn: Lean-verified control bus + service registry (bus_lifecycle.lean, 14 thms) and SlabRing/UMA broker; rt: PrefixState + hybrid checkpoint pool. - sp: faithful throughput-aware Adaptive-K port of clover_policy.h (cooldowns, probes, throughput guards) with scenario parity tests. - gw: strata-ctl-compatible wire emitters + serve session FSM (serve_session.lean, 10 thms); abi::serve accepts image= (Vision delta closed). - abi: pure contracts, checked JSON/VTC1/GEN parsers, zero-alloc sampler. - ld/cc: checked safetensors reader + write-once VTC1 writer / O_RDONLY reader. - tm: lock-free telemetry; nt: LyraRpc; lab shares the rt executor core. - Docs: ARCHITECTURE.md decision-complete spec (MoE-only scope, .vbundle, .vplan->CompiledPlan, wire contract, migration map); AGENTS.md Lean rule + tandem/review workflow. Verified live: cargo test --workspace -D warnings = 46/46 PASS; lean proofs = 34 theorems (slab_ring_dma 10, bus_lifecycle 14, serve_session 10), 0 sorryAx, standard axioms only; vetta-infer info on Inkling = 1244 tensors, 18.18 GiB, checked bounds.
This commit is contained in:
1 parent
63b1668a92
commit
7b50f1c07c
49 files changed
+3211
-1208
No files matched your search
@@ -0,0 +1,165 @@
|
||||
/-!
|
||||
proofs/bus_lifecycle.lean
|
||||
Formal contracts for the `vetta-infer-kn` microkernel (docs/ARCHITECTURE.md §2, §8):
|
||||
1. Service lifecycle: STOP/cancellation always drains to a terminal state,
|
||||
never resurrects, never skips the draining phase.
|
||||
2. Registry two-phase commit: a prepared id is fresh, a failed allocation
|
||||
leaves zero ghost entries, commit only adds the prepared entry.
|
||||
3. Bus delivery: messages are deliverable only to a `running` service.
|
||||
|
||||
Zero `sorryAx`; checked with `lean proofs/bus_lifecycle.lean`.
|
||||
-/
|
||||
|
||||
namespace Vetta.Proofs.Bus
|
||||
|
||||
-- ============================================================================
|
||||
-- 1. Service Lifecycle State Machine
|
||||
-- ============================================================================
|
||||
|
||||
/-- Lifecycle of one registered service. `stopping` = STOP issued, draining
|
||||
in-flight work; the service must reach `stopped` via an explicit drain ack. -/
|
||||
inductive SvcState where
|
||||
| registered -- entry committed, not yet started
|
||||
| running -- accepting bus messages
|
||||
| stopping -- STOP issued, draining (no new work accepted)
|
||||
| stopped -- terminal: resources released
|
||||
deriving DecidableEq, Repr
|
||||
|
||||
/-- Legal single-service transitions (mirrors `vetta_infer_kn::registry`). -/
|
||||
inductive SvcStep : SvcState → SvcState → Prop where
|
||||
| start : SvcStep .registered .running
|
||||
| stop : SvcStep .running .stopping
|
||||
| drain : SvcStep .stopping .stopped
|
||||
| cancelReady : SvcStep .registered .stopped -- cancelled before start
|
||||
|
||||
/-- Reflexive-transitive closure of `SvcStep`. -/
|
||||
inductive Steps : SvcState → SvcState → Prop where
|
||||
| refl (s : SvcState) : Steps s s
|
||||
| tail {s s' s'' : SvcState} : SvcStep s s' → Steps s' s'' → Steps s s''
|
||||
|
||||
/-- Theorem 1: `stopped` is terminal — no transition ever leaves it. -/
|
||||
theorem stopped_terminal {s : SvcState} : ¬ SvcStep .stopped s := by
|
||||
intro h; cases h
|
||||
|
||||
/-- Theorem 2: a draining service can never go back to `running`. -/
|
||||
theorem no_resurrect_stopping : ¬ SvcStep .stopping .running := by
|
||||
intro h; cases h
|
||||
|
||||
/-- Theorem 3: a stopped service can never go back to `running`. -/
|
||||
theorem no_resurrect_stopped : ¬ SvcStep .stopped .running := by
|
||||
intro h; cases h
|
||||
|
||||
/-- Theorem 4: `running` cannot jump straight to `stopped`: the drain phase
|
||||
is mandatory (in-flight work is always observed before release). -/
|
||||
theorem no_skip_drain : ¬ SvcStep .running .stopped := by
|
||||
intro h; cases h
|
||||
|
||||
/-- Theorem 5: entering `stopping` is only possible from `running`
|
||||
(STOP is only meaningful on a live service). -/
|
||||
theorem stop_only_from_running {s : SvcState} (h : SvcStep s .stopping) :
|
||||
s = .running := by
|
||||
cases h; rfl
|
||||
|
||||
/-- Theorem 6: leaving `stopping` can only land in `stopped` (drain ack). -/
|
||||
theorem drain_only_to_stopped {s : SvcState} (h : SvcStep .stopping s) :
|
||||
s = .stopped := by
|
||||
cases h; rfl
|
||||
|
||||
/-- Theorem 7 (progress): a running service always has a path to `stopped`. -/
|
||||
theorem running_reaches_stopped : Steps .running .stopped :=
|
||||
.tail .stop (.tail .drain (.refl .stopped))
|
||||
|
||||
/-- Theorem 8 (progress): a registered-but-not-started service can be
|
||||
cancelled to `stopped` without ever running. -/
|
||||
theorem registered_reaches_stopped : Steps .registered .stopped :=
|
||||
.tail .cancelReady (.refl .stopped)
|
||||
|
||||
/-- Theorem 9 (progress): a draining service always has a path to `stopped`. -/
|
||||
theorem stopping_reaches_stopped : Steps .stopping .stopped :=
|
||||
.tail .drain (.refl .stopped)
|
||||
|
||||
-- ============================================================================
|
||||
-- 2. Registry Two-Phase Commit (no ghost entries, fresh ids)
|
||||
-- ============================================================================
|
||||
|
||||
/-- Committed registry entries only. A pending (prepared but not committed)
|
||||
entry lives OUTSIDE this structure, so it is unobservable by construction. -/
|
||||
structure Registry where
|
||||
entries : List (Nat × SvcState)
|
||||
nextId : Nat
|
||||
|
||||
/-- Well-formedness: every committed id was handed out before `nextId`. -/
|
||||
def Registry.wf (r : Registry) : Prop :=
|
||||
∀ p ∈ r.entries, p.1 < r.nextId
|
||||
|
||||
/-- Phase 1 (pure peek): the candidate id for a new service. No mutation. -/
|
||||
def prepare (r : Registry) : Nat := r.nextId
|
||||
|
||||
/-- Phase 2: commit the prepared entry. Called ONLY after the service's
|
||||
resources were successfully allocated (mirrors `commit_slot` discipline). -/
|
||||
def commit (r : Registry) : Registry :=
|
||||
{ entries := (r.nextId, .registered) :: r.entries, nextId := r.nextId + 1 }
|
||||
|
||||
/-- Theorem 10: the prepared id is fresh — it never collides with a committed entry. -/
|
||||
theorem prepare_id_fresh (r : Registry) (hwf : r.wf) :
|
||||
∀ p ∈ r.entries, p.1 ≠ prepare r := by
|
||||
intro p hp heq
|
||||
have hlt := hwf p hp
|
||||
simp [prepare] at heq
|
||||
omega
|
||||
|
||||
/-- Theorem 11: committing the prepared entry preserves well-formedness. -/
|
||||
theorem commit_preserves_wf (r : Registry) (hwf : r.wf) : (commit r).wf := by
|
||||
intro p hp
|
||||
simp [commit] at hp ⊢
|
||||
rcases hp with ⟨rfl, rfl⟩ | hp
|
||||
· omega
|
||||
· have := hwf p hp
|
||||
omega
|
||||
|
||||
/-- Theorem 12: commit only ADDS the prepared entry; every pre-existing entry
|
||||
is preserved untouched (a failed allocation that never calls `commit`
|
||||
leaves the registry bit-identical — no half-committed state is observable). -/
|
||||
theorem commit_only_adds (r : Registry) :
|
||||
(commit r).entries = (r.nextId, .registered) :: r.entries := rfl
|
||||
|
||||
-- ============================================================================
|
||||
-- 3. Bus Delivery Rules
|
||||
-- ============================================================================
|
||||
|
||||
/-- A bus message is deliverable only to a running service. -/
|
||||
def deliverable : SvcState → Bool
|
||||
| .running => true
|
||||
| _ => false
|
||||
|
||||
/-- Theorem 13: deliverability implies `running` — no message ever reaches a
|
||||
registered, draining, or stopped service. -/
|
||||
theorem deliver_only_running {s : SvcState} (h : deliverable s = true) :
|
||||
s = .running := by
|
||||
cases s <;> simp [deliverable] at h ⊢
|
||||
|
||||
/-- Theorem 14: STOP itself is accepted only where delivery is legal,
|
||||
and it is exactly the transition into draining. -/
|
||||
theorem stop_is_delivery_gated {s s' : SvcState} (h : SvcStep s s')
|
||||
(hs : s' = .stopping) : deliverable s = true := by
|
||||
subst hs
|
||||
cases h
|
||||
rfl
|
||||
|
||||
-- Axiom audit (all theorems must rely only on standard core axioms, 0 sorryAx)
|
||||
#print axioms stopped_terminal
|
||||
#print axioms no_resurrect_stopping
|
||||
#print axioms no_resurrect_stopped
|
||||
#print axioms no_skip_drain
|
||||
#print axioms stop_only_from_running
|
||||
#print axioms drain_only_to_stopped
|
||||
#print axioms running_reaches_stopped
|
||||
#print axioms registered_reaches_stopped
|
||||
#print axioms stopping_reaches_stopped
|
||||
#print axioms prepare_id_fresh
|
||||
#print axioms commit_preserves_wf
|
||||
#print axioms commit_only_adds
|
||||
#print axioms deliver_only_running
|
||||
#print axioms stop_is_delivery_gated
|
||||
|
||||
end Vetta.Proofs.Bus
|
||||
@@ -0,0 +1,105 @@
|
||||
/-!
|
||||
proofs/serve_session.lean
|
||||
Formal contract for the `vetta-infer-gw` `--serve` request lifecycle
|
||||
(docs/ARCHITECTURE.md §6, consumer: strata-ctl/src/engine/supervisor.rs):
|
||||
1. STOP from any active phase always drains to a DONE (never hangs).
|
||||
2. `GEN 0` pre-warm reaches DONE without ever entering decode (no tokens).
|
||||
3. Tokens are emitted only while decoding; a draining request emits none.
|
||||
4. DONE is exited only to idle (one request cycle = one DONE).
|
||||
|
||||
Zero `sorryAx`; checked with `lean proofs/serve_session.lean`.
|
||||
-/
|
||||
|
||||
namespace Vetta.Proofs.Serve
|
||||
|
||||
/-- Per-request lifecycle on the engine side. `done` = DONE emitted, awaiting
|
||||
the next request; `stopping` = STOP received, draining in-flight work. -/
|
||||
inductive ReqState where
|
||||
| idle -- waiting for a command (prefix may be resident)
|
||||
| prefilling -- GEN accepted, processing prompt chunks (PP/RESUME)
|
||||
| decoding -- emitting T tokens
|
||||
| stopping -- STOP received, draining to DONE
|
||||
| done -- DONE emitted for this request
|
||||
deriving DecidableEq, Repr
|
||||
|
||||
/-- Legal transitions (mirrors `vetta_infer_gw::session`). -/
|
||||
inductive ReqStep : ReqState → ReqState → Prop where
|
||||
| gen : ReqStep .idle .prefilling
|
||||
| prefillComplete : ReqStep .prefilling .decoding -- max_new > 0
|
||||
| prewarm : ReqStep .prefilling .done -- max_new == 0: DONE immediately
|
||||
| finish : ReqStep .decoding .done -- stop / length / nonfinite
|
||||
| stopPrefill : ReqStep .prefilling .stopping
|
||||
| stopDecode : ReqStep .decoding .stopping
|
||||
| drain : ReqStep .stopping .done
|
||||
| nextRequest : ReqStep .done .idle
|
||||
|
||||
inductive Steps : ReqState → ReqState → Prop where
|
||||
| refl (s : ReqState) : Steps s s
|
||||
| tail {s s' s'' : ReqState} : ReqStep s s' → Steps s' s'' → Steps s s''
|
||||
|
||||
/-- Theorem 1: STOP is only meaningful on an active request (prefill/decode). -/
|
||||
theorem stop_only_from_active {s : ReqState} (h : ReqStep s .stopping) :
|
||||
s = .prefilling ∨ s = .decoding := by
|
||||
cases h with
|
||||
| stopPrefill => exact Or.inl rfl
|
||||
| stopDecode => exact Or.inr rfl
|
||||
|
||||
/-- Theorem 2: STOP in idle is a no-op — it never enters draining. -/
|
||||
theorem no_stop_in_idle : ¬ ReqStep .idle .stopping := by
|
||||
intro h; cases h
|
||||
|
||||
/-- Theorem 3: leaving `stopping` can only land in `done` (the drain ack). -/
|
||||
theorem drain_only_to_done {s : ReqState} (h : ReqStep .stopping s) :
|
||||
s = .done := by
|
||||
cases h; rfl
|
||||
|
||||
/-- Theorem 4 (STOP guarantee): a draining request always reaches DONE. -/
|
||||
theorem stopping_reaches_done : Steps .stopping .done :=
|
||||
.tail .drain (.refl .done)
|
||||
|
||||
/-- Theorem 5: a prefilling request always has a path to DONE (pre-warm direct). -/
|
||||
theorem prefilling_reaches_done : Steps .prefilling .done :=
|
||||
.tail .prewarm (.refl .done)
|
||||
|
||||
/-- Theorem 6: a decoding request always has a path to DONE. -/
|
||||
theorem decoding_reaches_done : Steps .decoding .done :=
|
||||
.tail .finish (.refl .done)
|
||||
|
||||
/-- Theorem 7 (GEN 0 pre-warm): prefill can reach DONE directly, skipping decode. -/
|
||||
theorem prewarm_skips_decode : ReqStep .prefilling .done := .prewarm
|
||||
|
||||
/-- Theorem 8: DONE is exited only to idle — one request cycle yields one DONE. -/
|
||||
theorem done_only_to_idle {s : ReqState} (h : ReqStep .done s) :
|
||||
s = .idle := by
|
||||
cases h; rfl
|
||||
|
||||
/-- Token emission is enabled only while decoding. -/
|
||||
def emitsTokens : ReqState → Bool
|
||||
| .decoding => true
|
||||
| _ => false
|
||||
|
||||
/-- Theorem 9: tokens are emitted only in `decoding` — never while prefilling,
|
||||
draining, or done. Combined with Theorem 3, a STOP'd request emits no token
|
||||
between STOP and its DONE. -/
|
||||
theorem tokens_only_decoding {s : ReqState} (h : emitsTokens s = true) :
|
||||
s = .decoding := by
|
||||
cases s <;> simp [emitsTokens] at h ⊢
|
||||
|
||||
/-- Theorem 10: idle is re-entered only from done (clean request boundary). -/
|
||||
theorem idle_only_from_done {s : ReqState} (h : ReqStep s .idle) :
|
||||
s = .done := by
|
||||
cases h; rfl
|
||||
|
||||
-- Axiom audit (standard core axioms only, 0 sorryAx)
|
||||
#print axioms stop_only_from_active
|
||||
#print axioms no_stop_in_idle
|
||||
#print axioms drain_only_to_done
|
||||
#print axioms stopping_reaches_done
|
||||
#print axioms prefilling_reaches_done
|
||||
#print axioms decoding_reaches_done
|
||||
#print axioms prewarm_skips_decode
|
||||
#print axioms done_only_to_idle
|
||||
#print axioms tokens_only_decoding
|
||||
#print axioms idle_only_from_done
|
||||
|
||||
end Vetta.Proofs.Serve
|
||||
Reference in new issue
Block a user