Skip to content

id(event-store): apply the groups fold on production ingest (#168) - #3725

Merged
dezren39 merged 2 commits into
mainfrom
queue/2952-168-groups-fold-ingest
Nov 1, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/2952-168-groups-fold-ingest

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Closes the production-ingest half of #168 (queue task 2952).

What

Production event-store ingest resolved group operations through the p2panda-auth membership layer alone, so the group rules that live in groups::fold — only an Admin changes a role or removes an Admin, a create may not repeat a member, a manager acts only through a chain from an owner — never gated a signed store event. A fold-refused operation applied in the store while group projections refused it.

event_store::resolve now:

  • bridges every group operation it can into the fold's event model — a create under Template::Custom with the default policy record (the record a signed store body cannot carry yet), member operations by member and access, after rewritten to the bridged operations each event causally follows;
  • folds them, and an operation the fold refuses with a voiding reason does not apply, however the membership layer judged it. Waiting/frozen refusals keep the membership verdict — the store's set may simply not hold the events the fold would need;
  • takes the roster of a folded group from the fold's GroupView, so a refused operation's target never shows as a member.

Since resolve() is the one derivation behind ingest, refresh/replay, late-body attach (attach_action) and sync batches, the gate is identical on every path, and it is a pure function of the stored set (verified across a reopen in tests).

Bridge limits (documented in the code)

  • A create is bridged only when it lists its author: the membership layer knows the creator only then, while the fold counts the creator as a member/Admin by construction and refuses a create that names it — so the author's entry is dropped for the fold. Creates not listing their author keep the membership verdict alone.
  • Operations naming a group as a member, and friendship/policy bodies the body codec does not carry, are not bridged; the fold judges those when they travel as group events.
  • A fold that errors on the bridged set gates nothing (membership verdict stands) rather than bricking the store.

Tests

New production-path tests (ingest_with_body with encoded bodies) in event_store::ingest:

  • test_a_managers_promote_is_refused_by_the_group_fold — a manager's promote (accepted by the membership layer) does not apply; the Admin creator's create/add/promote do; roster follows the fold.
  • test_the_fold_gate_survives_a_reopen_and_allows_a_managers_removal — the refusal is re-derived after reopen; a manager's removal of a plain member still applies.

Local (laptop): both new tests pass; cargo check --lib clean; the two changed files are rustfmt-clean.

Pre-existing failure (not this change)

The full --lib suite aborts at cli::tests::source_only_mode_is_opt_in_and_requires_world_mode with a stack overflow — reproduced on clean main bda855c66 with this change stashed. Same family as #3438; evidence posted there (comment 6559233631). CI on this PR is the arbiter for the rest of the suite.

🤖 Queue worker (repo-worker-code), lane A — task 2952. A shepherd task will follow CI/Codex and merge.


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

Production ingest resolved group operations through the p2panda-auth
membership layer alone, so the group rules that live in groups::fold —
only an Admin changes a role or removes an Admin, a create may not
repeat a member, a manager acts only through a chain from an owner —
never gated a signed store event: a fold-refused operation applied in
the store while group projections refused it.

resolve() now bridges every group operation it can into the fold's
event model (a create under the custom template with the default
policy record, the record a store body cannot carry yet; member
operations by member and access), folds them with the rest, and an
operation the fold refuses with a voiding reason does not apply.
Waiting and frozen refusals keep the membership verdict: the store's
set may simply not hold the events the fold would need. The fold's
projection also decides the roster of a group it folded, so a refused
operation's target never shows as a member.

The bridge covers the operations the body codec can express. A create
is bridged only when it lists its author (the membership layer knows
the creator only then, while the fold counts the creator as a member
by construction and refuses a create that names it, so the author's
entry is dropped for the fold). Operations naming a group as a member,
and friendship/policy bodies the codec does not carry, keep the
membership verdict alone. Because resolve() is the one derivation
behind ingest, refresh/replay, late-body attach and sync, the gate is
the same on every path.

Tests (production path, ingest_with_body with encoded bodies):
- a manager's promote, accepted by the membership layer, does not
  apply; the Admin's create/add/promote do, and the roster follows.
- the gate is re-derived after a reopen, and a manager's removal of a
  plain member still applies.

Pre-existing, not caused here: cli::tests::
source_only_mode_is_opt_in_and_requires_world_mode stack-overflows
the pkgs/id test binary on clean main bda855c too (same family as
#3438); the full --lib suite aborts at that test with or without
this change.
@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 14:27
@coderabbitai

coderabbitai Bot commented Nov 1, 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 14 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: 42728d8d-db87-441a-a52f-81f2dc0c8529
Commits

Reviewing files that changed from the base of the PR and between 27af74a and 5d89772.

Files selected for processing: 2
  • pkgs/id/src/event_store/ingest.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 commented Nov 1, 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-01T14:43:24.962021Z 5d89772 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.

@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: 3b99523d5a

ℹ️ 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 Outdated
Comment on lines +190 to +192
== Some(Reason::Voided)
{
applied.remove(&node.id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove fold-refused operations from membership authority

When a manager removes the group's Admin creator, the fold correctly refuses the removal, but this pass only deletes its ID from applied; the membership layer used in passes one and two still contains the removal. Consequently, a subsequent valid operation by that Admin is rejected by layer.is_effective even though the fold accepts it and the roster still lists the Admin. Merely masking the operation's applied flag does not prevent its authority changes from affecting descendants. Derive membership and descendant decisions with fold-refused operations represented as no-ops.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 5d89772 (shepherd, queue task 5665). The fold is now judged before the membership layer is built, and every operation the fold refuses with a voiding reason is fed to the layer as a no-op (Role::Other), so a refused removal no longer changes the authority descendants are judged against; pass three still removes voided operations from applied. Regression test: test_a_fold_refused_removal_does_not_strip_the_admins_authority — manager removes the Admin creator (refused, not applied), the Admin then removes the manager and it applies, roster = [Admin]. Passes on the laptop along with both pre-existing fold-gate tests.

Comment on lines +470 to +474
.and_then(|projection| projection.group(group))
{
let mut keys: Vec<AuthorKey> = view.members.keys().copied().collect();
keys.sort_unstable();
return keys;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reconcile membership acceptance before returning the fold roster

If a create lists its author Alice with Read access and Bob with Manage access, the bridge silently upgrades Alice to the fold's implicit Admin/Manage creator. Alice can then submit a removal of Bob that the membership layer rejects for insufficient access, while the fold accepts it. event_applied reports that removal as false, but this unconditional projection lookup returns a roster without Bob. Only use a projection whose membership changes agree with the authoritative applied decisions, or reject incompatible creator-access mappings before folding.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 5d89772 (shepherd, queue task 5665), taking the second option named in the finding: bridge() now rejects the incompatible creator-access mapping before folding — a create that lists its author below Manage does not bridge at all (the fold counts the creator as Admin by construction; the layer honours the listed access), so the group keeps the membership verdict alone and roster_of falls back to the layer roster, which agrees with the applied decisions by construction. Regression test: test_a_create_listing_its_author_below_manage_keeps_the_membership_roster — author listed Read removes the Manage member, removal does not apply, roster still lists both. Passes on the laptop.

, PR #3725 Codex P1+P2)

P1: judge the group fold before building the membership layer and feed
fold-refused (voiding) operations to the layer as no-ops, so a refused
removal of the Admin no longer strips the Admin authority that descendant
decisions are judged against. Pass three still removes voided operations
from applied.

P2: a create that lists its author below Manage no longer bridges into
the fold — the fold counts the creator as Admin by construction while the
layer honours the listed access, so the group keeps the membership
verdict alone and the roster cannot disagree with the applied decisions.

Regression tests for both scenarios in event_store::ingest::tests; the
two pre-existing fold-gate tests still pass.
@dezren39
dezren39 merged commit 60c325f into main Nov 1, 2026
1 check passed
@dezren39
dezren39 deleted the queue/2952-168-groups-fold-ingest branch November 1, 2026 14:42

@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: 5d89772967

ℹ️ 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 on lines +340 to +344
GroupAction::Promote { member, access } | GroupAction::Demote { member, access } => {
GroupBody::Member(MemberOp::SetRole {
member: member_key(member)?,
role: role_of(access),
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve directional semantics when bridging role changes

If Alice creates a group with Bob as Manage and Charlie as Read, then signs Promote(Bob, Read), the membership layer treats that promotion as a no-op, leaving Bob with Manage (this behavior is explicitly documented and used in membership/layer.rs:237-244). This bridge instead converts it into SetRole(Read), which groups/fold.rs:950-959 turns into a demotion. Bob's subsequent removal of Charlie is consequently refused by the fold as NotManager and suppressed by the resolver, although Bob still has authority under the original signed operations. Preserve the promotion/demotion direction instead of translating both into unconditional role assignments.

Useful? React with 👍 / 👎.

dezren39 pushed a commit that referenced this pull request Nov 1, 2026
…n concurrent removals (#3787)

Since the groups fold was wired into the event store's resolution
(#3725), its member judge has pre-empted the membership layer on
concurrent removals: it judges a removal against the state built by
the canonically earlier events, so the second half of a concurrent
removal tangle is refused by whichever side the ID order struck
first — NotActive for a removed author (mutual removal), NotAdmin
for a removal of the creator by a concurrently removed manager
(three-cycle), NotAMember for a target a concurrent removal already
struck (concurrent re-add, whose refusal then corrupts the dependent
re-add's frontier in the fold's own layer). The fold's roster and
voiding verdicts then disagree with the S2 outcomes the membership
layer reaches on its own, and voiding_scenarios fails 3 of 12 in the
nix build's checkPhase, blocking nixos-rebuild switch.

A removal in a non-friendship group whose author or target is named
by another removal concurrent with it — neither in the other's
causal past — is now handed to the membership layer with none of the
judge's current-state pre-checks; the layer judges authority at the
operation's position and arbitrates the tangle. Unilateral removals
keep every existing check: a manager's removal of an Admin is still
refused, because the Admin's answering removal is causally later,
not concurrent.
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