Skip to content

spec(tla): pad-directive model + behavior replay against process_pads - #1696

Merged
robcohen merged 1 commit into
mainfrom
feat/tla-pad-spec
Jul 2, 2026
Merged

robcohen merged 1 commit into
mainfrom
feat/tla-pad-spec

Conversation

@robcohen

@robcohen robcohen commented Jul 2, 2026

Copy link
Copy Markdown
Member

FV backlog (roadmap "Next" item): the pad directive — beancount's subtlest directive — gets a TLA+ model and full behavior-replay conformance.

Model

PadCorrect.tla (161 states, TLC-checked): pad arms → next balance absorbs the difference (pad = asserted − actual) → newer pads replace pending ones. Single account/currency; sub-account summing deliberately out of scope (integration-tested).

Replay — 1,044 behaviors (4,082 escalated) against the real process_pads

Synthesized pad amounts must match the model exactly; final balances must match. Building it surfaced two implementation semantics the suite now pins:

  1. Unused pad = error: a behavior ending with an armed pad must produce exactly the beancount-aligned unused-pad error — no more, no less.
  2. Opened-accounts precondition: process_pads silently ignores postings to unopened accounts (the validator owns that error class) — the replay opens accounts first, as any real ledger would; the precondition is documented in the test.

Wiring (all four layers, enforced by the coverage lint)

Generator derive (with TLA boolean normalization — "FALSE" is truthy in Python, a trap now documented) · corpus · lint replay-file list · escalation entry · RUST_MAPPING row · tla.yml model-check loop. This PR triggers the TLA workflow: lint + 17-spec model check + corpora lockstep + trace validation all run on it.

Verified locally: TLC clean · both corpus scales green · clippy -D warnings + fmt clean.

🤖 Generated with Claude Code

New PadCorrect.tla (161 states, TLC-checked): a pad directive arms a pending
pad; the next balance assertion absorbs the difference by synthesizing a
padding transaction (pad amount = asserted - actual); a newer pad replaces a
pending one. Single account/currency; the implementation's sub-account
summing semantic is out of model scope (pinned by integration tests).

Replay (rustledger-booking/tests/, 1,044 behaviors; 4,082 at escalated
bounds): model-legal pad/txn/balance sequences run through the real
process_pads. Conformance: synthesized pad amounts exactly match the model,
final balance matches, and — two semantics the replay surfaced and now pins:

- a behavior ending with an ARMED pad must produce exactly the
  implementation's unused-pad error (beancount-aligned), nothing else;
- process_pads only tracks inventories for Open-ed accounts (postings to
  unopened accounts are silently ignored — the validator owns that error
  class), so the replay opens accounts first as any real ledger would.

Wired through all four layers: generator derive (with TLA boolean
normalization — "FALSE" is truthy in Python), corpus, replay-file list in
the coverage lint, escalation-table entry, RUST_MAPPING row, tla.yml
model-check loop.

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

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 34.5ms ± 0.5ms 23.8 MB
beancount 765ms ± 4ms 50.6 MB
Comparison 22.2x faster 2.1x less

vs main branch (2026-07-02)

Metric main this PR Change
Time 39.8ms 34.5ms -13.3% 🟢
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

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 a new TLA+ spec and exhaustive behavior-replay suite for Beancount-style pad directive semantics, wiring it into the existing FV toolchain (generator, corpora, coverage lint, escalated replay, and CI model-check loop) and into rustledger-booking tests to validate process_pads conformance.

Changes:

  • Introduces PadCorrect TLA+ model + TLC config for pad lifecycle semantics (single account/currency).
  • Adds a new rustledger-booking behavior-replay integration test that replays the PadCorrect corpus against process_pads.
  • Wires PadCorrect through the FV scripts and CI workflow (coverage lint list, behavior derivation, escalated bounds, model-check loop) and adds required test dependencies.

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spec/tla/RUST_MAPPING.md Documents PadCorrect corpus coverage and replay target
spec/tla/PadCorrect.tla New TLA+ spec modeling pad arming and balance absorption semantics
spec/tla/PadCorrect.cfg TLC config/bounds and invariant for PadCorrect
scripts/tla-escalated-replay.py Adds escalated bounds for PadCorrect
scripts/tla-coverage-check.py Includes booking replay test file in coverage lint inputs
scripts/tla-behaviors.py Adds step derivation logic and registry entry for PadCorrect
crates/rustledger-booking/tests/tla_behavior_replay.rs New corpus replay test validating process_pads behavior
crates/rustledger-booking/Cargo.toml Adds serde_json for the new replay test
Cargo.lock Locks the added serde_json dependency in booking dev-deps
.github/workflows/tla.yml Ensures PadCorrect is included in CI model-check loop

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

Comment thread spec/tla/RUST_MAPPING.md Resolved
@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

@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!

@robcohen
robcohen merged commit d688ee3 into main Jul 2, 2026
54 checks passed
@robcohen
robcohen deleted the feat/tla-pad-spec branch July 2, 2026 20:11
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