Skip to content

test(tla): implementation-trace validation — the dual refinement direction - #1691

Merged
robcohen merged 1 commit into
mainfrom
feat/tla-trace-validation
Jul 2, 2026
Merged

robcohen merged 1 commit into
mainfrom
feat/tla-trace-validation

Conversation

@robcohen

@robcohen robcohen commented Jul 2, 2026

Copy link
Copy Markdown
Member

FV follow-up #2 (of the improvement menu), companion to #1690. Closes the remaining conceptual gap in the MBT layer.

The gap

The behavior-replay suite (#1685/#1688) checks model → implementation: every model behavior is implemented correctly, exhaustively up to the bound. The dual — implementation → model, i.e. the implementation never takes a transition the model forbids — was unchecked.

The mechanism (MongoDB/etcd-style trace validation)

  1. examples/conservation_trace_gen.rs drives the real Inventory through seeded-random Add/Reduce sequences (deterministic LCG — no clocks, no deps; failed reduces = disabled actions = stutters, not recorded) and emits the abstract state after every operation.
  2. scripts/tla-trace-validate.py wraps each trace in a trace-following TLA+ spec (C == INSTANCE Conservation) and has TLC verify the [][C!Next]_specVars action property — every recorded transition must be a legal model step.
  3. tla.yml runs the validator's self-test, then validates 24 fresh traces per run (seed = github.run_id, printed for exact reproduction — continuous sampling of the dual direction).

Trustworthiness of the harness itself

The self-test proves both directions: a hand-checked legal trace is accepted and an illegal one is rejected (Action property ConformsToConservation is violated) — plus the generator's --corrupt mode is verified to fail the pipeline. A vacuously-green harness is the failure mode to fear; this one demonstrably detects violations.

Together with #1685/#1688: two-sided refinement checking — exhaustive on the model side, continuously sampled on the implementation side. Extension to other specs follows the same template (documented in RUST_MAPPING.md).

Verified locally with real TLC

Self-test OK · 8/8 real implementation traces conform · corrupted traces fail · clippy -D warnings + fmt clean. This PR triggers the TLA workflow itself, so the new step runs on this very PR.

🤖 Generated with Claude Code

…ction

The behavior-replay suite checks model -> implementation (every model behavior
implemented correctly, exhaustively). This adds the DUAL, implementation ->
model: seeded-random op sequences drive the REAL Inventory, the abstract state
is recorded after every operation, and TLC verifies each recorded transition
satisfies Conservation.tla's Next relation via the ConformsToConservation
action property ([][C!Next]_specVars over a trace-following spec). An
implementation transition the model forbids fails the property. Together the
two directions give two-sided refinement checking — exhaustive model-side,
continuously sampled implementation-side.

- examples/conservation_trace_gen.rs: deterministic generator (seeded LCG, no
  clocks/deps); failed reduces are treated as disabled actions (stutters) and
  not recorded; --corrupt breaks the final state for the negative self-check.
- scripts/tla-trace-validate.py: builds a trace-following TLA module + cfg per
  trace, INSTANCE Conservation, runs TLC; --self-test proves the harness both
  ACCEPTS a hand-checked legal trace and REJECTS an illegal one (a vacuously
  green harness is the failure mode to fear).
- tla.yml: new step runs the self-test then validates 24 fresh traces per run
  (seed = github.run_id, printed for exact reproduction); Rust toolchain added
  to the workflow for the generator.

Verified locally end-to-end with real TLC: self-test OK (illegal trace
rejected with 'Action property ConformsToConservation is violated'), 8/8
implementation traces conform, corrupted traces fail the run.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings July 2, 2026 16:32
@robcohen
robcohen requested a review from a team as a code owner July 2, 2026 16:32
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the missing “implementation → model” refinement check to the MBT layer by generating real Inventory traces and validating each recorded transition against the TLA+ Conservation model in CI, complementing the existing exhaustive “model → implementation” behavior replay.

Changes:

  • Added a Rust trace generator example (conservation_trace_gen) that drives real Inventory Add/Reduce sequences and emits abstract state traces.
  • Added a Python trace validator that wraps traces into a trace-following TLA+ module and has TLC check the Next action property.
  • Extended the tla.yml workflow and mapping docs to run and document the dual-direction trace validation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
spec/tla/RUST_MAPPING.md Documents the new dual-direction trace-validation approach and how it complements behavior replay.
scripts/tla-trace-validate.py New validator script that generates per-trace TLA+ modules/config and runs TLC action-property checking.
crates/rustledger-core/examples/conservation_trace_gen.rs New deterministic trace generator example for producing implementation traces from real Inventory.
.github/workflows/tla.yml Adds CI step to self-test the validator and validate fresh traces each run using a varying seed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/tla-trace-validate.py Resolved
Comment thread scripts/tla-trace-validate.py Resolved
Comment thread spec/tla/RUST_MAPPING.md Resolved
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 31ms ± 0.3ms 23.8 MB
beancount 866.9ms ± 10.4ms 50.7 MB
Comparison 28x faster 2.1x less

vs main branch (2026-07-02)

Metric main this PR Change
Time 39.8ms 31ms -22.1% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@robcohen
robcohen merged commit aaec316 into main Jul 2, 2026
47 checks passed
@robcohen
robcohen deleted the feat/tla-trace-validation branch July 2, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants