Add Lean KV model and trace conformance tooling - #8339
Draft
Amaury Chamayou (achamayou) wants to merge 16 commits into
Draft
Add Lean KV model and trace conformance tooling#8339Amaury Chamayou (achamayou) wants to merge 16 commits into
Amaury Chamayou (achamayou) wants to merge 16 commits into
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
lean/kv/Kv/Properties.lean+276/-0)lean/kv/Kv/Protocol/+750/-0)lean/kv/Kv/Trace.lean,lean/kv/Main.lean+298/-0)+528/-1)+1000/-7)+1958/-0)+189/-0)+523/-3)+506/-0)Total requiring human review: 6,039 changed lines.
Machine-checked; no line-by-line proof review requested
lean/kv/Kv/Proofs/+1215/-0)Only
lean/kv/Kv/Proofs/is markedlinguist-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:
mk_all --check --lib Kvverifies that the generatedKv.leanroot imports every library module.axiom-auditlint driver audits every declaration underKv; 1,516 declarations currently use onlypropext,Classical.choice, andQuot.sound.lake-manifest.jsonpins the same Mathlib and transitive package revisions aslean/disaster-recovery.lake testruns the configured checker self-test driver.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, andList.mapIdx. The model retains plainList (K x V)data rather than Mathlib's dependent-sigmaAList, 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 andtrace.cppis not linked. The resultingkv_benchbinary contains noccf::kv::tracesymbols.Seven paired
RelWithDebInforuns of the existingkv_benchsuite 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.