8000 fix(group): release members-only spots when a membership ends by mwoods79 · Pull Request #727 · huddlz-hq/huddlz · GitHub
[go: up one dir, main page]

Skip to content

fix(group): release members-only spots when a membership ends - #727

Merged
mwoods79 merged 43 commits into
mainfrom
t3/release-rsvps-after-leave
Dec 2, 2026
Merged

mwoods79 merged 43 commits into
mainfrom
t3/release-rsvps-after-leave

Conversation

@mwoods79
@mwoods79 mwoods79 commented Nov 30, 2026 •
Copy link
Copy Markdown
Contributor

Summary

Leaving or being removed from a group releases upcoming RSVP and waitlist spots on its members-only huddlz. The next person waiting gets the freed seat and one promotion notice. Public drop-in spots and attendance history stay in place. Current membership is required to read archived attendance.

When departure makes an open members-only huddl unreadable, the page revisits its address and shows the same recovery page as a fresh visit. If a signed-in viewer can still read a cancelled huddl from their attendance history but its host group is hidden, a refresh takes them to their agenda.

Account deletion waits for in-flight picture uploads, key creation, memberships and invitations before cleanup. An email invitation queued behind its recipient’s deletion is refused. If the recipient changes their address instead, the invitation stays with the originally invited address. An invitation that is still pending can reach its recipient after the organizer who sent it closes their account. Anonymizing the required email keeps its case-insensitive uniqueness and allows concurrent references to the account ID.

Lock order

Action Locks and writes in acquisition order
Leave Delete own membership → close reminder (first insert references group) → affected huddlz by ID → released and promoted spots
Remove member Group → membership → removal notice → close reminder → affected huddlz by ID → released and promoted spots
Change role Group → membership → role change and notice
RSVP or join waitlist Shared acc 8000 ount lifecycle lock → group → membership key share if members-only → huddl → spot
Cancel RSVP Group → huddl → departing spot → promotion if a seat opens
Promote during release Already-held huddl → next waitlisted spot → promotion notice
Edit all dates Check series membership → active group FOR NO KEY UPDATE → reread source series and select source and all same-group series date IDs → those huddlz FOR UPDATE by ID → update source → load and update its group’s template → reconcile later dates in that group → record source and scheduled starts
Archive group Group for update → archive and notify members
Delete group permanently Group for update → memberships by ID → huddlz by ID → cascade and notify members
Invite by account or email Look up the addressed account ID → inviter and candidate account rows FOR SHARE by ID → active group → resolve the confirmed recipient → expire matching expired pending invitations → insert invitation
Claim invitation Actor’s shared lifecycle lock → actor and original inviter FOR SHARE by ID → active group → pending invitation FOR UPDATE → record link opening and, if confirmed, lock any pending invitation already bound to the account and reconcile the offers
Accept invitation Shared participant lifecycle locks → actor account FOR SHARE → active group → pending invitation FOR UPDATE → accept and grant membership if needed
Decline, revoke or expire invitation Actor account FOR SHARE when present → pending invitation FOR UPDATE → status update
Deliver invitation to account Recipient and original inviter FOR SHARE by ID → group FOR NO KEY UPDATE → invitation FOR UPDATE → when binding, lock any existing bound pending invitation, reconcile offers and announce when eligible
Join or add member Shared participant lifecycle locks → active group → insert membership
Create group Creator’s shared lifecycle lock → insert group → insert owner membership
Transfer ownership Shared lifecycle locks for actor and both owners → update group → demote previous owner if present → promote new owner
Suspend Target’s exclusive and administrator’s shared lifecycle locks in key order → target account and administrator reference → tokens and API keys → occupied huddlz by ID → spots
Create or replace profile picture Shared account lifecycle lock → insert picture → on replacement, retire previous pictures
Create API key Actor’s shared lifecycle lock → insert key
Delete account Exclusive lifecycle lock → account for no key update → owned and joined groups by ID → own memberships by ID → affected huddlz by ID → tokens, keys, pictures, notifications and invitations → archive owned groups, leave other groups and release remaining spots → anonymize account

The account lifecycle locks are transaction-scoped advisory locks acquired in key order. Ordinary group activity and departure take FOR NO KEY UPDATE on the group. Archival and permanent deletion take FOR UPDATE. A successful replacement invitation was traced through the group lock, the previous invitation’s expiry and the new insert.

Series membership is set at creation. The standalone-to-series attachment branch and its concurrency test were removed after #724 closed that update path. A legacy huddl in another group can carry the same template ID and remains independently editable while the home group edits its series.

