Repository navigation
fix(id): canonical winner for concurrent group creates (#165) - #4099
Conversation
Concurrent creates of one group were decided by arrival order: the membership gate crowned the first create applied, and event-store resolve fed the layer in stored order, so replicas could diverge and an attacker create naming a derived friendship group ID could claim it by arriving first. - gate: a create that causally follows the standing create stays refused (sequential GroupExists); a concurrent create is decided by the canonical rule -- smaller event ID wins -- via a new Admission::Displace when the winner arrives second. - layer: on displacement, re-decide every held event in canonical order (causal, ties to smaller ID, as in the groups fold) and return refreshed outcomes; the loser ends refused. - resolve: causal_order takes the smallest ready event ID first, so the layer it builds agrees with the fold on the winner. Tests: gate unit tests for concurrent larger/smaller and sequential creates; layer tests feeding concurrent named (derived-ID) creates in both arrival orders asserting identical members and effectiveness; resolve test that causal_order is invariant under stored permutation.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 41 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dee716b007
ℹ️ 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".
…ayer re-decision, linear causal_order P1 (membership/layer.rs): the gate crowned the concurrent-create winner by comparing raw event IDs, but canonical precedence (causal order, smallest ready ID first) can place a larger-ID create first when the smaller-ID create causally follows a larger-ID ancestor -- so admission and replay crowned different winners depending on arrival order. The gate now defers every concurrent create to the layer, which re-decides its held events in canonical order; the first create decided there stands. Adds a layer regression test feeding the interleaved-ancestor case in four arrival orders. P2 (event_store/resolve.rs): causal_order rescanned every node after each heap placement, making ordering a full history quadratic. It now uses dependency counts and child adjacency lists (as the groups fold does); absent-dependency and cycle errors are preserved. Adds a long-chain test.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d307468dc3
ℹ️ 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".
The long-chain causal_order test passed a slice of a temporary array (E0716, caught by the native arm64 CI job on PR #4099): bind the predecessor list to a local Vec so node() copies it while it lives. Test-only change; no production code touched.
fix(id): canonical winner for concurrent group creates (#165)
Closes the arrival-order race in issue #165 (queue task 2950).
Problem. Concurrent creates of the same group settled by arrival order: the membership gate (
gate.rs) crowned the first create applied ("The first create stands"), and event-store resolve fed the membership layer in stored order (causal_orderscanned nodes in position order). Replicas receiving the same two creates in different orders crowned different winners, and a stranger's create naming a derived friendship group ID could claim it by arriving first. The groups fold already defines the canonical rule — causal order, ties to the smaller event ID — but admission and resolve did not share it.Change.
membership/gate.rs: a create that causally follows the standing create (standing create reachable through its auth dependencies) stays refused — sequentialGroupExistsbehavior is unchanged. A concurrent create is decided by the canonical rule: the larger ID is refused; the smaller ID returns the newAdmission::Displace(standing)when it arrives second.membership/layer.rs: onDisplace, the layer re-decides every event it holds in canonical order (the fold's Kahn order) and returns refreshed outcomes — the latest outcome per event is its truth, so the displaced create's earlierAppliedis superseded byRefused(GroupExists)and all later decisions are rebuilt on the winner. The layer now retains received events to make the replay possible.event_store/resolve.rs:causal_orderpicks the smallest ready event ID first (heap, mirroringgroups/fold.rs), so the membership layer resolve builds agrees with the fold on the winner whatever order events were stored in.Tests.
causal_orderis invariant under stored-position permutation and orders concurrent roots by event ID.CI runs the pkgs/id suites on this PR; results reported on issue #165.
Need help on this PR? Tag
@codesmith-botwith what you need.