proofs: Lean 4 kernel-checked cache-restore correctness + prefix measure tool

proofs/auto_ckpt.lean: core-only Lean 4 model of the auto-ckpt / GEN 0 RESUME rule, kernel PASS (no sorryAx). Proves restore soundness (s <= lcp => first s tokens match, bit-identical recompute), branch invalidation (divergence at p => lcp <= p), and GEN 0 -> RESUME L. Backs the invariants in review/osservazioni-auto-ckpt.md.

examples/prefix_measure.rs: measures the real static prefix from live SQLite sessions via build_prefix_ids (no engine): ~1135 tokens/session, 575 tool_declare, ~589 shared cross-session. README Status documents both + the agreed next engine-side --auto-ckpt step. Suite 162 passed + 3 ignored, clippy/fmt clean.
This commit is contained in:
adm committed 2026-11-26 20:59:15 +01:00
1 parent db2dee2d2c
commit 862897fdbc
3 files changed
+280

No files matched your search

+14
View File
@@ -309,6 +309,20 @@ always sees a fresh notepad, no frozen header, no schema migration). The joint
`GEN 0 → RESUME` measurement on HIP (`examples/prewarm_bench.rs`) **passed**:
`cached_tokens == L == 385`, only the 35 new user tokens prefilled.
The cache-reuse correctness is also **formally verified**: `proofs/auto_ckpt.lean`
is a core-only Lean 4 model of the prefix-cache restore rule, kernel-checked
(`lean proofs/auto_ckpt.lean`, no `sorryAx`). It proves that selecting a checkpoint
at depth `s ≤ lcp` restores exactly the prompt's first `s` tokens (so recomputing
only the delta is bit-identical), that a divergence at `p` invalidates deeper
snapshots, and that a `GEN 0` over a prefix makes the next turn `RESUME` the whole
prefix. `examples/prefix_measure.rs` measures the real static prefix from the live
SQLite sessions (≈1135 tokens per session, 575 of them `tool_declare`; only ≈589
shared cross-session, since `SYSTEM_PROMPT` leads with the session identity). The
agreed next engine-side step is **automatic multi-level prefix checkpointing**
(`--auto-ckpt`: a per-slot snapshot pool + exact-`lcp` restore at every `GEN`,
opt-in and protocol-transparent). strata-ctl needs no change for it, provided the
pool retains the exact end-of-prefill checkpoint so `RESUME == L` still holds.
Not yet implemented (honest gaps): forced `tool_choice` (`required` / named function
returns a clear 400), multi-slot batching, logprobs / structured output, automatic
engine restart after a crash, a full SSRF guard against DNS rebinding, and the