Skip to content

Add Lean KV model and trace conformance tooling - #8339

Draft
Amaury Chamayou (achamayou) wants to merge 16 commits into
mainfrom
achamayou-kv-verification-draft
Draft

Add Lean KV model and trace conformance tooling#8339
Amaury Chamayou (achamayou) wants to merge 16 commits into
mainfrom
achamayou-kv-verification-draft

Conversation

@achamayou

@achamayou Amaury Chamayou (achamayou) commented Sep 10, 2026

Copy link
Copy Markdown
Member

Summary

Add a Lean 4.33.1 model of single-node KV operations, checked guarantees, and strict replay of traces emitted by the KV unit tests and concurrent fuzzer. Covers multi-map current snapshots, per-map globally committed views, commit conflicts, compaction, and rollback. The Lean package uses the same pinned Mathlib and axiom-audit tooling as the disaster-recovery model; C++ trace capture remains disabled by default and introduces no normal-build dependency.

Review guide

Changed-line counts are against the PR base and include additions and deletions. Start with the public properties and the protocol definitions: these contain the claims, assumptions, state, and transitions that need semantic review.

Needs human review

Surface Changed lines Review focus
lean/kv/Kv/Properties.lean 276 (+276/-0) 37 public property statements and their hypotheses
lean/kv/Kv/Protocol/ 750 (+750/-0) Types, assumptions, executable transitions, invariants, and sequential reference
lean/kv/Kv/Trace.lean, lean/kv/Main.lean 298 (+298/-0) Strict trace decoding, replay, diagnostics, and CLI behavior
Lean tests and trust wiring 529 (+528/-1) Mathlib-generated import root, pinned manifest, external audit configuration, and focused checker tests
C++ trace instrumentation 1,007 (+1000/-7) Capture points, locking boundaries, lifecycle, and normal-build isolation
C++ trace and fuzzer workloads 1,958 (+1958/-0) Deterministic cases, concurrent programs, and coverage
Python conformance runner 189 (+189/-0) Generate traces, invoke Lean, enforce observed fuzzer coverage, and retain logs
Build, CI, and documentation 526 (+523/-3) Opt-in build wiring, unified Lean CI workflow, and user-facing integration
Lean documentation and recorded finding 506 (+506/-0) Contract, scope limits, and model provenance

Total requiring human review: 6,039 changed lines.

Machine-checked; no line-by-line proof review requested

Surface Changed lines Why it can be collapsed
lean/kv/Kv/Proofs/ 1,215 (+1215/-0) Proof implementations checked by the pinned Lean kernel; theorem statements and all definitions/assumptions remain in the human-review surfaces above

Only lean/kv/Kv/Proofs/ is marked linguist-generated, so GitHub collapses proof steps without hiding the protocol, assumptions, properties, checker, dependency pins, or audit configuration.

Shared Lean tooling

The KV package follows the existing disaster-recovery workflow:

  • Mathlib mk_all --check --lib Kv verifies that the generated Kv.lean root imports every library module.
  • The pinned axiom-audit lint driver audits every declaration under Kv; 1,516 declarations currently use only propext, Classical.choice, and Quot.sound.
  • lake-manifest.json pins the same Mathlib and transitive package revisions as lean/disaster-recovery.
  • Bespoke axiom-audit code and runtime import-policy tests were removed.
  • lake test runs the configured checker self-test driver.
  • Lean tests retain one basic accepted history and two acceptance relationships absent from generated-trace coverage; 21 redundant positive histories were removed while negative and malformed-input coverage remains.

A second exhaustive API pass removed another 47 lines by reusing core list filtering/folds, Lean's JSON string parser, derived JSON serialization, exact natural-number decoding, stream error conversion, String.all, and List.mapIdx. The model retains plain List (K x V) data rather than Mathlib's dependent-sigma AList, while duplicate-key rejection, lexical UInt64 validation, lowercase hexadecimal validation, and NDJSON lifecycle handling remain deliberately stricter than available high-level APIs.

