Guard the sweep and reconcile against an empty-but-successful member fetch #2

Closed
opened 2026-10-27 04:57:25 +00:00 by inference-bot · 1 comment
Owner

An empty member fetch is treated as "everyone lapsed" — destructively.

Found while rotating the OC token on 2026-10-27, and deliberately NOT tested, because testing it means deactivating members.

Both OC-dependent maintenance paths act on whatever member list they get:

  • the nightly sweep deactivates every member whose email is not in the fetched set;
  • the newsletter reconcile unsubscribes every subscriber not in that set.

They are guarded against a fetch that raises — the sweep returns {"status":"skipped","reason":"member_fetch_failed"} a moment ago, and reconcile returns removed: 0 — and that guard is good. What is unguarded is a fetch that succeeds while returning nothing or much less than usual, which is what a narrow-scoped or partially-privileged token produces (the members connection can resolve while the individual email field comes back null). That outcome is reachable, is not loud, and deactivates the membership rather than failing to.

Suggested shape: treat a member set that is empty, or smaller than some large fraction of the previously-known active member count, as a fetch failure — log it, alert, and take no action — rather than as evidence that everyone lapsed. The same guard belongs on the reconcile path.

Not urgent (nothing about tonight's token change is broken), but it is the one mistake in this system with loud, member-visible, hard-to-reverse consequences.

**An empty member fetch is treated as "everyone lapsed" — destructively.** Found while rotating the OC token on 2026-10-27, and deliberately NOT tested, because testing it means deactivating members. Both OC-dependent maintenance paths act on whatever member list they get: - the nightly **sweep** deactivates every member whose email is not in the fetched set; - the **newsletter reconcile** unsubscribes every subscriber not in that set. They are guarded against a fetch that *raises* — the sweep returns `{"status":"skipped","reason":"member_fetch_failed"}` a moment ago, and reconcile returns `removed: 0` — and that guard is good. What is unguarded is a fetch that *succeeds* while returning nothing or much less than usual, which is what a narrow-scoped or partially-privileged token produces (the members connection can resolve while the individual `email` field comes back null). That outcome is reachable, is not loud, and deactivates the membership rather than failing to. Suggested shape: treat a member set that is empty, or smaller than some large fraction of the previously-known active member count, as a fetch failure — log it, alert, and take no action — rather than as evidence that everyone lapsed. The same guard belongs on the reconcile path. Not urgent (nothing about tonight's token change is broken), but it is the one mistake in this system with loud, member-visible, hard-to-reverse consequences.
Author
Owner

Fixed and verified on the live service. Image 20261027-452a27a (commits 452a27a + manifest pin 403a773).

The guard. fetch_members() now checks its result against the portal's local active count before returning, and raises when the list is implausible — empty, or at or below half of local. _member_set_verdict() is a pure decision function so it is testable without a database; eight cases are covered, including exactly-half (refused, deliberately), a fresh install with no members (allowed), and a grown list.

Verified live: the nightly sweep ran clean — {"status":"reconciled","provisioned":0,"deactivated":0,"reinvited":0,"newsletter_removed":0} — and the guard logged its ratio on the way through:

member-set guard OK (oc members query): fetched 62, 68 active locally

That line prints the numbers on every run, so drift toward the threshold becomes visible before it is dangerous rather than at the moment it bites.

Correction to this issue as filed. I claimed the newsletter reconcile was also exposed. It is not: listmonk_reconcile reads the local members table (SELECT email FROM members WHERE active = 1), not this fetch. The sweep is the only destructive consumer, which is a smaller blast radius than I described. The webhook paths call the same fetch but act on one member at a time — a bad list there means a credit pack is held rather than granted, which is recoverable and already alerts.

Likely trigger, worth knowing: the fetch filters members by the Membership tier's name. A rename of that tier on Open Collective returns admins only — a huge drop. Before this change the sweep would have read that as "everyone lapsed" and deactivated the membership.

Fixed and verified on the live service. Image `20261027-452a27a` (commits `452a27a` + manifest pin `403a773`). **The guard.** `fetch_members()` now checks its result against the portal's local active count before returning, and raises when the list is implausible — empty, or at or below half of local. `_member_set_verdict()` is a pure decision function so it is testable without a database; eight cases are covered, including exactly-half (refused, deliberately), a fresh install with no members (allowed), and a grown list. **Verified live**: the nightly sweep ran clean — `{"status":"reconciled","provisioned":0,"deactivated":0,"reinvited":0,"newsletter_removed":0}` — and the guard logged its ratio on the way through: ``` member-set guard OK (oc members query): fetched 62, 68 active locally ``` That line prints the numbers on every run, so drift toward the threshold becomes visible before it is dangerous rather than at the moment it bites. **Correction to this issue as filed.** I claimed the newsletter reconcile was also exposed. It is not: `listmonk_reconcile` reads the local `members` table (`SELECT email FROM members WHERE active = 1`), not this fetch. **The sweep is the only destructive consumer**, which is a smaller blast radius than I described. The webhook paths call the same fetch but act on one member at a time — a bad list there means a credit pack is held rather than granted, which is recoverable and already alerts. **Likely trigger, worth knowing**: the fetch filters members by the Membership *tier's name*. A rename of that tier on Open Collective returns admins only — a huge drop. Before this change the sweep would have read that as "everyone lapsed" and deactivated the membership.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: code/member-portal#2