members: an explicit SOURCE, so 'oc-incognito' stops being 'manual'
ci/woodpecker/push/woodpecker Pipeline was canceled

mmoya@mmoya.org sat in MANUAL_MEMBERS because OC hides the address on their
profile (incognito-5ad60182, email null since 2023), so email matching can never
find them. But "manual" means hand-provisioned, and the sweep SKIPS manual
members entirely: a paying subscriber had no lapse logic, no dues tracking and no
order attribution. Two different facts were sharing one word.

members.source now carries which one it is:
  oc            — OC-backed, matched by email (the default; NULL means this)
  oc-incognito  — OC-backed, profile hides the email, matched by the stored OC
                  SLUG — which the reconciliation already uses, since
                  fetch_member_orders() groups orders by the payer's slug and
                  members.slug holds exactly that for these people
  manual        — hand-provisioned; no contribution expected, nothing reconciles,
                  nobody lapses

So an oc-incognito member needs no exemption from reconciliation — they need to
stop being skipped, and the existing slug path does the rest.

Every decision that keyed on the raw MANUAL_MEMBERS list now keys on the source:
the reconciliation skip, the sweep's deactivation guard, and the shortfall-credit
exemption. An explicit source beats the list, so a member can be moved without
editing the env — and the env list can shrink toward deprecation. An
unrecognised or unreadable source falls back to 'oc', the direction that keeps
reconciling someone rather than quietly exempting them.

anchor_day_for_member also resolves by slug now: an incognito member is absent
from the member index (it drops anyone without an email), and falling back to
"today" would silently move their renewal day.

tests/test_oc_incognito.py pins all of it, including that the column is optional
(NULL = not stated) so this ships without a data migration.
This commit is contained in:
inference-admin committed 2026-11-13 22:24:46 +00:00
1 parent a98db6e36e
commit 64d1ea5093
2 files changed
+216 -4

No files matched your search

