Repository navigation
feat: machine-checked cache-stability theorems via Z3 (route 4, #2149) - #2159
Conversation
Add the solver lane of #2149 as a model-specification (route 4) proof: - proof/spec/*.smt2: byte-level contract of outbound-body assembly (String theory over bytes; impure points modeled at the interface as free functions/free inputs per owner stance) plus nine obligations: T1 growth stability (f(H+[m]) vs f(H) share a prefix of depth D past the merge-anchor's stable content; two scenarios: anchor flip and stationary) proven UNSAT in refutation form, T2 ref non-reuse under the persisted monotone cursor (UNSAT), and mutation twins that MUST be found (stable-region byte rewrite below D; post-archive cursor reset reissuing the dead high number 5 = the documented #421 residual, model hui=3 creset=4 n3=4 n4=5). - tests/cache-theorem.test.ts: z3 driver (PATH CLI or python module; solver subtests skip individually when absent so the main suite stays green) with per-check timing, plus grounding subtests pinning each spec axiom to the real code it abstracts (esc algebra vs JSON string encoder, mktag vs indexToRef, allocation rules vs assignRefs/ allocateFreeRef). - .github/workflows/ci-theorem.yml: dedicated ubuntu-only theorem lane, pinned z3-solver==4.9.1.0, paths-filtered to the assembly surface. Pure test/proof surface: zero production code touched, kernel/** untouched, no config surface added, no behavior changes.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2206-pr.2159.77be896This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2159.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Reviewing now — interim status: Theorem lane is RED on CI (
Fix in progress on the PR branch (CLI trailer gets |
…ess there too (#2159) The spec files carry assertions only. detectSolver() prefers a z3 CLI on PATH, and the pinned z3-solver wheel bundles one, so CI took the CLI branch: 'z3 -smt2 <file>' executed no check command, printed no verdict, exited 0 — all 9 obligations reported 'error'. Append (check-sat) (and get-model after it for SAT checks) on the CLI path, parse z3's define-fun model output for the mutation-witness assertion on both paths.
t2.smt2 grounds the archive op in applyCompactionArchive and the cursor discipline in state.nextIndex carry-verbatim, both in src/session.ts; the paths filter missed that file, so changes there could bypass the lane.
[bot] 🏷 Review complete — CI 全绿(19/19),可合并(merge 由人执行)。本轮 review 抓到并修掉了 theorem lane 的红灯,结论如下。 结构化七问
验证证据
收工判定:theorem lane 已由红转绿且见证可见,方向(route 4)维持 owner 已批方案不变,两个小修均已标注 commit 推入分支。请 owner 合并:#2159 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.37-master.bbb6859 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2149
What this is
The solver lane of #2149, delivered as route 4 (model specification) per the approved plan: the two theorems are proven by Z3 over a byte-level contract of outbound-body assembly, with two mechanisms keeping the contract honest against the code — grounding tests pinning each spec axiom to the real code it abstracts, and the already-merged #2144 billing suite as whole-body code↔spec sync evidence. Routes 1–3 (compiling the real pipeline into a symex front-end) remain available as follow-up hardening if the owner wants them after this lands.
Theorems (9 solver obligations, all < 1s total)
T1 — growth stability. For history H, message m, pipeline f: f(H+[m]) and f(H) share a byte prefix of depth D = envelope head + stable content of the merge-anchor element; everything past D may differ only at the existentially quantified declared carrier positions (MERGE family: nudge/hint text on the last-user turn; TAIL family: optional trailing element — imgNote / chain-checkpoint stamp with its clock impurity modeled x-at-interface / fresh-turn fallback). Two scenarios instantiated: merge anchor flips to the new message (S1) and stays stationary (S2). Proven UNSAT in refutation form (explicit shared-prefix term P, blen(P)=D — a decidable strengthening of the quantified ∃p≥D form, which Z3's string solver returns unknown on).
T2 — ref monotonicity / id-never-reused. Bounded 4-step session over the real allocator rules (kernel/src/refs.ts assignRefs/allocateFreeRef; archive op = the #421 operation): initial live map {a→5, b→2, c→3}, cursor 6, the session high (5) dies, archive prunes, two appends allocate.
t2-host: UNSAT — with the persisted monotone cursor (state.nextIndex carried verbatim), no allocation reissues an ever-issued number even though the high died. Machine-checked form of the host duty behind the kernel id-never-reused contract.t2-mutation: SAT — if the cursor is instead recomputed from the pruned map after the archive (highestUsedIndex+1, the documented fix: archive blocks across omp native compaction instead of silently deactivating them (#395) #421 residual), the solver produces exactly the countermodel hui=3 creset=4 n3=4 n4=5: dead high 5 reissued. The residual window is characterized exactly: it opens iff the cursor drops below a dead ever-issued number.Mutation discipline (acceptance criterion: proofs are not vacuous). Each theorem has a mutation twin injecting a stable-region defect (same-length content rewrite strictly below D in T1; the cursor reset in T2); the solver MUST find each as a counterexample within budget or the proof is treated as broken.
Files
proof/spec/*.smt2(11 files) — the contract + obligations; dialect notes and trust-boundary statement inproof/README.md(read this first).tests/cache-theorem.test.ts— z3 driver (PATH CLI or python module; solver subtests skip individually when absent so the main suite stays green on windows/no-z3 boxes) with per-check timing report, plus[grounding:*]subtests pinning esc algebra → JSON string encoder (200 randomized BMP pairs), mktag → indexToRef (200k round-trips), allocation rules → assignRefs/allocateFreeRef (incl. gap-below-cursor and BLOCKED-free cases)..github/workflows/ci-theorem.yml— dedicated ubuntu-only lane, pinned z3-solver==4.9.1.0, paths-filtered to the assembly surface (src/loop/, wire-body, system-anchor, chain-checkpoint, image-note, server, fake-completion, degenerate-retry, kernel rebuild/refs/render-refs/segment/block-map/ccr, proof/). ci.yml untouched.Verification
kernel/**untouched (read-only for grounding), no config surface added, no behavior changes.