Account references

  • Cleanup revokes tokens by subject, removes API keys and notifications, retires profile pictures, removes incoming invitations, and updates group ownership, memberships, huddlz and attendance as applicable. Tokens use a subject string. The other resources have account-ID foreign keys.
  • Other account references include huddl creators, publishers and cancellers, invitation senders, suspension attribution, huddl photo uploads, group activity, drop-in reminders, social connections, activity days, user blocks, impersonations and moderation reports. PaperTrail versions reference both actor and impersonator. These references continue to work through anonymization.

Evidence

Before: An upcoming members-only spot could survive a departure. A picture replacement or API key committed during deletion could survive cleanup. An open page could take a different route depending on which refresh arrived first.

After: Acceptance scenarios cover seat release, promotion, the former member’s recovery page and archived attendance through JSON:API and GraphQL. Separate database connections cover picture replacement, key creation, anonymization while the account ID is referenced, membership and invitation ordering, suspension attribution, group deletion and edits across a series. The edit-all tests verify the blocker with pg_blocking_pids and compare pg_stat_database.deadlocks before and after each case. They also cover a leave finishing while an edit waits for the lowest date ID, and a second connection locking a legacy huddl in another group during the edit.

A two-tab photo refresh reproduced a checkout timeout on the test’s shared sandbox connection. The gallery scenarios now finish their refreshes before teardown, and the test sandbox allows for overlapping reads. The photo upload action uses the same group lock as main.

Merge Danger

Door: Two-way

Blast Radius: Attendance and account deletion

  • Apply the reversible email-index migration before rolling out the application change. Rebuilding the unique index can block writes to the users table during the migration. Email is required, so the index covers every account in either direction.
  • Rejoining or reverting the release logic does not rebook a seat. Deploy all application nodes for consistent coordination.
  • The ordinary first-time leave versus permanent group deletion and organizer huddl creation during account deletion remain separate work. fix(series): generate new dates without dropping or granting spots #751 handles spots on newly generated series dates.

Who's going was shown to anyone holding an RSVP or a waitlist spot on the
huddl. A spot can outlive what made it possible: the huddl becomes
members-only, or the person leaves the group or is removed from it. They
could no longer open the huddl, yet the JSON:API and GraphQL lists still
named the people going.

The list now also needs what an RSVP needs: the huddl is open to everyone,
or the reader is a member of its group. Lifecycle plays no part, so the
list of an ended huddl, or of one whose group was archived, stays with the
people who had it before. Group roles and administration still grant no
exception.
Leaving a group, or being removed from it, left the person's RSVPs and
waitlist spots in place. On the group's members-only huddlz they kept a
seat they could not give up, on a huddl they could no longer open, and
were still sent its updates, reminders and cancellation.

Both actions now release the person's spots on the group's huddlz that are
still open to attendance and that only members can go to, under the same
huddl lock RSVPs take, and the next person waiting gets the seat and the
usual notice. Spots on huddlz open to everyone stay, since an RSVP there
never needed the membership, and so do spots on huddlz already cancelled
or ended, which are history.

The person is not told separately: a removal already has its own notice.
Releasing a suspended or deleted account's spots found them through the
attendee rows, which reaches only publicly visible huddlz, so spots on
members-only huddlz stayed. The huddlz are now read directly.

A cancelled huddl has no seat to hand on: its spots stay as history, and
nobody is promoted into it.
The huddlz whose spots are released were chosen before their rows were
locked, so a cancellation or an edit committing in between was missed:
a suspension could promote someone into a huddl just cancelled, and
leaving a group could drop an RSVP on a huddl just opened to everyone.
The locked row is now checked for both.

- a departing organizer's spot on a members-only draft is released too
- deleting an account closes the groups it owns before releasing its
  spots, so nobody is given a seat at a huddl cancelled in the same breath
Each spot's group was read separately while the spots were released, so a
group opened or closed at the same moment as someone leaving could have
one of their RSVPs released and another kept. The group's row is locked
and its visibility read once for the whole release.
Locking the group's row while releasing a leaving member's spots set a
leave against other work that reaches the group and its huddlz in a
different order: two members leaving together, a role change, an RSVP
during an account deletion. The visibility is still read once for the
whole release, so every spot is judged by the same answer.
…r-leave

