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.
105 lines
4.3 KiB
Lean4
105 lines
4.3 KiB
Lean4
/-!
|
||
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 |