Trace artifact audit

No NDJSON traces, generated fuzzer corpora, or captured outputs are checked in. Focused C++ unit-test and fuzzer traces are generated under build-kv-trace/kv-traces/, ignored by Git, checked by Lean, and uploaded by CI as diagnostic artifacts.

The Lean streaming test also generates its input at runtime: it encodes an existing in-memory test execution into an automatically deleted temporary file, then compares file-backed replay with in-memory replay.

Performance

Normal builds set CCF_KV_TRACING=OFF: trace fields and calls are removed by preprocessing and trace.cpp is not linked. The resulting kv_bench binary contains no ccf::kv::trace symbols.

Seven paired RelWithDebInfo runs of the existing kv_bench suite compared tracing OFF with an enabled-but-inactive tracing build. The median aggregate difference was -0.8% (run-to-run noise ranged from -12.6% to +11.5%); the serialise and deserialise suite medians were +0.7% and +0.4%. The smallest 10-entry cases exposed the expected fixed opt-in cost, at approximately +9%, from trace objects and atomic enabled checks. Active trace capture is intentionally test-only and adds mutex, JSON, queue, and file-writing work.

Scope limits

Proofs establish model properties; finite accepted traces are conformance evidence, not a full C++ refinement proof. Consensus, recovery, encryption/domains/access policy, and untyped range queries are outside the current model. See the README for details.

Capture the transaction-wide snapshot contract, prove KV safety properties, and replay instrumented unit-test traces without changing KV behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 267a4952-bb04-4d61-bd92-80249fe663d7
Capture each map global view at first handle acquisition while retaining the transaction-wide current snapshot. Update provenance and stability proofs, replay fixtures, regression coverage and documentation to follow implementation behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 267a4952-bb04-4d61-bd92-80249fe663d7
Remove redundant acquired-map and snapshot metadata, retain substantive kernel-checked guarantees, and share replay-preservation induction. Preserve all checked trace outcomes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 267a4952-bb04-4d61-bd92-80249fe663d7
Generate bounded seeded concurrent KV workloads, validate captured behavior with the Lean model, and document the observed zero-revision map dependency discrepancy.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 267a4952-bb04-4d61-bd92-80249fe663d7
Classify the new upstream regressions without claiming support for range queries or reserved transaction IDs. Keep the ordinary KV suite intact, select the independent non-conflict regression, and record that the original zero-revision failure is fixed upstream.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 267a4952-bb04-4d61-bd92-80249fe663d7
Keep model definitions and property statements review-visible, move supporting proofs behind the same GitHub review boundary as the recovery model, and retain explicit checked links for all 37 guarantees. Upgrade the Lean pin and preserve strict replay behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 267a4952-bb04-4d61-bd92-80249fe663d7
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Predefine CCF_KV_TRACING while generating API documentation so declarations guarded by the opt-in feature match their scanned definitions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@heidihoward Heidi Howard (heidihoward) added the lean Verification using Lean label Sep 10, 2026
Replace the separate trace and fuzz harnesses, unit tests, and coverage manifest with one focused integration runner. It generates only purpose-built traces, checks each with Lean, verifies fuzzer event coverage, and retains failure artifacts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the checked-in NDJSON examples and exercise file-backed replay with a temporary trace encoded from the existing Lean test events.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Run disaster-recovery proofs and KV trace conformance as jobs in the single Lean workflow, preserving manual dispatch and relevant pull-request path triggers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use the same pinned Mathlib import generator and axiom-audit linter as the disaster-recovery model. Remove the bespoke audit and import tests, and retain only accepted histories not covered by generated traces.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mark the container checkout as a safe Git directory before CMake calls git describe. The Lean model checks already pass; this unblocks the instrumented KV build.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reuse core list folds, filtering lemmas, JSON parsing primitives, derived serialization, stream error handling, and the standard Lake test driver. Preserve the KV representation and strict wire semantics where no exact library abstraction exists.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lean Verification using Lean

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants