docs(credits): the monthly refill is a floor, not an assignment

Merged
SW
3mo ago
+8-8

Contract half of the refill fix in recoupable/chat#1960. Row 2 of that issue's PR matrix.

checkAndResetCredits SETs remaining_credits to the plan total once a monthly refill is due, rather than topping up to it. Any account holding more than its plan total is therefore cut on the next balance read. Measured on prod 2026-08-17: 119 accounts hold more than the 333 free-plan total, 50 of them with a reset already pending. Because the refill is lazy and read-triggered, the loss fires on a GET, so reading a balance is what destroys it.

Today's docs describe that reduction as intended behaviour and build a contract on top of it. This PR corrects the contract.

What changes

POST /api/admins/credits — the "A grant expires after one month, plan for it" paragraph is replaced. It told admins that a granted balance "is then silently overwritten on the first balance read after it" and to "grant it again" if the headroom needed to outlive a month. Once the refill cannot reduce a balance, that is false and actively causes admins to re-grant credits that do not need re-granting.

AdminGrantCreditsResponse.expires_at is removed (breaking, admin-only). The field's whole purpose was to report when the refill would destroy the grant. With a floor refill, it describes an event that never happens. required drops from 8 fields to 7.

credits.mdx — new ### Monthly refill subsection under ## Subscription, stating the floor rule and that the refill is lazy and read-triggered.

Verification

  • api-reference/openapi/accounts.json parses after editing; AdminGrantCreditsResponse now reports required: [status, grant_id, account_id, remaining_credits, previous_credits, reason, granted_by, granted_at] and the same 7 properties plus status, with no expires_at in either.
  • grep -n "expires_at" api-reference/openapi/accounts.json returns nothing.
  • Edits were made as anchored text edits, not a json.load/json.dumps round-trip: accounts.json does not round-trip byte-for-byte (it stores non-ASCII as \uXXXX escapes), so a rewrite would have produced a 200-line whitespace diff.
  • Deliberately does not touch credits.mdx line 44, which docs#299 edits, so the two docs PRs merge in any order without conflict. They touch disjoint regions of accounts.json (card-on-file and the auto-recharge path vs. the admin grant block).

Merge order

Merge this after the api refill fix reaches prod (row 5 of chat#1960), not before. It is the one place the docs-first convention inverts: until the api change ships, a refill still reduces balances, and publishing the floor rule early would document behaviour prod does not have. The POST /api/admins/credits half additionally needs the api PR that stops returning expires_at (row 6).


Summary by cubic

Clarifies that the monthly credit refill is a floor, not an assignment, and updates docs to match. Previously, refills overwrote balances to the plan total on the next read and grants above the plan total were cut; now refills only top up and never reduce, so grants do not “expire.”

Rollout and migration

  • OpenAPI: AdminGrantCreditsResponse removes expires_at (breaking, admin-only). Update admin tools and automation to stop reading or relying on expires_at.
  • POST /api/admins/credits description now states that refills never reduce balances; the “grant expires after one month” guidance is removed.
  • credits.mdx: adds “Monthly refill” subsection explaining the floor rule and that the refill is lazy and read-triggered.
  • Merge only after the API refill fix is live in production; merging earlier would document behavior prod does not yet have.