Skip to content

feat(id): store-wired writer-set expansion — expand/expand_retro over the membership layer (#4998) - #6787

Merged
dezren39 merged 2 commits into
mainfrom
queue/4998-writer-set-expansion
Nov 7, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/4998-writer-set-expansion

Conversation

@dezren39

@dezren39 dezren39 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Closes #4998 (writer-set spec §9 item 2, slice 2 of #3789).

Implements the store-wired expansion lane code-c's triage on #4998 routed: PR #6672 (for #5545) landed the snapshot-level view::expand_set, but the acceptance API — expand(set_version) / expand_retro(set_version) expanding through is_member_at / access_at_position pinned to the set version's frontier — plus spec tests 1–7 and the idset.rs module-doc update were still unbuilt.

What changed

  • id-core membership layer — Membership::members_at_position + members_at_position_shared: the frontier-pinned enumeration counterpart of access_at_position (mirrors managers_at_position). Returns key members only, sorted — group-valued members are not followed, which is the one-level flattening of §D3/D4. Never reads the live members(group) roster.
  • idset::expand (new) — Expander over a Membership layer + SetVersion { set, frontier, resolution }:
    • resolves each referenced group at the pinned frontier, maps access → Role the way the groups fold does (Admin shows as Manage — the layer records it apart), caches resolutions under the §4.5 key (group, frontier, R), and delegates entry semantics (one-level groups, role_min, exclusions-win, per-entry include_history) to view::expand_set;
    • expand / expand_retro return BTreeSet<AuthorKey> — authors only, no counting path;
    • exclusions are applied by filtering admitted authors through ExpandedWriters::contains — the first test run caught that explicit_authors() alone does not subtract exclusions;
    • a Public admission cannot be materialized as a set of authors, so it is refused with ExpandError::PublicEntry instead of silently returning only the named authors (callers needing the public shape use view's ExpandedWriters).
  • idset.rs module doc — no longer states expansion is absent; it points at expand/view beside the types.
  • Tests — pkgs/id/tests/writer_set_expansion.rs: spec tests 1–7 named as such (order-independence; frontier-pinning; unchanged by a later group-membership event, recomputed with a fresh expander against a changed live roster; expand_retro ⊆ expand per entry + empty retro with no history entries; fork-invalidated grant changes the expansion — fed as Role::Other exactly as event_store/resolve.rs feeds fork-excluded actions — and the cache keys on R via cache_entries(); role_min at the frontier vs after a later promotion; exclusion removes an admitted writer and a never-admitted exclusion is a no-op), plus the public-entry refusal. Oracle: the membership layer fed a known causal history (per the testing doctrine, each test names its oracle in the file header).

Verification

  • cargo test -p id --test writer_set_expansion --test writer_set_projection — 8/8 + 4/4.
  • cargo test -p id -p id-core (laptop) — 3179 passed, 0 failed, 33 ignored, 50 test binaries. (A comment-ordering fix in layer.rs landed after that run; it touches no code.)

🤖 Queue worker lane code-t, fallback mode (queue backend down, #6619).


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

… the membership layer (#4998)

Spec §9 item 2 (slice 2 of #3789). Adds Membership::members_at_position(+_shared) in id-core — the frontier-pinned enumeration counterpart of access_at_position, key members only (one-level flattening, §D4) — and idset::expand::Expander, which resolves each referenced group at the set version's pinned frontier under its resolution state R, caches it under the §4.5 key (group, frontier, R), and delegates entry semantics to view::expand_set. expand/expand_retro return authors only; exclusions are applied by filtering the admitted set through ExpandedWriters::contains (the raw explicit_authors set does not subtract exclusions). A public admission cannot be materialized as a set of authors and is refused with ExpandError::PublicEntry. The idset module doc no longer states expansion is absent. Tests: pkgs/id/tests/writer_set_expansion.rs carries spec tests 1-7 (order-independence, frontier-pinning, reproducibility against a later membership event, retro subset + empty-without-history, fork-invalidated grant + cache key on R, role_min at the frontier, exclusion wins + never-admitted no-op) plus the public refusal. cargo test -p id -p id-core: 3179 passed, 0 failed.
@dezren39
dezren39 requested a review from a team as a code owner November 7, 2026 04:53
@coderabbitai

coderabbitai Bot commented Nov 7, 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 31 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: c563c58b-2e33-4ba7-92d5-df666d1692b9
Commits

Reviewing files that changed from the base of the PR and between 2c30bb8 and 9e0e5f4.

Files selected for processing: 4

  • pkgs/id/crates/id-core/src/membership/layer.rs
  • pkgs/id/src/idset.rs
  • pkgs/id/src/idset/expand.rs
  • pkgs/id/tests/writer_set_expansion.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 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T05:17:38.639886Z 9e0e5f4 Manual request
ℹ️ 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: d19a9021ca

ℹ️ 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 +138 to +139
#[test]
fn test_expand_is_order_independent() {

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 Cover expansion invariants with generated property tests

The new suite checks order independence, frontier pinning, and expand_retro(v) ⊆ expand(v) only with fixed examples; existing property suites do not exercise the new expansion APIs. The root AGENTS.md testing doctrine explicitly requires property tests for meaningful invariants and says examples do not replace them. Add generated entry permutations, role/history/exclusion combinations, and causal histories that check these guarantees against the declared oracle.

AGENTS.md reference: AGENTS.md:L41-L45

Useful? React with 👍 / 👎.

@dezren39 dezren39 Nov 7, 2026 •

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 9e0e5f4. Added a proptest property suite at the end of pkgs/id/tests/writer_set_expansion.rs (128 cases each), with the oracle for each property stated in its comment per the testing doctrine:

  • prop_expand_is_order_independent — generated entry/exclusion lists (key/group/public shapes, generated role_min and include_history) expand identically under permutation, including refusing identically;
  • prop_expand_retro_is_subset_of_expand — the retro subset invariant over generated sets;
  • prop_expand_is_frontier_pinned_under_generated_history — a generated add/remove/promote history chained after the pin never moves the pinned expansion; oracle is the expansion evaluated before the history is appended.

The seven spec tests remain as the named example/acceptance tests. Suite: writer_set_expansion 13/13, writer_set_projection 4/4.

Comment on lines +198 to +202
let members: BTreeMap<AuthorKey, Role> = self
.membership
.members_at_position(&version.frontier, group)?
.into_iter()
.map(|(author, access)| (author, access_role(&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 administrator roles before applying role_min

For a group entry with role_min: Role::Admin, this mapping assigns every administrator Role::Manage, so view::role_at_least rejects all of them because Manage < Admin. Consequently, administrator-only admissions always expand to an empty set, and administrator-only exclusions silently exclude nobody. The groups fold preserves this distinction by consulting record.admins before falling back to access_role (groups/fold.rs:1512–1516); expansion likewise needs the administrator metadata resolved at the pinned frontier rather than access levels alone.

Useful? React with 👍 / 👎.

@dezren39 dezren39 Nov 7, 2026 •

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 9e0e5f4, with one deliberate approximation. You're right that the layer-backed snapshot topped every admin out at Manage, so an Admin threshold admitted nobody.

What the wiring can and cannot know: expand resolves groups through the membership layer (§4.5's sanctioned entry points), and that layer records Admin as Manage — the fold keeps Admin apart in record.admins precisely because the layer has no Admin bit. So the fix evaluates an Admin role_min at Manage (clamp_admin_thresholds in idset/expand.rs): admins are admitted instead of nobody, pinned by test_expand_role_min_admin_is_answered_at_manage_the_layers_top_role.

The remaining inexactness — a non-admin manager also passes an Admin threshold — needs the fold's admin-at-frontier state plumbed into expansion, which no caller can supply to the layer today. That's filed as #6798 with the design sketch, and the limitation is stated in the expand module doc rather than hidden.

Comment thread pkgs/id/src/idset/expand.rs Outdated
Comment on lines +152 to +154
if admits_public(set, retro) {
return Err(ExpandError::PublicEntry);
}

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 Honor public exclusions before refusing materialization

For the supported emergency-stop configuration entries = [Public], excludes = [Public], this early return produces ExpandError::PublicEntry even though exclusions make the result the finite empty set. The existing projection explicitly supports this case (view::test_public_exclusion_admits_nobody), and the writer-set design §D6 requires its expansion to be empty. Check for the public exclusion before refusing a public admission so both expand and history-enabled expand_retro can return the correct empty result.

Useful? React with 👍 / 👎.

@dezren39 dezren39 Nov 7, 2026 •

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 9e0e5f4. expand_narrowed now checks for a public exclusion before the public-admission refusal: the §D6 emergency stop makes the expansion the finite empty set, so expand and expand_retro return Ok(empty) for entries = [Public], excludes = [Public] (and for named admissions under a public exclusion). Pinned by test_expand_public_exclusion_admits_nobody_not_refused. A public admission with no public exclusion still refuses with PublicEntry, since that expansion genuinely cannot be materialized as a set of authors.

…sion empty set, Admin threshold at Manage

P1: proptest property suite for the expansion invariants (order-independence over generated entry/exclusion permutations, expand_retro subset, frontier-pinning under generated add/remove/promote histories), each with its oracle stated. P2a: a public exclusion (the §D6 emergency stop) now yields the finite empty set instead of ExpandError::PublicEntry. P2b: role_min Admin is evaluated at Manage — the membership layer records Admin as Manage, so admins are admitted instead of nobody; the approximation (non-admin managers also pass an Admin threshold) is documented in the module doc and pinned by test_expand_role_min_admin_is_answered_at_manage_the_layers_top_role. Targeted: writer_set_expansion 13/13, writer_set_projection 4/4.
@dezren39

dezren39 commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

@codex review — fixes for the three findings are in 9e0e5f4; each finding thread has a reply with details.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 9e0e5f43fc

ℹ️ 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".

@dezren39
dezren39 merged commit 4cc0f66 into main Nov 7, 2026
4 checks passed
@dezren39
dezren39 deleted the queue/4998-writer-set-expansion branch November 7, 2026 05:18
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.

fix(id): writer-set expansion — expand/expand_retro over group grants (spec slice 2 of #3789)

1 participant