credits_drawn could exceed credit_balance after an admin set/correction (or a
negative adjustment), so a later pack was only partly usable: available =
max(0, purchased - drawn) swallowed the difference. Cap credits_drawn at the
row's balance on every add_credits movement; ledger history is unchanged.
Tests cover reduction-then-repurchase.
A guest has no monthly cycle, so nothing ever drew their spend against the $2
pack. Conversion kept the full credit_balance, handing back credits already
used — guest-access.md promises only the unspent credit carries over.
record_guest_conversion_draw() writes the consumed part as a negative ledger
row (reference guest-convert-draw:<email>) and bumps credits_drawn, capped by
the row's credit and idempotent on replay. Tests cover draw, replay, cap, and
the resulting remaining figure.
An operator account has team max_budget NULL (no cap). broker_get_usage only
assigned balance when max_budget was not None, so the DB path left 'balance'
unbound and the HTTP fallback read the same name before assignment — a 500 for
exactly the accounts the uncapped policy created. Initialise balance from the
member's allowance + credits still available, mark the response uncapped when
the team row has no cap, and keep the dashboard arithmetic defined.
Applying the draw mid-cycle used to push max_budget below the member's
already-recorded spend, so LiteLLM refused every call until their next reset
(weeks for some anchors). The draw is still recorded immediately — books are
correct — but the cap is only pushed once the member's spend has room for it,
which happens right after LiteLLM's reset. The tick retries every 10 minutes,
so the cap lands at the first tick after the boundary; deferred members are
reported in close_credit_cycles().deferred.
tests/test_credit_cycle_close.py covers draw-recorded/cap-deferred and the
cap landing after spend resets, with no second draw.
The allowance reconcile skips rows with org_slug (dues are paid by an OC
Organization, not an individual order), so org members never got an anchor_day
and close_credit_cycles skipped them forever — their packs regenerated monthly,
the same defect as #12.
- fetch_org_join_days(): paginated OC members walk, ORGANIZATION accounts only,
slug -> membership createdAt.
- reconcile_org_anchors(): for every active org-backed row with anchor_day NULL,
set anchor = org join day clamped to 1..28 and pin the team reset to its next
occurrence. Only NULL rows are touched (idempotent); an org with no OC record is
reported, never guessed, and keeps being reported until resolved.
- Runs in /admin/sweep and immediately in the org-member webhook path.
tests/test_org_anchors.py: anchor math incl. clamp, reset pin, idempotence,
unresolved reporting.
Operator/infrastructure accounts are a collective expense, not members: applying
the $15 + credits cap to them cuts the co-op's own tooling off mid-task.
- UNCAPPED_EMAILS (defaults to OPERATOR_EMAILS) is cleared in
sync_team_budget_from_balance via litellm_clear_team_budget: max_budget = NULL
on the team row (unlimited), written directly because /team/update drops
budget_reset_at.
- sync_team_budget_from_balance returns None for an uncapped account; admin
responses report team_budget: null rather than a computed figure.
LiteLLM zeroes a team's `spend` at budget_reset_at but leaves max_budget
alone, and nothing in the portal ever reduced credit_balance. So every
monthly reset restored every credit pack already spent: a $15 member who
bought $50 and used all $65 got $65 again the next month.
Fix — record the draw when a cycle closes:
- new `members.credits_drawn` (credits consumed in CLOSED cycles);
credit_balance stays the lifetime purchased total so the "bought all-time"
display never changes meaning.
- `compute_max_budget` caps at allowance + credits STILL AVAILABLE
(purchased − drawn). Spend inside the current cycle still does not shrink
the cap, so a credit add keeps raising it 1:1.
- `apply_cycle_draw` writes a NEGATIVE credit_ledger row per closed cycle,
deduped on reference `cycle-close:<email>:<cycle>`; the cycle's spend is
summed from LiteLLM_SpendLogs over the exact anchor-day window.
- `close_credit_cycles` runs every 10 min via the new Cloudron scheduler task
(credit_cycle_close.sh) and again as a catch-up inside /admin/sweep.
- CREDIT_CLOSE_FROM (default 2026-11-28) stops it charging cycles that
started before the fix: credits already regranted are forgiven rather than
clawed back mid-cycle.
- /admin/credits/{email} now reports credits_drawn.
Tests: tests/test_credit_cycle_close.py covers the cap arithmetic, the
issue's worked example, draw idempotence and the available-credit cap.
The sweep compared the ECB rate to a hardcoded 1.16 and emailed info@ with
"-5.39%" plus advice to "re-convert" — obsolete since fx_sync.py converts at
boot. The steady breach also froze the alert marker, so a later, real move
could never mail.
- Default baseline 1.0975 (the gateway's FX_FALLBACK_USD pin, ECB 2026-11-26);
runtime value set via FX_POLICY_EUR_USD.
- Email now says live billing is unaffected by conversion and points at the
stale artifacts (config fallback, ops pricing tables, fx_state.json).
An unreachable remote homeserver hangs every invite POST to that member until
the client timeout (8 rooms x 30s), which outlived the 5-minute service-sync
tick and starved every member queued behind it. Raise a member-scoped
_TransportError instead of returning False, skip that member's remaining rooms
for this pass, and report transport_skipped in the result. Invites stay
idempotent, so the next pass retries.
Test: a timed-out member is attempted once, not once per room.
The collective crossed 200 orders on 2026-11-23 (203). fetch_member_orders()
asked for orders(limit: 200) in one request, so the orders beyond the window —
the OLDEST ones, where long-standing members' recurring contributions live —
were absent from the sweep's read. Three paying members (ntnsndr,
elizabeth-barry1, guest-0f6d98ac) therefore read as "no recurring (monthly)
contribution on Open Collective" and were sent a payment reminder at 03:02 UTC
for contributions that were live and charged on 2 Nov.
fetch_oc_monthly_order_charges() had the same fixed window, hiding the oldest
orders' charge ladders from the shortfall credit pass.
Both now page by offset until OC's totalCount is covered, and a read that falls
short of totalCount RAISES instead of returning a short list: a short list is
the exact shape that reads as "nobody is paying".
The invite stamp meant 'handed to Loomio once, EVER', so a member whose
membership was later revoked (a lapse that was reversed) or who deleted
their Loomio account was recorded as invited and never invited again.
- Stamp only the addresses Loomio actually returns in added_emails; an
address accepted in the payload but not added stays eligible.
- Clear the stamp for an ACTIVE member stamped-but-absent from the live
roster; the invite itself waits one pass so a single stale page cannot
become an invite.
- Cap stamp clearing per pass (LOOMIO_RECONCILE_MAX, default 10): more
stamped-but-absent members means a short roster read, not a mass
re-invite.
- loomio_opt_out exempts members who deliberately left.
- Username fix falls back to the portal slug when a handle is already
taken (Loomio handles are instance-global; every OC alias resolves to
opencollective).
A no-tier BACKER is only a member when it predates the tier system
(LEGACY_NO_TIER_BEFORE). Treating every no-tier BACKER as memberish made
the $75 Workers.VC donation mail info@ as a paid contributor with no
account. Mirror fetch_members() exactly; donations stay silent, and only
unattached credit packs keep the hold-and-notify path.
An httpx.ReadTimeout during an invite POST raised out of sync_matrix_space,
so every member after the timed-out one got nothing and the service-sync log
said only 'Matrix sync failed:' (httpx transport exceptions stringify to '').
One new member sat uninvited for a day that way.
- invite(): catch httpx.HTTPError per member/room, log the type, return False
- pass counts only members whose invite actually returned True
- room-membership snapshot, the retire half and the Cloudron users walk no
longer abort on a transport error; the unreadable room/member is skipped
- service-sync now logs the exception TYPE (empty str(e) hid the cause)
Regression in tests/test_service_invites.py section 7: a timed-out member does
not stop the member after them, and the next pass retries them.
secrets.compare_digest raises TypeError on str containing non-ASCII, so a
webhook path token or header token with one answered 503/500 instead of
401/403 — a scanner manufactured a false money-critical alert on 2026-11-20.
Compare UTF-8 bytes through _secret_eq and fail closed on empty.
webhook_failures now stores ip and user_agent; the sweep email names each
source and distinguishes a probe from an Open Collective delivery.