Skip to content

feat(C3 partial): LWW-Register semilattice property tests (3 more)#1424

Merged
AceHack merged 1 commit intomainfrom
otto/c3-lwwregister-properties-2026-05-03
May 3, 2026
Merged

feat(C3 partial): LWW-Register semilattice property tests (3 more)#1424
AceHack merged 1 commit intomainfrom
otto/c3-lwwregister-properties-2026-05-03

Conversation

@AceHack
Copy link
Copy Markdown
Member

@AceHack AceHack commented May 3, 2026

Summary

Three FsCheck properties for LwwRegister, completing the third CRDT in the C3 list (after PN-Counter #1420 and OR-Set #1423):

  • LWW-register merge is commutative
  • LWW-register merge is idempotent
  • LWW-register merge is associative

LwwRegister.Merge picks larger timestamp; ties broken by replica-id (lexicographic ordinal) for determinism. The semilattice laws hold because (timestamp, replica) is a total order with deterministic tie-breaking.

Math-proofs assessment matrix C3 row: running total 9 of ~15 target after this PR (G-Counter already had 3; +PN-Counter 3 +OR-Set 3 +LWW 3).

Test plan

  • All 3 properties pass: dotnet test --filter "FullyQualifiedName~LWW-register" → 3 passed in 97ms.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 3, 2026 15:27
@AceHack AceHack enabled auto-merge (squash) May 3, 2026 15:27
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f3867dd42d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/Tests.FSharp/Properties/Math.Invariants.Tests.fs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds FsCheck semilattice-law properties for LwwRegister to extend the CRDT math-invariants test suite (continuing the C3 “math proofs” coverage work alongside prior PN-Counter and OR-Set additions).

Changes:

  • Add FsCheck properties asserting LwwRegister.Merge is commutative, idempotent, and associative.
  • Add a helper equality function for LwwRegister<int> since the type disables structural equality.

Comment thread tests/Tests.FSharp/Properties/Math.Invariants.Tests.fs
Comment thread tests/Tests.FSharp/Properties/Math.Invariants.Tests.fs Outdated
AceHack added a commit that referenced this pull request May 3, 2026
…ie-break Fact

3 P2 reviewer comments on #1424 surfaced a real issue: LwwRegister.Merge
is left-biased on FULL key equality (Timestamp=Timestamp AND
Replica=Replica), so commutativity FAILS for that corner. The original
property test used independent NonEmptyString-generated replica ids;
FsCheck almost never hit the equal-key case, so the property "passed"
by chance not by design.

Fix:
- Constrained the commutative + associative properties to use
  hard-coded distinct replica ids ("r1", "r2", "r3"). That makes
  full-key equality impossible, which is the LWW invariant that
  each (Timestamp, Replica) pair is a unique write-identity.
- Renamed properties to "merge is commutative under unique replica
  ids" + "merge is associative under unique replica ids" so the
  domain restriction is visible in the test name.
- Added [<Fact>] "LWW-register merge tie-breaks left on equal
  (timestamp, replica)" that exercises the deliberate left-bias
  contract — the asymmetric corner gets pinned as a unit test
  (not a property) because it's asymmetric by design.

The rationale comment now correctly documents the LWW invariant
and the deliberate left-bias on full-key equality.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Three FsCheck properties for LwwRegister, mirroring the G-Counter
/ PN-Counter / OR-Set pattern:
- LWW-register merge is commutative
- LWW-register merge is idempotent
- LWW-register merge is associative

LwwRegister.Merge picks larger timestamp; ties broken by replica-id
(lexicographic ordinal) for determinism. The semilattice laws hold
because (timestamp, replica) is a total order with deterministic
tie-breaking.

Math-proofs assessment matrix C3 row: closes 3 more after PN-Counter +
OR-Set (running total: 9 of ~15 target).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 3, 2026 15:36
@AceHack AceHack force-pushed the otto/c3-lwwregister-properties-2026-05-03 branch from 552fdd6 to d56e677 Compare May 3, 2026 15:36
@AceHack AceHack merged commit 3216278 into main May 3, 2026
27 of 28 checks passed
@AceHack AceHack deleted the otto/c3-lwwregister-properties-2026-05-03 branch May 3, 2026 15:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment on lines +167 to +169
// A separate property below exercises the deliberate tie-breaking
// (equal timestamps + equal replicas) to lock the deterministic
// left-bias contract; that one uses lwwEqual on the whole state.
Comment on lines +202 to +204
// merge is intentionally left-biased — picks the left argument.
// This is the documented determinism contract; commutativity
// does NOT hold in this corner. Pinned as a [<Fact>] (not
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