From af1f34520586bcd7a943eb01e4ec8c33b6950df2 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 22 Oct 2026 21:34:24 +0530 Subject: [PATCH 1/5] docs(plan): Kani proofs of the storage encodings (#627) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz --- .../2026-10-22-627-kani-storage-encoding.md | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 docs/superpowers/plans/2026-10-22-627-kani-storage-encoding.md diff --git a/docs/superpowers/plans/2026-10-22-627-kani-storage-encoding.md b/docs/superpowers/plans/2026-10-22-627-kani-storage-encoding.md new file mode 100644 index 0000000000..6f008515cc --- /dev/null +++ b/docs/superpowers/plans/2026-10-22-627-kani-storage-encoding.md @@ -0,0 +1,119 @@ +# Kani proofs of the storage encodings (#627) — Plan + +Spec: `docs/superpowers/specs/2026-10-22-kani-storage-encoding-design.md` (PR #689). +Test-only: no library, `.graph` format or WAL change. + +| PR | Steps | Branch | Base | +|---|---|---|---| +| 1 | 1–8: harnesses, lint, workflow, docs, this plan | `test/627-kani` | `v3` | +| 2 | 9–13: `encode_value` harnesses, lint, workflow, docs | `test/627-kani-v2` | `main` | + +PR 1 says "Closes #627" (a `v3` test-only change closes on merge). PR 2 says "Refs #627". +Each PR is reviewed with Codex, CI is owned until green, and neither merges without the +user's go-ahead (`v3`: merge commit; `main`: squash). + +Kani runs only on the bench machine (the laptop OOMs). Harness names are fully qualified +with `--exact`; `--verbose` crashes the Kani compiler on this crate, use +`-Z unstable-options --cbmc-args --verbosity 9` instead. + +## Deviations from the spec + +1. **`--output-format terse` is added to the Kani arguments** (spec §3.3, §4). Kani 0.68.0 + refuses `-j` without it (`Conflicting options: --jobs requires + --output-format=terse`); found on the first bench-machine run of step 4. + +Clarifications: + +1. **Test counts do not change.** Kani harnesses are not `#[test]`s, so the 1321 count in + `CLAUDE.md` and `docs/TEST_COVERAGE.md` stays. `TEST_COVERAGE.md` gets a separate Kani + section with the 12 (`v3`) or 5 (`main`) harnesses. +2. **The lint table is `[workspace.lints.rust]`.** The package already opts in with + `[lints] workspace = true` on both branches, so the check-cfg entry goes next to + `[workspace.lints.clippy]`. `fuzz/` and the golden generators are outside the + workspace and never see `cfg(kani)`. + +## PR 1 — `v3` + +1. **Rebase.** `test/627-kani` onto `origin/v3` (done 2026-10-22: 75a3faca; `keys.rs`, + `index.rs`, `graph/types.rs` unchanged). Harness files as prototyped: + `src/storage/keys/verification.rs` (7), `src/storage/index/verification.rs` (5), + `#[cfg(kani)] mod verification;` in `keys.rs` (before `mod tests`) and `index.rs` + (before `mod tests`). +2. **Lint.** In `Cargo.toml`, before `[workspace.lints.clippy]`: + + ```toml + [workspace.lints.rust] + # Kani proof harnesses (#627): `cargo kani` sets cfg(kani). + unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kani)'] } + ``` + + Check: `cargo build` and `cargo clippy --all-targets` print no + `unexpected cfg condition name: kani`; `cargo test --lib` passes. +3. **Workflow** `.github/workflows/kani.yml`, modelled on `grammar-verifier.yml`: + - `run-name` and `KANI_REF` from `workflow_dispatch` `inputs.ref`, else from the cron + string (`"0 6 * * *"` main, `"0 18 * * *"` v3; offset from the grammar verifier's + 05:30/17:30), else for `pull_request` the PR head (checkout default). + - `pull_request` `paths:` `src/storage/keys.rs`, `src/storage/keys/**`, + `src/storage/index.rs`, `src/storage/index/**`, `src/graph/types.rs`, `Cargo.toml`, + `.github/workflows/kani.yml`. + - `permissions: contents: read, issues: write`; `timeout-minutes: 30`. + - Steps: `actions/checkout@v4` (with `ref: KANI_REF` only when not a PR); + `model-checking/kani-github-action@v1.1` with `kani-version: 0.68.0`, + `args: --lib -j --output-format terse -Z unstable-options --harness-timeout 10m`. The action has no + output capture, so the failure report links the run instead of tailing a log. + - `Record Kani failure` step, `if: failure() && github.event_name == 'schedule'`, + opens or comments on `Nightly Kani failure ()` with run URL, commit and the + reproduce command `cargo kani --lib -j`. + - Check: `actionlint` clean; after push, the PR run is green with 12 harnesses + reported `VERIFICATION:- SUCCESSFUL`. Dispatch and schedule need the file on the + default branch, so the nightly path is first exercised after PR 2 merges (step 13). +4. **Bench-machine run.** Copy the rebased tree to the bench machine and run + `cargo kani --lib -j --output-format terse -Z unstable-options --harness-timeout 10m`. + Result 2026-10-22: 12 successes, 40 s wall, 1.1 GB peak RSS. Record the summary line in the PR body. +5. **Mutation check (not committed).** On the bench machine, break each encoder once + (`put_int` drops the sign flip; `float_bits` skips the negative transform; + `put_valid_to` encodes `i64::MAX` like any other value; `encode_value` Ref writes + the UUID bytes reversed) and confirm the matching harness fails. Revert. Result 2026-10-22: one mutation per + harness, all 12 fail. +6. **Docs.** + - `docs/TEST_COVERAGE.md`: a `### Kani proofs (#627)` section under Covered Areas, + the two harness tables from spec §3.1/§3.2 (names and properties, no timings), + what is left out (spec §5, one paragraph), and the run command; reproduce line in + Reproducing. + - `CLAUDE.md`: module list — `index.rs` and the `keys.rs` entry note + `verification.rs` (`#[cfg(kani)]`, encoder proofs, #627); Build and Run gets + `cargo kani --lib -j` with "bench machine or CI only: needs ~27 GB if a decoder + harness is added". + - `CHANGELOG.md` `[Unreleased]`: a Testing entry — Kani proves the key and value + encoders order-preserving (#627); test-only. + - `ROADMAP.md`: tick #627 if listed. No docs-site change (no user-facing behaviour). +7. **Commit** the plan with PR 1 (`docs(plan): ...`), then `test(storage): Kani proofs + of the key and value encoders (#627)`, `ci: nightly and PR Kani workflow (#627)`, + `docs: ...`. +8. **PR, Codex review, CI.** `codex exec -s read-only ... < /dev/null`; verify findings + against the code; fix; wait for green; ask to merge. + +## PR 2 — `main` backport + +9. Branch `test/627-kani-v2` from `origin/main` in `.claude/worktrees/627-kani-v2`. + Copy `src/storage/index/verification.rs` unchanged and add `#[cfg(kani)] mod + verification;` before `#[cfg(test)] mod tests` in `src/storage/index.rs`. Confirm + `encode_value`'s type bytes match (`Null 0x00`, `Boolean 0x01`, `Integer 0x02`, + `Float 0x03`, `Ref 0x06`) and that `index.rs` imports `Value` so `use super::*` + resolves. +10. Same `Cargo.toml` lint (step 2), same `kani.yml` (step 3) byte-for-byte, so the + copy on `main` that drives both crons matches `v3`. +11. Bench-machine run: 5 successes. Mutation check on the Ref harness. +12. Docs as step 6 with 5 harnesses; `CHANGELOG.md` `[Unreleased]` on `main`. The PR body + says the 7 `keys.rs` harnesses are left out because `main` has no `keys.rs`, and that + the NaN position is #688, not asserted. +13. Codex review, CI green, ask to merge. After merge, dispatch `kani.yml` once with + `ref: main` and once with `ref: v3` to exercise the nightly path; both green. + +## After both merge + +- Delete the bench-machine prototype dirs: `~/Work/AMC/Minigraf/kani-627`, `kani-627b`, + `kani-627-logs`, `kani-627b-logs`, `kani-627-run.sh`, `kani-627-par.sh`, + `kani-627b-par.sh`. +- Ask whether to uninstall Kani from the laptop (`~/.kani`, 485 MB, `cargo-kani`). +- Remove the worktrees; update memory (`project_627_kani_next_session.md`, issue roadmap). From 950253e2a96642ee22093385eda705b44d1ef6d2 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 22 Oct 2026 21:34:24 +0530 Subject: [PATCH 2/5] test(storage): Kani proofs of the key and value encoders (#627) Twelve #[cfg(kani)] harnesses prove, for every input, that the v8 key encoders and encode_value keep the order the indexes rely on. Cargo.toml declares the kani cfg so normal builds do not warn. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz --- Cargo.toml | 4 ++ src/storage/index.rs | 3 ++ src/storage/index/verification.rs | 67 +++++++++++++++++++++++ src/storage/keys.rs | 3 ++ src/storage/keys/verification.rs | 90 +++++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 src/storage/index/verification.rs create mode 100644 src/storage/keys/verification.rs diff --git a/Cargo.toml b/Cargo.toml index a70e200ea4..fc4cbafea8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -128,6 +128,10 @@ lto = "thin" [lints] workspace = true +[workspace.lints.rust] +# Kani proof harnesses (#627): `cargo kani` sets cfg(kani). +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kani)'] } + [workspace.lints.clippy] # Panic prevention — use Result/? or debug_assert! instead unwrap_used = "deny" diff --git a/src/storage/index.rs b/src/storage/index.rs index 6b69f463ce..f43db8ecd1 100644 --- a/src/storage/index.rs +++ b/src/storage/index.rs @@ -187,6 +187,9 @@ impl Indexes { } } +#[cfg(kani)] +mod verification; + #[cfg(test)] mod tests { use super::*; diff --git a/src/storage/index/verification.rs b/src/storage/index/verification.rs new file mode 100644 index 0000000000..3c4e5a3f47 --- /dev/null +++ b/src/storage/index/verification.rs @@ -0,0 +1,67 @@ +//! Kani proof harnesses for the canonical value encoding (#627). +//! +//! Each harness proves one variant's encoding for every value of that variant: +//! the type byte, and that byte order matches the variant's order. An order +//! that is exact on equality is also injective, and distinct type bytes order +//! and separate the variants. Strings and keywords are left out: CBMC does not +//! finish on variable-length encodings at a useful bound, so the fuzz and +//! property tests cover them. + +use super::*; +use uuid::Uuid; + +#[kani::proof] +fn encode_value_null_and_boolean() { + let a: bool = kani::any(); + let b: bool = kani::any(); + let ea = encode_value(&Value::Boolean(a)); + let eb = encode_value(&Value::Boolean(b)); + assert_eq!(ea.first(), Some(&0x01)); + assert_eq!(a.cmp(&b), ea.cmp(&eb)); + assert_eq!(encode_value(&Value::Null), vec![0x00]); +} + +#[kani::proof] +fn encode_value_integer_preserves_order() { + let a: i64 = kani::any(); + let b: i64 = kani::any(); + let ea = encode_value(&Value::Integer(a)); + let eb = encode_value(&Value::Integer(b)); + assert_eq!(ea.first(), Some(&0x02)); + assert_eq!(a.cmp(&b), ea.cmp(&eb)); +} + +/// Non-NaN floats keep IEEE total order, so `-0.0` sorts before `0.0` and the +/// two encode differently. +#[kani::proof] +fn encode_value_float_preserves_order() { + let a: f64 = kani::any(); + let b: f64 = kani::any(); + kani::assume(!a.is_nan() && !b.is_nan()); + let ea = encode_value(&Value::Float(a)); + let eb = encode_value(&Value::Float(b)); + assert_eq!(ea.first(), Some(&0x03)); + assert_eq!(a.total_cmp(&b), ea.cmp(&eb)); +} + +/// Every NaN encodes to the same bytes. +#[kani::proof] +fn encode_value_nan_is_canonical() { + let a: f64 = kani::any(); + let b: f64 = kani::any(); + kani::assume(a.is_nan() && b.is_nan()); + assert_eq!( + encode_value(&Value::Float(a)), + encode_value(&Value::Float(b)) + ); +} + +#[kani::proof] +fn encode_value_ref_preserves_order() { + let a = Uuid::from_bytes(kani::any()); + let b = Uuid::from_bytes(kani::any()); + let ea = encode_value(&Value::Ref(a)); + let eb = encode_value(&Value::Ref(b)); + assert_eq!(ea.first(), Some(&0x06)); + assert_eq!(a.cmp(&b), ea.cmp(&eb)); +} diff --git a/src/storage/keys.rs b/src/storage/keys.rs index 7d2ad1e86e..606bfa0dea 100644 --- a/src/storage/keys.rs +++ b/src/storage/keys.rs @@ -734,6 +734,9 @@ pub fn read_uint_bytes(bytes: &[u8]) -> Result { Ok(v) } +#[cfg(kani)] +mod verification; + #[cfg(test)] mod tests { use super::*; diff --git a/src/storage/keys/verification.rs b/src/storage/keys/verification.rs new file mode 100644 index 0000000000..ac5d3a8ac0 --- /dev/null +++ b/src/storage/keys/verification.rs @@ -0,0 +1,90 @@ +//! Kani proof harnesses for the key encodings (#627). +//! +//! Each harness proves its property for every input of the given types. Only +//! the encoders are covered: CBMC does not finish on the `Reader` decoders +//! (their error paths build an `anyhow::Error`) or on variable-length strings, +//! so the fuzz and property tests cover those. + +use super::*; + +fn enc_int(v: i64) -> Vec { + let mut out = Vec::new(); + put_int(&mut out, v); + out +} + +fn enc_uint(v: u64) -> Vec { + let mut out = Vec::new(); + put_uint(&mut out, v); + out +} + +#[kani::proof] +#[kani::unwind(10)] +fn put_int_preserves_order() { + let a: i64 = kani::any(); + let b: i64 = kani::any(); + assert_eq!(a.cmp(&b), enc_int(a).cmp(&enc_int(b))); +} + +#[kani::proof] +#[kani::unwind(10)] +fn put_uint_preserves_order() { + let a: u64 = kani::any(); + let b: u64 = kani::any(); + assert_eq!(a.cmp(&b), enc_uint(a).cmp(&enc_uint(b))); +} + +/// Non-NaN floats keep IEEE total order (`-0.0` before `0.0`). +#[kani::proof] +fn float_bits_preserves_order() { + let a: f64 = kani::any(); + let b: f64 = kani::any(); + kani::assume(!a.is_nan() && !b.is_nan()); + assert_eq!(a.total_cmp(&b), float_bits(a).cmp(&float_bits(b))); +} + +/// NaN is canonical and sorts after every other float. +#[kani::proof] +fn float_bits_nan_sorts_last() { + let a: f64 = kani::any(); + let n: f64 = kani::any(); + kani::assume(n.is_nan()); + assert_eq!(float_bits(n), float_bits(f64::NAN)); + if !a.is_nan() { + assert!(float_bits(a) < float_bits(n)); + } +} + +#[kani::proof] +fn float_bits_round_trips() { + let a: f64 = kani::any(); + kani::assume(!a.is_nan()); + assert_eq!(float_from_bits(float_bits(a)).to_bits(), a.to_bits()); +} + +/// Newer transactions sort first. +#[kani::proof] +#[kani::unwind(10)] +fn put_tx_desc_reverses_order() { + let a: u64 = kani::any(); + let b: u64 = kani::any(); + let mut ea = Vec::new(); + let mut eb = Vec::new(); + put_tx_desc(&mut ea, a); + put_tx_desc(&mut eb, b); + assert_eq!(b.cmp(&a), ea.cmp(&eb)); +} + +/// Includes `VALID_TIME_FOREVER` (`i64::MAX`), encoded as the single byte 0xFF. +#[kani::proof] +#[kani::unwind(10)] +fn put_valid_to_preserves_order() { + let a: i64 = kani::any(); + let b: i64 = kani::any(); + let mut ea = Vec::new(); + let mut eb = Vec::new(); + put_valid_to(&mut ea, a); + put_valid_to(&mut eb, b); + assert_eq!(a.cmp(&b), ea.cmp(&eb)); +} From 8376cb43d31533c568e31777f7e25e3d7f625696 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 22 Oct 2026 21:34:24 +0530 Subject: [PATCH 3/5] ci: Kani proofs on encoder PRs and nightly (#627) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz --- .github/workflows/kani.yml | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 .github/workflows/kani.yml diff --git a/.github/workflows/kani.yml b/.github/workflows/kani.yml new file mode 100644 index 0000000000..f021acf826 --- /dev/null +++ b/.github/workflows/kani.yml @@ -0,0 +1,97 @@ +name: Kani proofs + +# Two branches, 12 hours apart: main at 06:00 UTC, v3 at 18:00 UTC. +# Scheduled runs always use this file from the default branch, so the branch +# under test is chosen from the cron string that fired (as in +# grammar-verifier.yml). Keep the cron strings here and in KANI_REF/run-name +# identical. +run-name: >- + Kani proofs (${{ github.event_name == 'pull_request' && github.head_ref + || github.event_name == 'workflow_dispatch' && inputs.ref + || (github.event.schedule == '0 18 * * *' && 'v3' || 'main') }}) + +# #627: proves the byte encoders that order index keys (src/storage/keys/ +# verification.rs, src/storage/index/verification.rs). The whole set takes +# about 30 seconds of proof time and ~1 GB of memory. Kani upgrades are +# deliberate PRs that re-run the set. + +on: + pull_request: + paths: + - "src/storage/keys.rs" + - "src/storage/keys/**" + - "src/storage/index.rs" + - "src/storage/index/**" + - "src/graph/types.rs" + - "Cargo.toml" + - ".github/workflows/kani.yml" + schedule: + - cron: "0 6 * * *" # main + - cron: "0 18 * * *" # v3 + workflow_dispatch: + inputs: + ref: + description: Branch to prove + required: true + default: main + +permissions: + contents: read + issues: write + +env: + KANI_REF: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || (github.event.schedule == '0 18 * * *' && 'v3' || 'main') }} + +jobs: + kani: + name: Kani proofs + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - uses: actions/checkout@v4 + if: ${{ github.event_name == 'pull_request' }} + + - uses: actions/checkout@v4 + if: ${{ github.event_name != 'pull_request' }} + with: + ref: ${{ env.KANI_REF }} + + - name: Run Kani + uses: model-checking/kani-github-action@v1.1 + with: + kani-version: 0.68.0 + args: --lib -j --output-format terse -Z unstable-options --harness-timeout 10m + + - name: Record Kani failure + if: ${{ failure() && github.event_name != 'pull_request' }} + shell: bash + env: + GH_TOKEN: ${{ github.token }} + ISSUE_TITLE: "Nightly Kani failure (${{ env.KANI_REF }})" + run: | + report_file="kani-failure.md" + { + echo "The Kani proofs failed on ${{ env.KANI_REF }}." + echo + echo "- Run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + echo "- Commit: $(git rev-parse HEAD)" + echo "- Reproduce: \`cargo kani --lib -j --output-format terse -Z unstable-options --harness-timeout 10m\` (Kani 0.68.0)" + echo + echo "The failing harness and its counterexample are in the run log." + } > "$report_file" + + existing_issue="$(gh issue list \ + --repo "$GITHUB_REPOSITORY" \ + --state open \ + --search "$ISSUE_TITLE in:title" \ + --json number,title \ + --limit 100 \ + --jq ".[] | select(.title == \"$ISSUE_TITLE\") | .number" \ + | head -n 1)" + + if [ -n "$existing_issue" ]; then + gh issue comment "$existing_issue" --repo "$GITHUB_REPOSITORY" --body-file "$report_file" + else + gh issue create --repo "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" --body-file "$report_file" + fi From 1c00c5e602c56348a9eb2abcb589d999fd21a245 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 22 Oct 2026 21:34:25 +0530 Subject: [PATCH 4/5] docs: Kani proofs of the encoders (#627) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz --- CHANGELOG.md | 1 + CLAUDE.md | 8 ++++++-- docs/TEST_COVERAGE.md | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bbf35a762..bc69502d9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -127,6 +127,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `tests/snapshot_atomicity_test.rs` races a writer against a reader: a query must see each transaction whole, whether written with `execute` or a `WriteTransaction` (#554), and must read one state for all its patterns (#555), in memory and on file. It also runs the v2.x checkpoint race from #558, which never failed on v3: copy-on-write checkpoints do not overwrite pages a published reader uses. - **The `datalog_eval` fuzz guard counts partial bindings** (#597). The guard skipped inputs whose patterns join to more than 50,000 rows, counting only the rows after the last pattern. A `not-join` body still runs on the executor pattern by pattern in text order, so a 120-pattern body built hundreds of thousands of partial bindings before its last pattern matched nothing, and ran past the 60-second timeout. The guard now counts the bindings after every pattern. On the `v3` corpus (4,783 inputs) coverage drops by 7 of 9,719 edges. The input is added as a seed, as is the `btree_page` input of the cursor fix above. +- **Kani proofs of the key and value encoders (#627).** `src/storage/keys/verification.rs` and `src/storage/index/verification.rs` hold 12 Kani harnesses, compiled only under `cfg(kani)`. They prove for every input that the v8 key encoders (`put_int`, `put_uint`, `put_tx_desc`, `put_valid_to`, `float_bits`) and `encode_value` keep the order the indexes rely on, that every NaN encodes to one value, and that `float_bits` round-trips. `.github/workflows/kani.yml` runs them on pull requests that touch the encoders and nightly on `main` and `v3`. Decoders, strings, packed pages and the WAL are not covered: the model checker does not finish on them, and the fuzz and property tests remain their defence. Test-only; `Cargo.toml` declares the `kani` cfg so normal builds do not warn. - **Parser vs grammar verifier (#643).** `src/query/datalog/parser/verifier.rs` checks, for every generated input, that the parser rejects what `tests/grammar/grammar.pest` rejects, and accepts what it accepts unless the error code is semantic (a listed code with a witness pest accepts). It runs every string of 1 to 3 characters over 102 characters (ASCII, `\t \n \r`, four non-ASCII stand-ins) through `parse_edn`, and every bracket-balanced sequence of up to `MINIGRAF_GRAMMAR_BOUND` (default 3) of 32 tokens in 15 command templates through `parse_datalog_command`, also with no separators up to 3 tokens. Deterministic; about 20 s by default and 3.5 min at bound 4 on a 16-thread machine. The drift it found is listed in `KNOWN_DRIFT` by cause (comments and non-ASCII letters #650, since documented: see below; empty sections, ignored keywords, rule and call heads, a lone `:` or `-`, unterminated strings #651, since fixed; a fact of more than four elements losing elements, #649, since fixed); each fix removes its entry. `grammar.pest` now says what the parser means: a fact is exactly `[e a v]` plus an optional valid-time map and a retracted fact exactly `[e a v]`; `not`, `not-join`, `or`, `or-join` (and `and` inside an `or`) are never rule names; literal keywords end at a word boundary (`:find?x` is one keyword). - **The grammar documents comments and non-ASCII identifiers** (#650). The parser has always accepted both; `tests/grammar/grammar.pest` and `docs/GRAMMAR.md` now say so. A `;` starts a comment that runs to the end of the line and is skipped like whitespace. Symbols, variables, keywords and bind slots take Unicode letters and numerals (`:person/名前`, `?ñ`), as Rust's `char::is_alphabetic` and `char::is_numeric` define them; a symbol starts with a letter or `_`, and `-` followed by a numeral starts a number, not a symbol. Nothing the parser accepts or rejects changes. diff --git a/CLAUDE.md b/CLAUDE.md index b3e0c9786c..45b8843563 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -84,6 +84,10 @@ cargo test --test complex_queries_test -- --nocapture cargo test --test recursive_rules_test -- --nocapture cargo test --test concurrency_test +# Kani proofs of the encoders (#627); ~1 GB. Never add decoder/string harnesses +# without a bench-machine run first: they went past 27 GB without finishing +cargo kani --lib -j --output-format terse -Z unstable-options --harness-timeout 10m + # Run examples cargo run --example embedded cargo run --example file_storage @@ -112,8 +116,8 @@ cargo run < demos/demo_negation.txt - `backend/memory.rs`: In-memory backend for testing - `backend/fault_inject.rs`: `FaultInjectingBackend` — injects I/O errors for durability tests (test builds only) - `fault.rs`: thread-local fault plan (test builds only, #390) — EIO, torn/short writes, sticky ENOSPC, failed fsync with or without lost writes, at the k-th write or sync of `FileBackend`, the WAL and `sync_parent_dir`; driven by `src/fault_matrix.rs` - - `index.rs`: pending (uncheckpointed) EAVT/AEVT keys over UUIDs and strings, `encode_value` - - `keys.rs`: byte-comparable v8 keys (FDB integers, value tags, `tx↓`, FOREVER), DICT keys, `MAX_VALUE_BYTES`, `MAX_IDENT_BYTES` + - `index.rs`: pending (uncheckpointed) EAVT/AEVT keys over UUIDs and strings, `encode_value`; `index/verification.rs`: Kani proofs of `encode_value` (`#[cfg(kani)]`, #627) + - `keys.rs`: byte-comparable v8 keys (FDB integers, value tags, `tx↓`, FOREVER), DICT keys, `MAX_VALUE_BYTES`, `MAX_IDENT_BYTES`; `keys/verification.rs`: Kani proofs that the key encoders preserve order (`#[cfg(kani)]`, #627; `kani.yml` runs them on encoder PRs and nightly) - `node.rs`: prefix-compressed leaf and shortest-separator internal node codecs - `btree.rs`: On-disk B+tree over byte keys (`build_btree`, `cow_update` (copy-on-write inserts and deletes; an emptied leaf or node leaves its parent, an emptied tree is root 0; #550) and `cow_insert`, `LeafCursor` with `seek`, `prefix_scan`, `get`, `MutexStorageBackend`) - `dict.rs`: `DictReader` (id ↔ UUID/ident, tx timestamps, long values) and `Encoder` (checkpoint-time id assignment and key building) diff --git a/docs/TEST_COVERAGE.md b/docs/TEST_COVERAGE.md index 5e7b434754..a338f32813 100644 --- a/docs/TEST_COVERAGE.md +++ b/docs/TEST_COVERAGE.md @@ -34,6 +34,7 @@ This covers the unreleased file-format-v8 work (#287, #371): the index-key value - **Large transactions** (`src/storage/persistent_facts/large_tx.rs`, 7 tests; `src/fault_matrix.rs`, 4 tests; `src/storage/page.rs`, 2 tests; `src/storage/cache.rs`, `src/storage/btree.rs` and `statement.rs`, 4 tests; #550): a `transact`/`retract` of more than one chunk, run by `Minigraf::execute` on a file database at chunk sizes 1 to 4, stores the same records as the one-chunk path (repeats across chunks stored once, several values and windows of one attribute, shared long values, refs, keywords, transaction-level windows, retractions, pending WAL entries committed with it), returns its `tx_id`, answers `:as-of`, passes `verify`, deletes the WAL and survives reopen; another window of a triple an earlier chunk wrote (`API-011`) and a value too long for a checkpoint in a later chunk (`WAL-003`) give the one-chunk path's code and message, take no `tx_count`, write no meta and leave the WAL, and the next checkpoint writes a meta before deleting it, as the first checkpoint after an open with a WAL does; a crash before the meta write on a new file reopens through the WAL guard, and is `STG-033` without it; cursors and fact logs opened before and between chunks keep their snapshot through later checkpoints. The fault matrix injects every write and sync fault at every call of a large transaction on a file with one and with two valid meta slots, with and without a WAL beforehand. Allocator tracking and release, cache eviction, and cursor peeking have unit tests. With `test-oracle`, `tests/crash_kill_test.rs` adds a variant whose child makes most transactions large and rolls back a large statement after writing pages, and `tests/model_based_test.rs` runs at a chunk size of 2; `tests/large_transaction_acceptance_test.rs` (ignored, `test-oracle` only, nightly in `.github/workflows/smoke.yml`) holds at most 16,384 materialised facts for a 1M-fact `transact` and prints peak RSS. - **Grammar page** (`tests/grammar_doc.rs`, 10 tests; #643): `docs/GRAMMAR.md` matches the EBNF rendered from `tests/grammar/grammar.pest`; each rendering rule (sequence, choice and grouping, names and builtins, `SOI`/`EOI` dropped, lookaheads as comments, bounded repetition, quoting, token marks, section titles, line breaking, the whitespace note and the comment note it joins) on a small grammar. - **Plan independence** (`tests/plan_independence_test.rs`, 15 tests, `test-oracle` feature only; #596): a matrix of queries (joins in both text orders, cross products, keyword and ref, floats, long strings, filter and binding expressions, recursive rules and rules with `not`, `or`/`or-join` including the #250 short-circuit shapes, placed and deferred `not`/`not-join`, aggregates, `:as-of`, `:valid-at`, `:any-valid-time`), in memory and on file after a checkpoint and a reopen, through `execute` and a cursor, gives the same bag of rows with clause reordering on and off (`minigraf::__reorder`) and with the engine's negation bodies and `or` branches chosen, forced hashed and forced correlated (`minigraf::__subplans`, #546; the matrix gains #546's negation and disjunction shapes); #596's example and the unification cases (an expression whose output is its input, two expressions on one variable, integer vs float, `-0.0` vs `0.0`); and `or` / `or-join` branches whose expressions read or bind from a variable only the outer row binds, nested and in rule bodies (#620); and expressions, chains of them and a `not` after them, reading a variable only an `or` binds, in queries, with rules and in rule bodies (#625; `tests/disjunction_test.rs` repeats them without `test-oracle`). Under `test-oracle` the model-based and property tests also rerun every generated query with reordering off (the property test also with negation bodies and `or` branches forced hashed; it generates `or` / `or-join` over bound variables, #546). Unit tests cover `branch_outer_reads` (#620), the planner deferring an expression only an `or` can bind for, after the expressions placed before it and ahead of the deferred `not`s (#625), `apply_expr` (equal, different, integer vs float, NaN, `-0.0`/`0.0` with and without replacing, keyword vs ref both ways, a failing expression), `Binders::expression`, the switch (source order kept, per thread, restored on drop), and the engine planner's `Bind` modes and build side with the switch off; the engine's join matrix gains six unification shapes. +- **Kani proofs of the encoders** (#627; not `#[test]`s, run by `cargo kani` and `.github/workflows/kani.yml`): 12 harnesses prove, for every input, that the byte encoders ordering index keys keep their order. `src/storage/keys/verification.rs` (7): `put_int`, `put_uint` and `put_valid_to` (including `VALID_TIME_FOREVER`) preserve order, `put_tx_desc` reverses it, `float_bits` preserves IEEE total order on non-NaN floats (`-0.0` before `0.0`), maps every NaN to one value after all others, and round-trips through `float_from_bits`. `src/storage/index/verification.rs` (5): `encode_value` writes `Null` as `[0x00]` and each of `Boolean`, `Integer`, `Float` and `Ref` with its own type byte and in its own order, and every NaN to the same bytes. Each harness fails when its encoder is broken on purpose. Decoders, strings, packed pages and the WAL are left out: CBMC does not finish on them (decoder error paths build an `anyhow::Error`; a 3-byte string order proof is a 105M-clause formula), so the fuzz and property tests cover them (spec `docs/superpowers/specs/2026-10-22-kani-storage-encoding-design.md` §5). - **Public diagnostics**: structured parser, query, storage, WAL, API, and internal error codes; the error-code registry is checked against [`ERROR_REFERENCE.md`](ERROR_REFERENCE.md). - **Compatibility and quality**: golden-file corpus of released file formats, cross-platform format compatibility, property-based tests, long-haul smoke coverage, a weekly soak at 10M facts with a 5-hour churn (#392), XTDB/Datomic semantic compatibility, grammar conformance, and rustdoc examples. @@ -59,6 +60,10 @@ cargo test --quiet # Include the scheduled/ignored tests when the host supports them cargo test -- --include-ignored +# Kani proofs of the encoders (#627): ~40 s and ~1 GB with -j; Kani pins its own nightly +cargo install --locked kani-verifier && cargo kani setup +cargo kani --lib -j --output-format terse -Z unstable-options --harness-timeout 10m + # Generate a local branch-coverage report (requires cargo-llvm-cov and a nightly toolchain) cargo +nightly llvm-cov --branch --html From bff7abff3db1d099d4426f5bf891135b1dc93663 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 22 Oct 2026 21:40:59 +0530 Subject: [PATCH 5/5] ci: open Kani failure issues only for scheduled runs (#627) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz --- .github/workflows/kani.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/kani.yml b/.github/workflows/kani.yml index f021acf826..65c9042000 100644 --- a/.github/workflows/kani.yml +++ b/.github/workflows/kani.yml @@ -64,7 +64,7 @@ jobs: args: --lib -j --output-format terse -Z unstable-options --harness-timeout 10m - name: Record Kani failure - if: ${{ failure() && github.event_name != 'pull_request' }} + if: ${{ failure() && github.event_name == 'schedule' }} shell: bash env: GH_TOKEN: ${{ github.token }}