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.
143 lines
4.2 KiB
Rust
143 lines
4.2 KiB
Rust
//! `vetta-infer-gw`: gateway & CLI (docs/ARCHITECTURE.md §2, §6).
|
||
//!
|
||
//! Engine → consumer wire emitters, matching `strata-ctl/src/engine/protocol.rs`
|
||
//! (`EngineLine::parse`) field for field:
|
||
//! `READY <ctx> [stop] [hold] [holdb]`, `INFO k=v …`, `T <id>`,
|
||
//! `PP <read> <total> [ms] [tok_s]`, `RESUME <n>`,
|
||
//! `DONE <gen> <prompt> <prompt_ms> <decode_ms> <finish> [extra…]`, `ERR <msg>`.
|
||
//!
|
||
//! `DONE` fields 1–5 are stable; the tail is kept raw by the consumer, so new
|
||
//! statistics can be appended without breaking it. Floats use Python-repr
|
||
//! spelling (`1.0`), which the consumer's parser expects.
|
||
|
||
pub mod session;
|
||
|
||
/// Python-repr float spelling (always a decimal point), as `strata-ctl` emits.
|
||
fn fmt_float(v: f64) -> String {
|
||
let s = format!("{v}");
|
||
if s.contains('.') {
|
||
s
|
||
} else {
|
||
format!("{s}.0")
|
||
}
|
||
}
|
||
|
||
/// First meaningful line after startup. `INFO` may precede it; the consumer
|
||
/// treats any other pre-`READY` line as startup chatter and `ERR` as refusal.
|
||
pub fn ready_line(max_context: u32, can_stop: bool, can_hold: bool, can_hold_batch: bool) -> String {
|
||
let mut s = format!("READY {max_context}");
|
||
if can_stop {
|
||
s.push_str(" stop");
|
||
}
|
||
if can_hold {
|
||
s.push_str(" hold");
|
||
}
|
||
if can_hold_batch {
|
||
s.push_str(" holdb");
|
||
}
|
||
s
|
||
}
|
||
|
||
pub fn info_line(pairs: &[(&str, &str)]) -> String {
|
||
let mut s = String::from("INFO");
|
||
for (k, v) in pairs {
|
||
s.push(' ');
|
||
s.push_str(k);
|
||
s.push('=');
|
||
s.push_str(v);
|
||
}
|
||
s
|
||
}
|
||
|
||
pub fn token_line(id: u32) -> String {
|
||
format!("T {id}")
|
||
}
|
||
|
||
/// Prefill progress, one per chunk. `tok_s_mean` is optional (4th field).
|
||
pub fn pp_line(read: u32, total: u32, ms: f64, tok_s_mean: Option<f64>) -> String {
|
||
match tok_s_mean {
|
||
Some(ts) => format!("PP {read} {total} {} {}", fmt_float(ms), fmt_float(ts)),
|
||
None => format!("PP {read} {total} {}", fmt_float(ms)),
|
||
}
|
||
}
|
||
|
||
pub fn resume_line(n: u32) -> String {
|
||
format!("RESUME {n}")
|
||
}
|
||
|
||
/// End of request. Fields 1–5 stable across versions; `extra` is the raw tail
|
||
/// (draft stats, cache hits, expert tiers, …) the consumer preserves verbatim.
|
||
pub fn done_line(
|
||
generated: u32,
|
||
prompt_tokens: u32,
|
||
prompt_ms: f64,
|
||
decode_ms: f64,
|
||
finish: &str,
|
||
extra: &[String],
|
||
) -> String {
|
||
let mut s = format!(
|
||
"DONE {generated} {prompt_tokens} {} {} {finish}",
|
||
fmt_float(prompt_ms),
|
||
fmt_float(decode_ms)
|
||
);
|
||
for e in extra {
|
||
s.push(' ');
|
||
s.push_str(e);
|
||
}
|
||
s
|
||
}
|
||
|
||
pub fn err_line(msg: &str) -> String {
|
||
format!("ERR {msg}")
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
|
||
#[test]
|
||
fn ready_flags_match_consumer_parse() {
|
||
assert_eq!(ready_line(262144, true, true, false), "READY 262144 stop hold");
|
||
assert_eq!(ready_line(4096, false, false, false), "READY 4096");
|
||
assert_eq!(ready_line(8192, true, false, true), "READY 8192 stop holdb");
|
||
}
|
||
|
||
#[test]
|
||
fn info_and_token_shapes() {
|
||
assert_eq!(
|
||
info_line(&[("version", "0.1.0"), ("expert_slots", "64")]),
|
||
"INFO version=0.1.0 expert_slots=64"
|
||
);
|
||
assert_eq!(token_line(151645), "T 151645");
|
||
assert_eq!(resume_line(512), "RESUME 512");
|
||
}
|
||
|
||
#[test]
|
||
fn prefill_progress_optional_mean() {
|
||
assert_eq!(pp_line(1024, 8192, 431.5, Some(2373.2)), "PP 1024 8192 431.5 2373.2");
|
||
assert_eq!(pp_line(128, 512, 90.0, None), "PP 128 512 90.0");
|
||
}
|
||
|
||
#[test]
|
||
fn done_five_stable_fields_and_raw_tail() {
|
||
assert_eq!(
|
||
done_line(41, 128, 90.5, 310.25, "stop", &[]),
|
||
"DONE 41 128 90.5 310.25 stop"
|
||
);
|
||
let extra: Vec<String> = ["7", "10", "55", "chunk=2048"].iter().map(|s| s.to_string()).collect();
|
||
assert_eq!(
|
||
done_line(41, 128, 90.5, 310.25, "length", &extra),
|
||
"DONE 41 128 90.5 310.25 length 7 10 55 chunk=2048"
|
||
);
|
||
// Integral floats keep the Python-repr ".0" spelling.
|
||
assert_eq!(done_line(1, 2, 3.0, 4.0, "stop", &[]), "DONE 1 2 3.0 4.0 stop");
|
||
}
|
||
|
||
#[test]
|
||
fn err_shape() {
|
||
assert_eq!(
|
||
err_line("GEN: unknown/unsupported key pen_from"),
|
||
"ERR GEN: unknown/unsupported key pen_from"
|
||
);
|
||
}
|
||
} |