From 8abd9129176dda3c2dc29701a5737bf39caa6c22 Mon Sep 17 00:00:00 2001
From: Heimdall
Date: Fri, 6 Nov 2026 21:26:13 +0000
Subject: [PATCH 001/113] docs: guest accounts design (role field, invite,
grants, leave and erase)
Co-Authored-By: Claude Sonnet 5.5
---
docs/guest-accounts.md | 255 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 255 insertions(+)
create mode 100644 docs/guest-accounts.md
diff --git a/docs/guest-accounts.md b/docs/guest-accounts.md
new file mode 100644
index 0000000..3044056
--- /dev/null
+++ b/docs/guest-accounts.md
@@ -0,0 +1,255 @@
+# Guest accounts
+
+Status: **design, nothing implemented.** Written for `eureka-body:follow_up:bifrost-guest-accounts` under
+`eureka-body:ruling:guest-arrival-bifrost` (Meta: guests need no Matrix account of their own; they get a GameCult
+account through Bifrost with a guest role, and move to member, user or patron on the same account seamlessly),
+building on `eureka-body:ruling:bifrost-owns-accounts-invite-only`. I could not `view` either ruling from the
+Heimdall mind, so their text here is the follow-up brief's wording; check it against the rulings. First guest:
+sletz (Faust developer). Aqua decides on `#aquasynth` access, so the first grant list is hers to name.
+
+Read at Bifrost `bf8ff62` (`src/Bifrost.Web/Domain/BifrostModels.cs`, `Features/Membership`, `Features/Heimdall`,
+`Features/Oidc`, `Features/Motions`, `Features/ConceptVotes`, `Pages/App/Members`) and Heimdall `575be9c`
+(`src/app-profiles.ts`, `docs/app-profiles/bifrost.md`).
+
+## The shape in one paragraph
+
+A guest is a `UserAccount` like any other: same `Id` (the OIDC `sub`), same `NormalizedBifrostIdentity` (the Matrix
+localpart, minted once). What is new is one field, `Membership.Role`, with four values: `guest`, `user`, `patron`,
+`member`. Role is the single place that says what an account may do. A role change rewrites that field and writes a
+receipt; it never creates a second account, never re-mints the identity, so chat history, grants and the Matrix
+user stay attached.
+
+## What exists today
+
+- `UserAccount.Id` is the OIDC subject; `NormalizedBifrostIdentity` is `preferred_username` and, through MAS, the
+ Matrix localpart (`docs/oidc-issuer.md`). `HeimdallAccountId` is only an authenticator handle.
+- `Membership.Status` is `Authenticated | PendingApproval | Active | Suspended`. `CurrentBifrostActor.IsActiveMember`
+ (`Status == Active`) is the one test behind `/App`, bridge transport (`BridgeActionService` l.492), motion votes
+ (`EffectiveVotingWeight`, `MotionGovernanceService` l.72), concept votes (`VoterIdentity.For`, member versus
+ account class) and the OIDC authorize, token and userinfo endpoints (`OidcEndpoints` l.50, l.131) and the
+ back-channel logout reconciler.
+- `MemberRole` (`StandardMember`, `Producer`, `Maintainer`, `LedgerReviewer`, `PlatformAdmin`) are capability
+ roles a member holds in addition. They are not the new field.
+- Invites are `MembershipInvitation`, keyed by GitHub login (`MembershipSynchronizationService` l.37,
+ `Members/Index.cshtml.cs` l.34). A guest may have no GitHub login at all.
+- Heimdall sign-in (`HeimdallAuthService.StartAsync`) with `requireMemberAccess = false` already creates an
+ identity-only account at `Authenticated`; with member access it creates `Active`.
+- Nothing exists for room grants, leaving, erasing, or any "estate" in code (estates are rulings and research
+ only, `docs/charter-amendment-proposal.md`).
+
+## Decision: one role field, status stays lifecycle
+
+Two authorities cannot both say "may this account vote". Today `Status == Active` says it. The cut:
+
+- `Membership.Status` keeps its meaning as lifecycle of the account: may it hold a session. Add `Left` and
+ `Erased` (see Leave and erase). `Active` means admitted and in good standing, for any role.
+- `Membership.Role` (new, non-null, enum `AccountRole`) decides rights. `IsActiveMember` becomes
+ `Status == Active && Role == Member`, and is the only place that expression exists. Every current
+ `IsActiveMember` caller keeps working unchanged and a guest fails all of them without a per-site edit.
+- OIDC authorize, token, userinfo and the logout reconciler change their test from "Active member" to
+ "`Status == Active`" (any role), so a guest, user or patron can hold a chat session and a member demoted to
+ `Suspended` still loses it. This is the one behavioural change outside new code, and it is the line to review.
+- Backfill: `Active` becomes `member`; `Authenticated` and `PendingApproval` become `user`; an account with a
+ current `Patron` tier snapshot and not `Active` becomes `patron`. Nobody starts as `guest`.
+
+Naming risk: `MemberRole` already exists for capability roles. If the collision bites, call the new field
+`Class`; the published field below follows whichever name is chosen. I use `Role` because that is the ruling's word.
+
+Alternative considered and not recommended: a boolean `IsGuest` on `Membership` with guests kept at `Active`.
+Smaller to land, but `user` and `patron` stay implicit in status and tier snapshots, so "the role field Personas
+read" would have to be derived in three places. One stored field is one reading.
+
+## Invite shape
+
+New table `GuestInvitation`, separate from `MembershipInvitation` (which is GitHub-login-keyed and leads to
+approval, not to a guest). Fields:
+
+| field | rule |
+|---|---|
+| `Id` | Guid. |
+| `TokenHash` | SHA-256 of a 256-bit random token. The token itself is shown to the issuer once, as a link, and never stored. |
+| `IntendedIdentity` | the localpart the issuer picks (for example `sletz`), validated by `BifrostIdentityService.NormalizeIdentity`, reserved while the invite is open. Minted once on accept; a collision gets the usual `-2` suffix. |
+| `Label` | free note for the issuer ("sletz, Faust developer"). |
+| `RoomGrants` | the rooms to grant on accept (below), as a list of grant requests. |
+| `IssuedByUserAccountId`, `IssuedAtUtc` | issuer must be a platform admin (`CanManageMembership`), as for member invites. |
+| `ExpiresAtUtc` | default seven days. |
+| `AcceptedByUserAccountId`, `AcceptedAtUtc`, `RevokedAtUtc` | one use; revoke before accept ends it. |
+
+The link is a bearer: whoever signs in first with it is the guest. That is the cost of not needing sletz's
+provider handle in advance, and it is why the token is single-use and short-lived and why the accept is shown
+to the issuer. Recommended over binding the invite to a provider handle (which needs a Discord or Google id the
+issuer may not have). The issuer may still restrict `ExpectedProvider`; open fork, see Questions.
+
+## Sign-in via Heimdall
+
+1. Guest opens `/invite/guest/`. Bifrost checks hash, expiry, unused, unrevoked, and stores the invite id in
+ the existing Heimdall attempt (`HeimdallAuthService` protects attempt state with the data protector).
+2. Bifrost starts Heimdall sign-in with `requireMemberAccess = false` (identity only, no entitlement policy).
+ Heimdall authenticates; it does not issue the identity (`docs/jurisdiction-map.md`).
+3. On the callback, in one transaction: resolve `HeimdallAccountId`.
+ - No account: create `UserAccount` with `IntendedIdentity`, `Membership { Status = Active, Role = Guest }`, write
+ the room grants, mark the invite accepted, write the receipt.
+ - Account exists: the invite never lowers an account. A `member`, `patron` or `user` keeps their role; the grants
+ are added and the invite is spent. If the existing account is `Left` or `Erased`, refuse.
+4. Bifrost issues its own cookie as for any account. From there the guest reaches chat through the one OIDC client.
+
+Gap, drift found while reading: Bifrost's `AllowedProviders` is `discord, patreon, twitch`
+(`HeimdallAuthService.AllowedProviders`), but Heimdall's `bifrost` app profile allows `discord, patreon, google`
+(`app-profiles.ts`, `bifrostProfile`). Twitch cannot start in Heimdall and Google is refused by Bifrost. A guest with
+neither Discord, Patreon nor a Google account cannot sign in, and GitHub is not a Heimdall sign-in provider for
+this app. Which provider sletz uses is unknown to me; align the two lists before the first invite.
+
+## Guest rights
+
+A guest may: sign in, hold a Bifrost cookie, hold a chat session through OIDC, see and edit their own profile
+(`MemberProfile`), be in the rooms granted to them, and leave or erase (below). A guest may not:
+
+- vote on motions: `EffectiveVotingWeight` is `0` for any role but `member` (today it is `Max(1, ...)` for
+ `Active`, which would give every guest weight 1; that line must read the role);
+- cast concept-mill appraisals: `VoterIdentity.For` returns no voter for a guest (not even `VoterClass.Account`);
+- appear on any estate roll or in any tally. The charter proposal snapshots each estate's roll at notice (A6);
+ `guest` is on no roll, so a guest cannot be counted, cannot make a quorum, and reclassifying a guest after a
+ snapshot changes nothing for that snapshot;
+- use bridge transport, claim or log work, earn points or ledger credit, or hold tier snapshots (those make them
+ a patron or member by changing role, not by decorating a guest);
+- hold a `MemberRole` or any of the `CanManage*` flags;
+- invite anyone.
+
+This list is enforced by role in one place (`CurrentBifrostActor`), not by a check at each use.
+
+## Per-room grants
+
+Rooms are Matrix rooms in chat, not Bifrost objects. Bifrost owns the decision, so a grant is Bifrost state:
+
+`GuestRoomGrant { Id, UserAccountId, RoomRef, GrantedByUserAccountId, GrantedAtUtc, ExpiresAtUtc?, RevokedAtUtc? }`
+
+`RoomRef` is a room id or alias as chat names it. Aqua's `#aquasynth` is the first one if she says yes.
+
+The grant has to reach Matrix to mean anything. Today Bifrost's only Matrix writer is the Persona mouth, with
+per-Persona access tokens (`docs/bridge.md`), and it holds no admin or invite right.
+
+Gap (largest in this doc): something must perform "invite this Matrix user to that room" on a grant and "remove
+them" on revoke or expiry. Candidates: a Bifrost-owned bot user that is a member with invite power in the granted
+rooms (reuses the Matrix client API, no Synapse admin credential), or the Synapse admin API. I recommend the bot
+user: narrower credential, and the room's power levels remain the real gate. Until it exists, the grant is a
+record, a human invites the guest by hand, and the receipt says `delivered_by: manual`. Rooms for guests must be
+invite-only; a guest who can reach a public room needs no grant, and that is a chat configuration fact I have not
+verified.
+
+Second gap: a guest has a full Matrix account once MAS provisions the localpart, so Matrix itself will let them
+create rooms or DM unless Synapse's room-creation and invite settings (`room_list_publication_rules`,
+`allow_public_rooms_*`, a spam-checker or module) say otherwise. These are global in Synapse, not per user, so a
+guest limit may have to be power levels in every room they are in. I did not find a per-user switch.
+
+## Role change on the same account id, with a receipt
+
+`ChangeRole(accountId, to, actor, reason)` is the only writer of `Membership.Role`. It runs in one transaction:
+
+1. refuse `Erased` and `Left`; refuse a no-op;
+2. write `Role`, and for `member` also set `Status = Active`, `ApprovedAtUtc`, and the default `StandardMember`
+ capability role (the same effects as `OnPostApproveAsync`); for `patron`, nothing beyond the role (tier
+ snapshots come from support events as before);
+3. write `AccountRoleReceipt { Id, UserAccountId, From, To, ChangedAtUtc, ChangedByUserAccountId, Reason }`;
+4. leave `UserAccount.Id`, `NormalizedBifrostIdentity`, `HeimdallAccountId`, grants and profile untouched.
+
+Who may change: a platform admin (`CanManageMembership`). Promoting to `member` is the existing approve path;
+this design routes it through `ChangeRole` so one writer exists. Promoting to `member` also applies whatever the
+charter says about joining an estate (not decided; see Questions). Demotion (member to guest) is allowed and
+receipted; it also removes the `MemberRole`s and capability flags in the same transaction.
+
+The receipt is a Postgres row today, like `AuditEvent`. Bifrost's rule is that durable state has a CultCache `.cc`
+witness (`docs/jurisdiction-map.md`, Design Rules); the witness is owed (Gaps).
+
+Seamless means: the guest's session cookie, OIDC subject, Matrix id, display name and room memberships do not
+change on promotion. A cookie issued before promotion carries identity claims only, never the role, so it needs
+no refresh; the actor is read from the database each request (`CurrentBifrostActorAccessor`).
+
+## Leave and erase
+
+Neither exists in Bifrost today. Two different acts:
+
+**Leave** (guest or any role, self-service): sets `Status = Left`, revokes every grant, and expels the account
+from granted rooms through the same effector as grants. The OIDC reconciler already notices a non-`Active`
+subject within 30 seconds and logs MAS out, and the token and userinfo endpoints refuse. The account row and
+`Id` stay, so a later invite can restore it (a `Left` account re-accepting is a role change from itself, receipted).
+Nothing else about the person is deleted by leaving.
+
+**Erase** (self-service, or admin on request): irreversible. In one transaction: blank `DisplayName`, `AvatarUrl`,
+`MemberProfile`, `GitHubLogin`/`GitHubUserId`, clear `HeimdallAccountId` (the authenticator link), set
+`Status = Erased`, keep `Id` and `NormalizedBifrostIdentity` as a tombstone so the localpart is never reissued to
+someone else (OIDC says it is minted once), keep receipts but with names stripped. The reason to keep a tombstone
+row is that receipts and audit events point at the id.
+
+An erasing guest has no votes, ledger entries or points, because guests cannot create them. A member or patron
+who erases does, and those are accounting records: their erase is a separate question (Questions). Guest erase
+is the case this design covers.
+
+Outside Bifrost, erase is incomplete without two effectors:
+
+- Matrix: Synapse's deactivate-with-erase admin call and MAS deactivation for the user. Federation is disabled in
+ the chat map (`gamecult-ops/docs/gamecult-chat-map.md`: federation paths 404), which helps: messages are
+ not copied to other servers. Other members' clients, and any export or training copy, are not reached by an
+ erase. Whether chat content is training data is `heimdall-body`'s consent rulings (Heimdall PR #6), which already
+ define exit by redaction; a guest's messages follow whatever that doc says, not this one.
+- Heimdall: I found no account-delete or unlink path in Heimdall `src`. Clearing `HeimdallAccountId` on the Bifrost
+ side leaves the Heimdall account and its provider link alive. Heimdall needs an erase call keyed by the account id
+ before "erased" is true end to end.
+
+## What Eureka reads
+
+Personas read the role, not the account. Do not put it in OIDC: the issuer promises "no membership detail leaves
+Bifrost" (`docs/oidc-issuer.md`) and chat does not need it. Publish a typed CultMesh document under the
+`gamecult.bifrost.governance` family (the nearest existing schema namespace, `verse-service-contract.md` l.60), id
+`gamecult.bifrost.account.v1`, key = account id:
+
+| field | type | note |
+|---|---|---|
+| `account_id` | uuid | OIDC `sub`; never changes. |
+| `identity` | string | `NormalizedBifrostIdentity`; the Matrix localpart, so Matrix user id is `@:` (server name per MAS config, not verified here). |
+| `display_name` | string | blank once erased. |
+| `role` | `guest` \| `user` \| `patron` \| `member` | the field Personas read. |
+| `status` | `authenticated` \| `pending_approval` \| `active` \| `suspended` \| `left` \| `erased` | |
+| `role_since` | UTC ms | from the latest `AccountRoleReceipt`. |
+| `rooms` | list of room refs | only for `guest`: the live grants. Others get rooms by estate. |
+
+A Persona deciding how to treat someone looks up `identity` from the Matrix sender and reads `role`. A sender with
+no document is not a Bifrost account (a bridge ghost or an unlinked user) and is `unknown`, never defaulted to
+`guest` or `user`. Bifrost does not decide Persona behavior; it states the role.
+
+No such publisher or witness exists; Bifrost has no `.cc` export for accounts today.
+
+## Cut sequence (not specs)
+
+1. `Membership.Role`, backfill, `IsActiveMember` and the OIDC tests moved to the new reading, vote and concept-vote
+ exclusions, with tests that fail if a guest gets weight or a voter key.
+2. `GuestInvitation`, the accept path, the Heimdall provider list aligned.
+3. `AccountRoleReceipt` and `ChangeRole`, with `OnPostApproveAsync` routed through it.
+4. `GuestRoomGrant` and the Matrix effector.
+5. Leave, then erase (Bifrost side), then the Matrix and Heimdall effectors.
+6. The account document and its `.cc` witness.
+
+## Gaps, plainly
+
+- The Matrix effector for grants, leave and erase does not exist, and no credential for it is provisioned.
+- Synapse cannot cap what a guest does per user; room-creation and invite limits are global (unverified: I did not
+ read the live Synapse config).
+- Heimdall has no erase path. Bifrost and Heimdall disagree on provider lists today.
+- No `.cc` witness or CultMesh publisher for accounts or receipts. Bifrost's account state is Postgres only.
+- Matrix id shape (`@:`) depends on MAS importing `preferred_username` as localpart; the OIDC doc
+ says so, I did not check the deployed MAS.
+- Tie to the answer-collector consent doc (Heimdall PR #6): a guest posting in a room may be posting to a sample
+ collector. That doc keys on `member_id`, and says a sender with no linked member is dropped. Whether a guest has a
+ `member_id`, and so whether their answers are collected at all, is not decided here. Default: not collected.
+- Erase for member and patron roles (ledger and vote records) is unmapped.
+
+## Questions for the deciders
+
+1. **Is `Role` the right name** given `MemberRole`, and is one stored role (this doc) preferred over a boolean
+ `IsGuest`? Recommendation: stored role. Confidence: medium; the boolean is cheaper if user and patron are not
+ yet needed.
+2. **Bearer link or provider-bound invite?** Recommendation: bearer, single use, seven days, optional
+ `ExpectedProvider`. Confidence: medium; this is a trust call about how sletz will be sent the link.
+3. **Which Heimdall provider will sletz sign in with?** Needed before the lists are aligned.
+4. **Do guests get a `member_id` for the answer collector?** Default no.
+5. **Does promotion to member join the Members estate immediately**, or does the charter's notice and snapshot
+ rule apply to the roll? The charter text is a proposal, not in force.
From 2aabaabc53c7d9f853635f0f3470b2ce1e6be1a3 Mon Sep 17 00:00:00 2001
From: Heimdall
Date: Tue, 10 Nov 2026 06:13:02 +0000
Subject: [PATCH 002/113] docs(guest-accounts): fold in Eureka's review:
matrix_id lookup, unknown/status/freshness contract, closed-room grants with
steward grantor, guest DM conflict
Co-Authored-By: Claude Sonnet 5.5
---
docs/guest-accounts.md | 52 ++++++++++++++++++++++++++++++++++--------
1 file changed, 43 insertions(+), 9 deletions(-)
diff --git a/docs/guest-accounts.md b/docs/guest-accounts.md
index 3044056..5471e47 100644
--- a/docs/guest-accounts.md
+++ b/docs/guest-accounts.md
@@ -4,7 +4,8 @@ Status: **design, nothing implemented.** Written for `eureka-body:follow_up:bifr
`eureka-body:ruling:guest-arrival-bifrost` (Meta: guests need no Matrix account of their own; they get a GameCult
account through Bifrost with a guest role, and move to member, user or patron on the same account seamlessly),
building on `eureka-body:ruling:bifrost-owns-accounts-invite-only`. I could not `view` either ruling from the
-Heimdall mind, so their text here is the follow-up brief's wording; check it against the rulings. First guest:
+Heimdall mind, so their text here is the follow-up brief's wording. Eureka's review (PR comment, 2026-11-07) checked
+it against the rulings and found guest-arrival matches; the conflicts it found are folded in below. First guest:
sletz (Faust developer). Aqua decides on `#aquasynth` access, so the first grant list is hers to name.
Read at Bifrost `bf8ff62` (`src/Bifrost.Web/Domain/BifrostModels.cs`, `Features/Membership`, `Features/Heimdall`,
@@ -125,6 +126,12 @@ Rooms are Matrix rooms in chat, not Bifrost objects. Bifrost owns the decision,
`RoomRef` is a room id or alias as chat names it. Aqua's `#aquasynth` is the first one if she says yes.
+**Scope (per `guest-room-moderation-ruled`, `guest-room-authority-ruled`).** Project rooms are public-join and
+hand-moderated by the steward, with Eureka as backstop, so a guest who can reach a public room needs no grant. A
+grant exists only for a room its steward chooses to keep closed, and its grantor is that room's steward, not a
+platform admin (the invite itself is still issued by a platform admin; `GrantedByUserAccountId` records the
+steward). Room entry for public rooms is not Bifrost's decision.
+
The grant has to reach Matrix to mean anything. Today Bifrost's only Matrix writer is the Persona mouth, with
per-Persona access tokens (`docs/bridge.md`), and it holds no admin or invite right.
@@ -132,9 +139,19 @@ Gap (largest in this doc): something must perform "invite this Matrix user to th
them" on revoke or expiry. Candidates: a Bifrost-owned bot user that is a member with invite power in the granted
rooms (reuses the Matrix client API, no Synapse admin credential), or the Synapse admin API. I recommend the bot
user: narrower credential, and the room's power levels remain the real gate. Until it exists, the grant is a
-record, a human invites the guest by hand, and the receipt says `delivered_by: manual`. Rooms for guests must be
-invite-only; a guest who can reach a public room needs no grant, and that is a chat configuration fact I have not
-verified.
+record, a human invites the guest by hand, and the receipt says `delivered_by: manual`. Whether the closed rooms a
+steward keeps are invite-only in Synapse is a chat configuration fact I have not verified.
+
+What Matrix takes from the Bifrost account is exactly this effector: invite or remove on a grant, and the power
+level the effector sets on invite. Role never enters OIDC, so Matrix reads no role from the issuer
+(`bifrost-owns-accounts-invite-only`: grants flow from the account through the effector, not through claims).
+
+**Guest DMs (`guest-dms-ruled`) conflict, open.** The mouth declines invites from other servers and accepts
+same-server DM invites (`tools/persona-matrix-mouth.mjs` `answerInvites`). The ruling's decline-for-now assumed
+federated guests; a Bifrost guest is a local `@sletz:`, so the mouth would accept their DM. Either the mouth
+declines DMs from role `guest` (using the account document below), or the ruling is revisited. That is Eureka's and
+the ruling's owner's call, not this doc's; until it is made, the mouth's behaviour is the ruling's opposite for local
+guests.
Second gap: a guest has a full Matrix account once MAS provisions the localpart, so Matrix itself will let them
create rooms or DM unless Synapse's room-creation and invite settings (`room_list_publication_rules`,
@@ -205,16 +222,31 @@ Bifrost" (`docs/oidc-issuer.md`) and chat does not need it. Publish a typed Cult
| field | type | note |
|---|---|---|
| `account_id` | uuid | OIDC `sub`; never changes. |
-| `identity` | string | `NormalizedBifrostIdentity`; the Matrix localpart, so Matrix user id is `@:` (server name per MAS config, not verified here). |
+| `identity` | string | `NormalizedBifrostIdentity`; the Matrix localpart. |
+| `matrix_id` | string | the full mxid `@:`, server name taken from MAS config at publish time so no reader assumes it. The lookup key for a Persona, which holds the Matrix sender id and not the account uuid. |
| `display_name` | string | blank once erased. |
| `role` | `guest` \| `user` \| `patron` \| `member` | the field Personas read. |
| `status` | `authenticated` \| `pending_approval` \| `active` \| `suspended` \| `left` \| `erased` | |
| `role_since` | UTC ms | from the latest `AccountRoleReceipt`. |
| `rooms` | list of room refs | only for `guest`: the live grants. Others get rooms by estate. |
-A Persona deciding how to treat someone looks up `identity` from the Matrix sender and reads `role`. A sender with
-no document is not a Bifrost account (a bridge ghost or an unlinked user) and is `unknown`, never defaulted to
-`guest` or `user`. Bifrost does not decide Persona behavior; it states the role.
+Contract the document carries, not left to each reader:
+
+- **Lookup.** The document is queryable by `matrix_id`.
+- **Absence is `unknown`.** A sender with no document is not a Bifrost account (a bridge ghost or an unlinked user).
+ Readers must treat it as `unknown`, never default it to `guest`, `user` or `member`. This reverses today's Persona
+ reading (everyone unlisted is `member`), which narrows to the Bifrost `member` role.
+- **Status gates the role.** Only `status = active` yields a usable role; `suspended`, `left`, `erased`,
+ `authenticated` and `pending_approval` yield none.
+- **Not Bifrost accounts.** Operator, the Persona's own id and Minds are typed by the reader's config, which takes
+ precedence over the document. Minds are not Bifrost accounts and must not fall to `unknown`.
+- **Freshness.** A reader loads the document when it builds each turn, never once at start, so a role change
+ applies from the next message; past messages keep the role they were read under. `role_since` lets a trace say
+ which role was read. Publisher bound: a role or status change is published within 30 seconds, the same bound the
+ OIDC reconciler already keeps for a non-`active` subject. No publisher exists, so this is the requirement it is
+ built to, not a measurement.
+
+Bifrost does not decide Persona behavior; it states the role.
No such publisher or witness exists; Bifrost has no `.cc` export for accounts today.
@@ -250,6 +282,8 @@ No such publisher or witness exists; Bifrost has no `.cc` export for accounts to
2. **Bearer link or provider-bound invite?** Recommendation: bearer, single use, seven days, optional
`ExpectedProvider`. Confidence: medium; this is a trust call about how sletz will be sent the link.
3. **Which Heimdall provider will sletz sign in with?** Needed before the lists are aligned.
-4. **Do guests get a `member_id` for the answer collector?** Default no.
+4. **Do guests get a `member_id` for the answer collector?** Default no. Eureka agrees from the chat side: the
+ Persona turn is not the collector, and presence in a room is the room's decision (Heimdall PR #6 owns the
+ collector).
5. **Does promotion to member join the Members estate immediately**, or does the charter's notice and snapshot
rule apply to the roll? The charter text is a proposal, not in force.
From 030bd0eede8cd87243c83dd1cec7d042d025ec87 Mon Sep 17 00:00:00 2001
From: Heimdall
Date: Wed, 11 Nov 2026 12:16:18 +0000
Subject: [PATCH 003/113] Members: demoting an admin derives the flags from the
roles left after the removal
Co-Authored-By: Claude Sonnet 5.5
---
src/Bifrost.Web/Pages/App/Members/Index.cshtml.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/Bifrost.Web/Pages/App/Members/Index.cshtml.cs b/src/Bifrost.Web/Pages/App/Members/Index.cshtml.cs
index e9b536b..f761a3f 100644
--- a/src/Bifrost.Web/Pages/App/Members/Index.cshtml.cs
+++ b/src/Bifrost.Web/Pages/App/Members/Index.cshtml.cs
@@ -177,6 +177,8 @@ public sealed class IndexModel(
}
else if (!(user.Id == Actor.UserAccount.Id && role == MemberRole.PlatformAdmin))
{
+ // Out of the collection too, so the flags below derive from the roles as they will stand after the save.
+ user.Membership.RoleAssignments.Remove(existingAssignment);
dbContext.RoleAssignments.Remove(existingAssignment);
}
From 27ca04f1d6ef1180b29ad55cbf62e408fec76a72 Mon Sep 17 00:00:00 2001
From: Heimdall
Date: Wed, 11 Nov 2026 12:16:18 +0000
Subject: [PATCH 004/113] Bootstrap admin promotion never lifts a suspension
and writes a receipt when it changes status (tests cover this and the
demotion fix)
Co-Authored-By: Claude Sonnet 5.5
---
.../MembershipSynchronizationService.cs | 31 +--
.../Shared/ApplicationBootstrapper.cs | 51 ++++-
.../Bifrost.Web.Tests/BootstrapAdminTests.cs | 176 ++++++++++++++++++
3 files changed, 233 insertions(+), 25 deletions(-)
create mode 100644 tests/Bifrost.Web.Tests/BootstrapAdminTests.cs
diff --git a/src/Bifrost.Web/Features/Membership/MembershipSynchronizationService.cs b/src/Bifrost.Web/Features/Membership/MembershipSynchronizationService.cs
index 8ee13a0..6d41d73 100644
--- a/src/Bifrost.Web/Features/Membership/MembershipSynchronizationService.cs
+++ b/src/Bifrost.Web/Features/Membership/MembershipSynchronizationService.cs
@@ -12,7 +12,9 @@ public sealed class MembershipSynchronizationService(
BifrostDbContext dbContext,
BifrostIdentityService bifrostIdentityService,
IOptions bootstrapOptions,
- TimeProvider timeProvider)
+ TimeProvider timeProvider,
+ AuditTrailService auditTrailService,
+ ILogger logger)
{
public async Task SynchronizeAsync(ClaimsPrincipal principal, CancellationToken cancellationToken)
{
@@ -109,9 +111,14 @@ public sealed class MembershipSynchronizationService(
invitation.AcceptedAtUtc = now;
}
+ MembershipStatus? promotedFrom = null;
if (IsBootstrapAdmin(gitHubLogin, bootstrapOptions.Value))
{
- PromoteToBootstrapAdmin(userAccount.Membership!, now);
+ promotedFrom = userAccount.Membership!.Status;
+ if (!ApplicationBootstrapper.TryPromoteBootstrapAdmin(userAccount, now, logger))
+ {
+ promotedFrom = null;
+ }
}
else if (userAccount.Membership!.Status == MembershipStatus.Active)
{
@@ -125,22 +132,16 @@ public sealed class MembershipSynchronizationService(
userAccount.MemberProfile!.UpdatedAtUtc = now;
+ if (promotedFrom is { } before && before != userAccount.Membership!.Status)
+ {
+ // One save: the promotion and its receipt stand or fall together.
+ await ApplicationBootstrapper.RecordPromotionAsync(auditTrailService, userAccount, before, cancellationToken);
+ return;
+ }
+
await dbContext.SaveChangesAsync(cancellationToken);
}
- private static void PromoteToBootstrapAdmin(Bifrost.Web.Domain.Membership membership, DateTimeOffset now)
- {
- membership.Status = MembershipStatus.Active;
- membership.IsPlatformAdmin = true;
- membership.CanManageProjects = true;
- membership.CanManageLedger = true;
- membership.CanModerateMotions = true;
- membership.ApprovedAtUtc ??= now;
-
- ApplicationBootstrapper.EnsureRole(membership, MemberRole.PlatformAdmin, null, now, "Bootstrap admin");
- ApplicationBootstrapper.EnsureRole(membership, MemberRole.StandardMember, null, now, "Default active member role");
- }
-
private static bool TryReadGitHubIdentity(
ClaimsPrincipal principal,
out long gitHubUserId,
diff --git a/src/Bifrost.Web/Features/Shared/ApplicationBootstrapper.cs b/src/Bifrost.Web/Features/Shared/ApplicationBootstrapper.cs
index 1a3cd0f..04879e2 100644
--- a/src/Bifrost.Web/Features/Shared/ApplicationBootstrapper.cs
+++ b/src/Bifrost.Web/Features/Shared/ApplicationBootstrapper.cs
@@ -10,6 +10,7 @@ public sealed class ApplicationBootstrapper(
BifrostDbContext dbContext,
IOptions bootstrapOptions,
TimeProvider timeProvider,
+ AuditTrailService auditTrailService,
ILogger logger)
{
public async Task RunAsync(CancellationToken cancellationToken)
@@ -40,16 +41,11 @@ public sealed class ApplicationBootstrapper(
foreach (var adminUser in adminUsers.Where(x => x.Membership is not null))
{
- var membership = adminUser.Membership!;
- membership.Status = MembershipStatus.Active;
- membership.IsPlatformAdmin = true;
- membership.CanManageProjects = true;
- membership.CanManageLedger = true;
- membership.CanModerateMotions = true;
- membership.ApprovedAtUtc ??= now;
-
- EnsureRole(membership, MemberRole.PlatformAdmin, null, now, "Bootstrap admin");
- EnsureRole(membership, MemberRole.StandardMember, null, now, "Default active member role");
+ var before = adminUser.Membership!.Status;
+ if (TryPromoteBootstrapAdmin(adminUser, now, logger) && before != adminUser.Membership.Status)
+ {
+ await RecordPromotionAsync(auditTrailService, adminUser, before, cancellationToken);
+ }
}
if (dbContext.ChangeTracker.HasChanges())
@@ -58,6 +54,41 @@ public sealed class ApplicationBootstrapper(
}
}
+ ///
+ /// The one bootstrap-admin promotion, used at startup and at sign-in. A Suspended account is left exactly as it is (an admin's
+ /// decision; only the suspension service lifts it) and the refusal is logged by account id. Returns whether it promoted.
+ ///
+ public static bool TryPromoteBootstrapAdmin(UserAccount account, DateTimeOffset now, ILogger logger)
+ {
+ var membership = account.Membership!;
+ if (membership.Status == MembershipStatus.Suspended)
+ {
+ logger.LogWarning("Bootstrap admin promotion skipped for suspended account {UserAccountId}.", account.Id);
+ return false;
+ }
+
+ membership.Status = MembershipStatus.Active;
+ membership.IsPlatformAdmin = true;
+ membership.CanManageProjects = true;
+ membership.CanManageLedger = true;
+ membership.CanModerateMotions = true;
+ membership.ApprovedAtUtc ??= now;
+
+ EnsureRole(membership, MemberRole.PlatformAdmin, null, now, "Bootstrap admin");
+ EnsureRole(membership, MemberRole.StandardMember, null, now, "Default active member role");
+ return true;
+ }
+
+ /// The receipt for a bootstrap promotion that changed membership status; saves together with the promotion.
+ public static Task RecordPromotionAsync(AuditTrailService auditTrailService, UserAccount account, MembershipStatus before, CancellationToken cancellationToken) =>
+ auditTrailService.RecordAsync(
+ null,
+ nameof(Bifrost.Web.Domain.Membership),
+ account.Membership!.Id,
+ "membership.bootstrap-promoted",
+ $"Bootstrap admin promotion of {account.DisplayName} ({before} -> {account.Membership.Status}).",
+ cancellationToken);
+
public static void EnsureRole(
Bifrost.Web.Domain.Membership membership,
MemberRole role,
diff --git a/tests/Bifrost.Web.Tests/BootstrapAdminTests.cs b/tests/Bifrost.Web.Tests/BootstrapAdminTests.cs
new file mode 100644
index 0000000..a980dd6
--- /dev/null
+++ b/tests/Bifrost.Web.Tests/BootstrapAdminTests.cs
@@ -0,0 +1,176 @@
+using System.Security.Claims;
+using Bifrost.Web.Data;
+using Bifrost.Web.Domain;
+using Bifrost.Web.Features.Membership;
+using Bifrost.Web.Features.Shared;
+using Bifrost.Web.Pages.App.Members;
+using Bifrost.Web.Tests.Support;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+
+namespace Bifrost.Web.Tests;
+
+/// Bootstrap promotion never lifts a suspension and leaves a receipt when it changes status; demoting an admin clears the admin flags.
+public sealed class BootstrapAdminTests
+{
+ private const long BootstrapGitHubId = 4242;
+
+ private static (Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory Factory, CapturingLoggerProvider Logs) NewFactory()
+ {
+ var logs = new CapturingLoggerProvider();
+ var factory = new TestWebApplicationFactory().WithWebHostBuilder(b => b.ConfigureServices(s => s.AddLogging(l => l.AddProvider(logs))));
+ return (factory, logs);
+ }
+
+ private static async Task SeedBootstrapLoginAsync(IServiceProvider services, MembershipStatus status)
+ {
+ using var scope = services.CreateScope();
+ var db = scope.ServiceProvider.GetRequiredService();
+ var account = new UserAccount
+ {
+ DisplayName = "Test Admin",
+ GitHubUserId = BootstrapGitHubId,
+ GitHubLogin = "test-admin",
+ NormalizedGitHubLogin = "TEST-ADMIN",
+ BifrostIdentity = "testadmin",
+ NormalizedBifrostIdentity = "testadmin",
+ MemberProfile = new MemberProfile { Nickname = "ta" },
+ Membership = new Bifrost.Web.Domain.Membership { Status = status, ApprovedAtUtc = status == MembershipStatus.Suspended ? DateTimeOffset.UtcNow : null }
+ };
+ db.UserAccounts.Add(account);
+ await db.SaveChangesAsync();
+ return account.Id;
+ }
+
+ private static async Task<(Bifrost.Web.Domain.Membership Membership, List Receipts)> ReadAsync(IServiceProvider services, Guid accountId)
+ {
+ using var scope = services.CreateScope();
+ var db = scope.ServiceProvider.GetRequiredService();
+ var membership = await db.Memberships.AsNoTracking().Include(x => x.RoleAssignments).SingleAsync(x => x.UserAccountId == accountId);
+ var receipts = await db.AuditEvents.AsNoTracking().Where(x => x.EntityId == membership.Id.ToString()).ToListAsync();
+ return (membership, receipts);
+ }
+
+ private static ClaimsPrincipal BootstrapPrincipal() => new(new ClaimsIdentity(
+ [
+ new Claim(ClaimTypes.NameIdentifier, BootstrapGitHubId.ToString()),
+ new Claim(ClaimTypes.Name, "test-admin")
+ ], "test"));
+
+ [Theory]
+ [InlineData("startup")]
+ [InlineData("signin")]
+ public async Task A_suspended_bootstrap_login_stays_suspended_and_unpromoted(string path)
+ {
+ var (factory, logs) = NewFactory();
+ using var _ = factory;
+ var id = await SeedBootstrapLoginAsync(factory.Services, MembershipStatus.Suspended);
+ var before = (await ReadAsync(factory.Services, id)).Receipts.Count;
+
+ await RunPathAsync(factory.Services, path);
+
+ var (membership, receipts) = await ReadAsync(factory.Services, id);
+ Assert.Equal(MembershipStatus.Suspended, membership.Status);
+ Assert.False(membership.IsPlatformAdmin);
+ Assert.Empty(membership.RoleAssignments);
+ Assert.Equal(before, receipts.Count);
+ Assert.Contains(logs.Lines, x => x.Contains("suspended account") && x.Contains(id.ToString()));
+ }
+
+ [Theory]
+ [InlineData("startup")]
+ [InlineData("signin")]
+ public async Task A_bootstrap_promotion_that_changes_status_writes_a_receipt(string path)
+ {
+ var (factory, _) = NewFactory();
+ using var _f = factory;
+ var id = await SeedBootstrapLoginAsync(factory.Services, MembershipStatus.Authenticated);
+
+ await RunPathAsync(factory.Services, path);
+
+ var (membership, receipts) = await ReadAsync(factory.Services, id);
+ Assert.Equal(MembershipStatus.Active, membership.Status);
+ Assert.True(membership.IsPlatformAdmin);
+ var receipt = Assert.Single(receipts, x => x.Action == "membership.bootstrap-promoted");
+ Assert.Contains("Authenticated -> Active", receipt.Detail);
+
+ await RunPathAsync(factory.Services, path); // already Active: no second receipt
+ Assert.Single((await ReadAsync(factory.Services, id)).Receipts, x => x.Action == "membership.bootstrap-promoted");
+ }
+
+ private static async Task RunPathAsync(IServiceProvider services, string path)
+ {
+ using var scope = services.CreateScope();
+ if (path == "startup")
+ {
+ await scope.ServiceProvider.GetRequiredService().RunAsync(CancellationToken.None);
+ }
+ else
+ {
+ await scope.ServiceProvider.GetRequiredService().SynchronizeAsync(BootstrapPrincipal(), CancellationToken.None);
+ }
+ }
+
+ private sealed class FixedActor(CurrentBifrostActor actor) : ICurrentBifrostActorAccessor
+ {
+ public Task GetAsync(CancellationToken cancellationToken) => Task.FromResult(actor);
+ }
+
+ private static async Task SeedAsync(IServiceProvider services, string name, bool admin)
+ {
+ using var scope = services.CreateScope();
+ var db = scope.ServiceProvider.GetRequiredService();
+ var membership = new Bifrost.Web.Domain.Membership { Status = MembershipStatus.Active, ApprovedAtUtc = DateTimeOffset.UtcNow };
+ if (admin)
+ {
+ membership.IsPlatformAdmin = membership.CanManageProjects = membership.CanManageLedger = membership.CanModerateMotions = true;
+ membership.RoleAssignments.Add(new RoleAssignment { Role = MemberRole.PlatformAdmin });
+ }
+
+ var account = new UserAccount
+ {
+ DisplayName = name,
+ BifrostIdentity = $"{name}-{Guid.NewGuid():N}"[..20],
+ NormalizedBifrostIdentity = $"{name}-{Guid.NewGuid():N}"[..20],
+ Membership = membership
+ };
+ db.UserAccounts.Add(account);
+ await db.SaveChangesAsync();
+ return account.Id;
+ }
+
+ private static async Task ToggleAsync(IServiceProvider services, Guid by, Guid target, MemberRole role)
+ {
+ using var scope = services.CreateScope();
+ var db = scope.ServiceProvider.GetRequiredService();
+ var actor = new CurrentBifrostActor(true, await db.UserAccounts.Include(x => x.Membership!).ThenInclude(x => x.RoleAssignments).SingleAsync(x => x.Id == by));
+ var page = new IndexModel(db, new FixedActor(actor), scope.ServiceProvider.GetRequiredService(),
+ scope.ServiceProvider.GetRequiredService(), TimeProvider.System);
+ Assert.IsType(await page.OnPostToggleRoleAsync(target, role, CancellationToken.None));
+ }
+
+ [Fact]
+ public async Task Demoting_an_admin_through_the_page_clears_the_admin_flags_and_promoting_sets_them()
+ {
+ var (factory, _) = NewFactory();
+ using var _f = factory;
+ var actingAdmin = await SeedAsync(factory.Services, "acting", admin: true);
+ var otherAdmin = await SeedAsync(factory.Services, "other", admin: true);
+ var member = await SeedAsync(factory.Services, "member", admin: false);
+
+ await ToggleAsync(factory.Services, actingAdmin, otherAdmin, MemberRole.PlatformAdmin);
+ var (demoted, _) = await ReadAsync(factory.Services, otherAdmin);
+ Assert.False(demoted.IsPlatformAdmin);
+ Assert.False(demoted.CanManageProjects);
+ Assert.False(demoted.CanManageLedger);
+ Assert.False(demoted.CanModerateMotions);
+ Assert.DoesNotContain(demoted.RoleAssignments, x => x.Role == MemberRole.PlatformAdmin);
+
+ await ToggleAsync(factory.Services, actingAdmin, member, MemberRole.PlatformAdmin);
+ var (promoted, _) = await ReadAsync(factory.Services, member);
+ Assert.True(promoted.IsPlatformAdmin);
+ Assert.Contains(promoted.RoleAssignments, x => x.Role == MemberRole.PlatformAdmin);
+ }
+}
From c1c057b43c5d2cc1bcf5dff56769b65f0923233b Mon Sep 17 00:00:00 2001
From: Heimdall
Date: Wed, 11 Nov 2026 12:17:36 +0000
Subject: [PATCH 005/113] Members page: a refused suspend or unsuspend shows
the admin why (fixed message via TempData, role=alert)
Co-Authored-By: Claude Sonnet 5.5
---
.../Pages/App/Members/Index.cshtml | 5 +
.../Pages/App/Members/Index.cshtml.cs | 20 ++-
.../MembersPageNoticeTests.cs | 130 ++++++++++++++++++
3 files changed, 154 insertions(+), 1 deletion(-)
create mode 100644 tests/Bifrost.Web.Tests/MembersPageNoticeTests.cs
diff --git a/src/Bifrost.Web/Pages/App/Members/Index.cshtml b/src/Bifrost.Web/Pages/App/Members/Index.cshtml
index b4d67e5..91f04c4 100644
--- a/src/Bifrost.Web/Pages/App/Members/Index.cshtml
+++ b/src/Bifrost.Web/Pages/App/Members/Index.cshtml
@@ -14,6 +14,11 @@
because trust and contributor accountability are product concerns, not just auth concerns.
+ @if (!string.IsNullOrEmpty(Model.Notice))
+ {
+ @Model.Notice
+ }
+
@if (Model.Actor.CanManageMembership)
{