Repository navigation
fix(id/groups): let the membership layer arbitrate removals tangled in concurrent removals (#3787) #3871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(id/groups): let the membership layer arbitrate removals tangled in concurrent removals (#3787) #3871
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -881,8 +881,24 @@ impl Engine { | |
| if record.dissolved_by.is_some() { | ||
| return Err(Refusal::Dissolved); | ||
| } | ||
| let Some((author, author_role)) = self.effective_author(by_id, group, event) else { | ||
| return Err(Refusal::NotActive); | ||
| // A removal tangled in a concurrent removal is the membership layer's call, not this | ||
| // judge's (design §6.2): the layer judges authority at an operation's causal position | ||
| // and arbitrates concurrent removals — the other half of a mutual removal takes | ||
| // effect, and a removal cycle removes every member. Judged against the state built | ||
| // so far instead, the second half of such a tangle is refused for whoever the | ||
| // canonical order happened to strike first: NotActive when its author was removed, | ||
| // NotAMember when its target was, NotAdmin when its target is the creator. So an | ||
| // entangled removal is handed to the layer with no pre-checks of this judge's own. | ||
| // Only true concurrency entangles: a removal in the event's causal past, or one the | ||
| // event is in the past of, leaves the checks below in force — a manager's unilateral | ||
| // removal of an Admin is still refused. Friendships keep their own path: a removal | ||
| // there dissolves, and the dissolve machinery owns the verdict. | ||
| let entangled = | ||
| record.friendship.is_none() && self.removal_entangled(by_id, group, event, op); | ||
| let (author, author_role) = match self.effective_author(by_id, group, event) { | ||
| Some(found) => found, | ||
| None if entangled => (event.author, Role::Pull), | ||
| None => return Err(Refusal::NotActive), | ||
| }; | ||
| let is_admin = author_role == Role::Admin; | ||
| let is_manager = author_role >= Role::Manage; | ||
|
|
@@ -915,6 +931,20 @@ impl Engine { | |
| }) | ||
| } | ||
| MemberOp::Remove { member, successor } => { | ||
| if entangled { | ||
| return Ok(Decision { | ||
| group, | ||
| action: Some(GroupAction::Remove { | ||
| member: GroupMember::Individual(AuthId::Key(member)), | ||
| }), | ||
| effect: Effect::Remove { | ||
| member, | ||
| dissolves: record.policy.on_member_removed == OnMemberRemoved::Dissolve, | ||
| successor, | ||
| by: event.id, | ||
| }, | ||
| }); | ||
| } | ||
| if !self.listed(&group, &member) { | ||
| return Err(Refusal::NotAMember(member)); | ||
| } | ||
|
|
@@ -969,6 +999,30 @@ impl Engine { | |
| } | ||
| } | ||
|
|
||
| /// Whether the removal `op` in `event` is tangled in a concurrent removal: another | ||
| /// removal in the same group, concurrent with `event` — neither in the other's causal | ||
| /// past — names the event's author or the member `op` removes. A removal the event | ||
| /// causally follows, and one that causally follows the event, do not entangle it. | ||
| fn removal_entangled( | ||
| &self, | ||
| by_id: &BTreeMap<Hash, &Event>, | ||
| group: Hash, | ||
| event: &Event, | ||
| op: MemberOp, | ||
| ) -> bool { | ||
| let MemberOp::Remove { member, .. } = op else { | ||
| return false; | ||
| }; | ||
| let past = causal_past(by_id, &event.after); | ||
| by_id.values().any(|other| { | ||
| other.id != event.id | ||
| && other.group == Some(group) | ||
| && !past.contains(&other.id) | ||
| && !causal_past(by_id, &other.after).contains(&event.id) | ||
| && matches!(removed_member(other), Some(target) if target == event.author || target == member) | ||
|
Comment on lines
+1021
to
+1022
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a group with one early removal followed by N causally chained policy events, this predicate rebuilds the complete causal past of every subsequent policy event before checking whether it is even a removal. Those descendants pass Useful? React with 👍 / 👎. |
||
| }) | ||
| } | ||
|
|
||
| pub(super) fn record(&self, group: &Hash) -> Result<&Record, Refusal> { | ||
| self.groups.get(group).ok_or(Refusal::NoGroup) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When two non-Admin managers concurrently remove the same Admin,
removal_entangledreturns true for both because they share a target, and this early return bypasses theNotAdminguard below. Neither downstream layer restores that protection:manage_chainchecks only Manage authority, and the membership layer represents Admin as Manage (access_level/access_for). Consequently, managers can remove an Admin simply by issuing concurrent removals, even though either removal alone is forbidden. Preserve the Admin-versus-manager restriction at the operation's causal position instead of dropping it for every entangled removal.Useful? React with 👍 / 👎.