Skip to content

fix(id): canonical winner for concurrent group creates (#165) - #4099

Merged
dezren39 merged 3 commits into
mainfrom
queue/2950-165-concurrent-create-winner
Nov 2, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/2950-165-concurrent-create-winner

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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_order scanned 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 — sequential GroupExists behavior is unchanged. A concurrent create is decided by the canonical rule: the larger ID is refused; the smaller ID returns the new Admission::Displace(standing) when it arrives second.
  • membership/layer.rs: on Displace, 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 earlier Applied is superseded by Refused(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_order picks the smallest ready event ID first (heap, mirroring groups/fold.rs), so the membership layer resolve builds agrees with the fold on the winner whatever order events were stored in.

Tests.

  • gate: concurrent create with larger ID refused; with smaller ID displaces; sequential create refused even with the smaller ID.
  • layer: concurrent creates naming a derived group ID (neither event's own ID), fed in both arrival orders, converge to identical members with the canonical winner effective and the loser refused; sequential named create refused even with the smaller ID.
  • resolve: causal_order is 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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

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.
@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 00:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T01:34:41.462461Z d307468 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d3f7f05c-0e44-4302-953d-16236184d51d
Commits

Reviewing files that changed from the base of the PR and between 7a0da2f and 441f857.

Files selected for processing: 3
  • pkgs/id/crates/id-core/src/membership/gate.rs
  • pkgs/id/crates/id-core/src/membership/layer.rs
  • pkgs/id/src/event_store/resolve.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

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

Copy link
Copy Markdown

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: 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".

Comment thread pkgs/id/src/event_store/resolve.rs Resolved
…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.

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

Copy link
Copy Markdown

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: 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.
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.

1 participant