reconcile paid credit packs against the ledger, report-first (issue #7)
ci/woodpecker/push/woodpecker Pipeline was canceled

Credits have one path in: the OC order.processed webhook. On 2026-11-13 two paid
packs got nothing through it — a $50 whose delivery 500'd on httpx's 5s default,
and a $10 with no delivery in the retained log at all — and nothing on a
schedule noticed. This adds a pass that reads OC's own order list and compares it
with our books over a day-based window (not "whatever the log still holds": the
$10 gap was 11h old and the log had lost the whole morning).

Report-first: CREDIT_RECONCILE defaults to 'report' (log findings, change
nothing) and grants only when set to 'on'. Grants go through add_credits() with
credit_pack_reference(), the same per-order key the webhook writes, so a late
delivery and this pass are idempotent against each other in both directions. A
buyer with no active membership is reported, never credited — those keep the
hold-and-email path.

credit_pack_accounted() encodes what our own rows actually look like: a v2 id, a
hyphenated legacy id, an empty-suffix legacy reference, and held_credits rows. A
bare oc:<slug>:<order.id> match read 21 credited purchases as missing during
development, so the fallback demands a second signal (member + tip-free amount +
date) before calling an order credited.

POST /admin/credit-pack-reconcile (X-Admin-Token) runs it on demand, dry unless
?apply=1 and the policy is on. 33 new checks; all 18 suites green.
This commit is contained in:
inference-admin committed 2026-11-13 20:16:24 +00:00
1 parent 32e744d9ee
commit 5868ca82e8
3 files changed
+620 -1

No files matched your search

+25 -1
View File
@@ -191,7 +191,31 @@ Four jobs run inside the container via `CloudronManifest.json` → `addons.sched
against the live Open Collective list: provisions missed signups, deactivates
lapsed members, syncs Loomio + Matrix. Idempotent; a missed webhook
self-heals within a day. The same sweep also runs the payment-driven
allowance reconciliation (below).
allowance reconciliation (below) and the credit-pack reconciliation.
**Credit-pack reconciliation** (`CREDIT_RECONCILE`, default `report`) — credits
are granted on exactly one path, the OC `order.processed` webhook, and that
path can fail AFTER the money has moved: on 2026-11-13 a $50 pack's delivery
500'd on httpx's invisible 5-second default, and a $10 pack had no delivery in
the retained log at all. Neither left a ledger row and nothing noticed. This
pass reads OC's OWN order list (`fetch_collective_orders`, needs the `orders`
scope on `OC_PERSONAL_TOKEN`, granted 2026-11-13) and compares it with our
books over `CREDIT_RECONCILE_DAYS` (default 30 — days, not "whatever our log
still holds": the $10 gap was 11 hours old and the log had already lost the
whole morning). In `report` mode it logs findings and changes NOTHING; grants
happen only when `CREDIT_RECONCILE=on`. Every grant uses
`credit_pack_reference()` — the same per-order key the webhook writes — so a
late delivery and this pass cannot both credit one purchase. A buyer who is not
an active member is reported, never credited: those keep the hold-and-email
path. On demand: `POST /admin/credit-pack-reconcile` (`X-Admin-Token`), a dry
run unless `?apply=1` and the policy is `on`.
Matching caution: our own references are NOT uniform, so a bare
`oc:<slug>:<order.id>` test reports credited purchases as missing (it read 21
of them that way, all false). `credit_pack_accounted()` matches the exact
reference when one exists and otherwise requires a second signal — same member,
same tip-free amount, within days — and counts a `held_credits` row as
accounted for.
**Service-invite triggers:** the sweep is the backstop, not the primary path.
Two faster triggers exist, because a member who has just set up their account