Skip to content

crdt example: property-based law checks over the executable merge#32

Open
pyrex41 wants to merge 1 commit into
mainfrom
claude/backpressure-authz-durable-0wu27q
Open

crdt example: property-based law checks over the executable merge#32
pyrex41 wants to merge 1 commit into
mainfrom
claude/backpressure-authz-durable-0wu27q

Conversation

@pyrex41

@pyrex41 pyrex41 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Follow-up to the CRDT example. Its README is honest that tier (c)'s proofs are
about an axiomatized join, not the shipped merge (the model↔code gap), and
tier (b) only checked the laws on a handful of hand-picked states. This PR does
the cheapest thing that narrows that gap: property-based checking of the
executable merge over thousands of random states.

Changes

  • crdt.shen — add the doc-* semilattice laws. The LWW-Map (doc) is the
    CRDT the demo actually uses, but only gc-* and lww-* had law predicates.
    Adds doc-eq? (order- and duplicate-independent, via an effective-field
    comparison mirroring gc-eq?) plus doc-idempotent? / doc-commutative? /
    doc-associative?. Still loads clean under (tc +).
  • selftest.lua — a new 2b. laws by PROPERTY section. A seeded PRNG
    generates random G-Counters, registers, and docs over small alphabets (so ids
    and keys collide and clocks tie — the adversarial corners), then runs all nine
    laws over 2000 cases each (18k checks). On failure it prints a reproducible
    counterexample. I confirmed the harness can go red (pointing it at a non-law
    reports a violation immediately), so the green result is meaningful.
  • README.md — tier (b) reframed as property-based; the honest-scope note
    now says the property run narrows the model↔code gap without claiming a
    universal proof over the representation.

Why this and not a full inductive proof

Re-deriving the semilattice axioms from doc-merge's definition (induction over
the field-list representation) would close the gap, but that's real proof
engineering and out of scope for an example. Property-testing the shipped merge
on thousands of random states is the high-value, low-cost step — and it's the
exact bug class (silent replica divergence on inputs no one hand-picked) these
laws exist to catch.

Port suite green (467/467); luajit examples/crdt/selftest.lua green.

🤖 Generated with Claude Code


Generated by Claude Code

Follow-up to the CRDT example. Tier (b) previously checked the semilattice
laws on a handful of hand-picked states — instance checking. This adds
property-based checking over 2000 random states each (seeded PRNG, so a failure
prints a reproducible counterexample), which is the cheapest way to narrow the
model<->code gap the README's tier (c) is honest about not closing: the SHIPPED
merges are now exercised on thousands of random inputs, not four.

- crdt.shen: add the doc-* semilattice laws (doc-eq? via an order/duplicate-
  independent effective-field comparison, plus doc-idempotent?/commutative?/
  associative?). The LWW-Map is the CRDT the demo actually uses, so proving its
  merge laws is the highest-value part; previously only gc-* and lww-* had them.
- selftest.lua: a "2b. laws by PROPERTY" section generating random G-Counters,
  registers, and docs over small alphabets (so ids/keys collide and clocks tie —
  the adversarial corners), running all nine laws over 2000 cases each. 18000
  checks; verified the harness can go red (a non-law reports a counterexample).
- README: tier (b) reframed as property-based; the honest-scope note now says
  the property run *narrows* the model<->code gap without claiming a universal
  proof over the representation.

Port suite green (467/467); crdt selftest green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CC5aXvUTaaNgfGHQJjGsvX
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