+98 -4
View File
@@ -408,6 +408,72 @@ INACTIVE_GROUP_ID = os.environ.get("INACTIVE_GROUP_ID", "")
# Open Collective member list. Used for the free "founder" tier, which OC
# cannot process as a $0 recurring subscription. These members are exempt from
# the sweep's deactivation (they have no OC membership to lapse).
# How a member's membership is ACCOUNTED FOR. This exists because "manual" was
# doing two incompatible jobs (2026-11-13):
# oc — OC-backed, matched by email. The default.
# oc-incognito — OC-backed, but the OC profile HIDES its email (mmoya@mmoya.org),
# so email matching can never see them. The contribution is real
# and the reconciliation already matches orders by the payer's
# SLUG, which is what the members.slug column holds for these
# people — so they keep lapse logic, dues tracking and order
# attribution, and are NOT swept into the manual bucket.
# manual — hand-provisioned (MANUAL_MEMBERS): no OC contribution is
# expected, so nothing reconciles and nobody lapses.
# A row with no explicit source falls back to MANUAL_MEMBERS, so this changed
# nothing for anyone until a source was actually set.
MEMBER_SOURCES = ("oc", "oc-incognito", "manual")
def member_source(email: str, conn=None) -> str:
"""This member's accounting source. Never raises: an unreadable row is 'oc'
(the default), which is the safe direction — it means we keep reconciling them
rather than quietly exempting them from it."""
email = (email or "").strip().lower()
src = ""
try:
own = conn is None
conn = conn or get_db()
try:
cols = {r[1] for r in conn.execute("PRAGMA table_info(members)")}
if "source" in cols:
row = conn.execute("SELECT source FROM members WHERE lower(email) = ?",
(email,)).fetchone()
src = ((row[0] if row else "") or "").strip().lower()
finally:
if own:
conn.close()
except Exception as e:
logger.warning("member_source(%s): %s", email, e)
if src in MEMBER_SOURCES:
return src
return "manual" if email in MANUAL_MEMBERS else "oc"
def is_manual_member(email: str, conn=None) -> bool:
"""Hand-provisioned: the set MANUAL_MEMBERS names, minus anyone given an
explicit source of their own (an oc-incognito member is OC-backed even though
email matching cannot see them)."""
return member_source(email, conn) == "manual"
def set_member_source(email: str, source: str) -> bool:
"""Record a member's source. Idempotent; returns True when the row was written."""
source = (source or "").strip().lower()
if source not in MEMBER_SOURCES:
raise ValueError(f"unknown source {source!r}; expected one of {MEMBER_SOURCES}")
conn = get_db()
try:
cols = {r[1] for r in conn.execute("PRAGMA table_info(members)")}
if "source" not in cols:
conn.execute("ALTER TABLE members ADD COLUMN source TEXT")
cur = conn.execute("UPDATE members SET source = ? WHERE lower(email) = ?",
(source, (email or "").strip().lower()))
conn.commit()
return cur.rowcount > 0
finally:
conn.close()
MANUAL_MEMBERS = {
e.strip().lower()
for e in os.environ.get("MANUAL_MEMBERS", "").split(",")
@@ -1031,6 +1097,10 @@ def get_db() -> sqlite3.Connection:
# only by their own rules (credit exhausted, or the GUEST_DAYS time box).
if "account_type" not in cols:
conn.execute("ALTER TABLE members ADD COLUMN account_type TEXT DEFAULT 'member'")
# Migration: source — how this membership is accounted for (see
# MEMBER_SOURCES). NULL means "not stated": fall back to MANUAL_MEMBERS.
if "source" not in cols:
conn.execute("ALTER TABLE members ADD COLUMN source TEXT")
# Migration: oc_email — the Open Collective email a member's contribution
# arrives under when it differs from their account email (set via
# POST /admin/guest-convert when a invited friend joins under another
@@ -5226,7 +5296,8 @@ async def admin_overview(request: Request):
"active": bool(active),
"state": mstate,
"state_reason": mstate_reason,
"manual": email.lower() in MANUAL_MEMBERS,
"manual": member_source(email) == "manual",
"source": member_source(email),
"org": org_slug or None,
"matrix_mxid": matrix_mxid or None,
"balance": float(balance) if balance is not None else MEMBER_BUDGET,
@@ -6948,7 +7019,7 @@ async def reconcile_memberships() -> dict:
if info["account_type"] == "guest":
continue
user_id = info["user_id"]
if email not in active_emails and email not in MANUAL_MEMBERS:
if email not in active_emails and not is_manual_member(email):
try:
if INACTIVE_GROUP_ID and user_id:
await cloudron_set_group(user_id, INACTIVE_GROUP_ID)
@@ -7516,6 +7587,25 @@ async def anchor_day_for_member(email: str, slug: str = "") -> int:
return d
except Exception as e:
logger.warning("anchor_day_for_member: OC join-date lookup failed for %s: %s", email, e)
if slug:
# An oc-incognito member is absent from the member index (it drops anyone
# without an email), but their orders carry the slug we store. Their
# billing rhythm still anchors the cycle — falling back to "today" would
# silently move their renewal day.
try:
orders = (await fetch_member_orders()).get(slug) or []
joined = min((_parse_oc_dt(str(o.get("createdAt"))) for o in orders
if _parse_oc_dt(str(o.get("createdAt")))), default=None)
if joined:
d = _clamp_anchor_day(joined.day)
conn = get_db()
conn.execute("UPDATE members SET anchor_day = ? WHERE email = ?", (d, email))
conn.commit()
conn.close()
logger.info("anchor_day_for_member: %s anchored to %d from their OC order", email, d)
return d
except Exception as e:
logger.warning("anchor_day_for_member: order lookup failed for %s/%s: %s", email, slug, e)
return _clamp_anchor_day(datetime.now(timezone.utc).day)
@@ -7600,7 +7690,11 @@ async def reconcile_allowances(send: bool = False) -> dict:
# renewal decision, no reminder, ever.
counts["skipped"] += 1
continue
if email.lower() in MANUAL_MEMBERS:
if member_source(email, conn) == "manual":
# Hand-provisioned: no OC contribution is expected, so there is
# nothing to reconcile. An 'oc-incognito' member is NOT skipped —
# their contribution is matched by the slug in row[1] below, which is
# the only key OC gives us for them.
counts["skipped"] += 1
continue
if org_slug:
@@ -8907,7 +9001,7 @@ async def reconcile_allowance_shortfalls(send: bool = False) -> dict:
skipped.append({**c, "email": email, "why": "not an active portal member"})
continue
m = meta.get(email) or {}
if email in MANUAL_MEMBERS or m.get("org_slug"):
if is_manual_member(email) or m.get("org_slug"):
skipped.append({**c, "email": email, "why": "exempt member (manual / organization-backed)"})
continue
rec = index.get(email)