* origin/main:
  fix(api): accept only sign-in tokens on the GraphQL socket (#730)
  fix(huddl): tie organizer-only huddl details to the current role (#726)
  fix(groups): keep a group's address book with its organizers (#725)
  fix(discover): noindex empty filtered public discovery responses (#734)
An RSVP or waitlist place sent at the same moment as the person's own
leave or removal could commit after their spots had been released, and
stay on a members-only huddl with no membership behind it.

Both sides are now decided under the group's row lock, the lock RSVPs,
removal, role changes and huddl edits already take first:

- leaving takes it before the membership row, as removal does
- taking a spot checks again, once it holds the lock, that the huddl is
  still open to the person
- account deletion locks a group it owns before its drafts, and leaves
  its other groups before releasing the remaining spots

Every change inside a group now reaches the group, then the membership,
then the huddlz, so two of them cannot wait on each other. That also ends
the deadlock between a leave and a role change for the same member.
A spot released because a membership ended, or an account was suspended
or deleted, changed who's going without telling anyone looking at the
huddl. Only the huddl's own `:cancel_rsvp` published the change.

The spot now publishes its own release on the huddl's topic, with the
message open pages already reload on, so one publisher covers a spot
given up and a spot released. The huddl stops publishing `:cancel_rsvp`
itself, which would have announced the same change twice.

- people looking at the huddl see the seat pass to the next person
  waiting
- the person who lost access is taken off the page
Leaving while an organizer cancels the huddl can finish in either order.
When the cancellation commits first the spot stays as history, as it
does for any cancelled huddl, so that case now checks the membership
alone. Also state that an account's own group is there to be locked
before it is closed.
The page reloads when the release is announced, in its own process, and
under a loaded suite that took longer than the default 100 ms the redirect
assertion allows. The wait is bounded and ends as soon as the page moves.
The lock a leave takes was a function added to `RequireActiveGroup`, with
`LockLifecycle` rewritten to call it. Those two files go back to what main
has, and the lock lives in `GroupLock`, used by leaving and by account
deletion.

It locks the same row, so it still takes turns with every change that
asks whether the group is active, and it asks for no more than that: a
row that only points at the group is not held up behind a leave.
…r-leave

* origin/main:
  fix(auth): bind administrator viewing credentials to the browser session (#736)
  fix(api): authenticate API, GraphQL and MCP from the bearer alone (#729)
A weaker lock here let the same transaction ask for a stronger one later:
closing a deleted account's group cancels its huddlz, then archives the
group. That second request waits for rows that point at the group, and a
writer of such a row can be waiting on a huddl the transaction already
holds. The database counted those as deadlocks even though every test
passed, because the loser was an activity entry written after commit.
…r-leave

* origin/main:
  fix(groups): authorize membership changes against their roster (#739)
A leave now takes the group's row lock before its membership, so it waits
for a removal elsewhere in the roster to commit and then goes through.
That ordering is what settles a leave against the person's own RSVP.
Releasing a person's spots already took huddlz in id order. An "edit all"
on a series, closing the groups of a deleted account and deleting a group
for good took theirs in other orders, so each could hold a huddl the
other was waiting for. All of them now lock what they will touch up
front through `LockedHuddl.hold_in_order/1`: groups, then memberships,
then huddlz by id.

Account deletion also stops holding off rows that merely point at the
account. It keeps its lock on the account at the strength that orders it
against the person's other changes, and writes the account's own row
last: that write changes the email, which makes every such row wait.
Adds the two interleavings that deadlocked when a leave waited for its
group (archiving against a returning member's account deletion; an
organizer adding a member while deleting their own account), suspension
and account deletion against the person's own RSVP, every multi-huddl
release against an "edit all", and deleting a group against a leave.

Each test now fails if PostgreSQL reports a deadlock on any connection,
including a write made after the action committed.
…account

Leaving for the first time writes the person's reminder for the group,
which points at the group's row. That no longer sets the two against each
other, so both kinds of member are covered.
…eletion

Both sides hold the group's memberships and several of its huddlz, and
now take them in the same order.
…r-leave

* origin/main:
  test: let the shared test storage read pictures (#767)
  fix(live): keep pages open through a transient refresh error (#766)

# Conflicts:
#	lib/huddlz_web/live/huddl_live/show.ex
After merging the transient-refresh change, a huddl page whose viewer
lost access visits itself again rather than redirecting directly, so the
visitor sees what a fresh visit shows; transient errors still keep the
page open.
@mwoods79
mwoods79 merged commit bf633b6 into main Dec 2, 2026
5 checks passed
@mwoods79
mwoods79 deleted the t3/release-rsvps-after-leave branch December 2, 2026 02:05
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

0