Files
member-portal/CloudronManifest.json
inference-bot fe898905b4
ci/woodpecker/push/woodpecker Pipeline failed
credits: close each cycle so a pack cannot be spent twice (#12)
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.
2026-11-27 20:29:12 +00:00

40 lines
1.2 KiB
JSON

{
"id": "coop.inference.member-portal",
"title": "Member Portal",
"author": "Inference Cooperative",
"description": "Membership middleware: syncs Open Collective members with Cloudron users and LiteLLM keys, and injects per-member keys into inference requests.",
"version": "0.1.0",
"healthCheckPath": "/health",
"httpPort": 8000,
"addons": {
"localstorage": {},
"oidc": {
"loginRedirectUri": "/",
"logoutRedirectUri": "/"
},
"sendmail": {},
"scheduler": {
"membership_sweep": {
"schedule": "0 3,11,19 * * *",
"command": "/app/code/sweep.sh"
},
"service_sync": {
"schedule": "*/5 * * * *",
"command": "/app/code/service_sync.sh"
},
"metrics_snapshot": {
"schedule": "15 3 * * *",
"command": "/app/code/metrics_snapshot.py"
},
"credit_cycle_close": {
"schedule": "*/10 * * * *",
"command": "/app/code/credit_cycle_close.sh"
}
}
},
"manifestVersion": 2,
"website": "https://inference.coop",
"contactEmail": "info@inference.coop",
"dockerImage": "registry.inference.coop/code/member-portal:20261127-0e53c33"
}