fix(rotation): one CoinPay login per run, real login errors (CLI 0.16.1) (#292)

coinpaySession() POSTed /api/auth/login from every preflight and mint of
the CoinPay API key and webhook secret rotators. A run over ~220 CoinPay
keys fired hundreds of logins from one address; coinpayportal limits
sign-in to 10/min, so all but the first few preflights failed and were
reported as "needs a CoinPay merchant session" even with correct
credentials.

- Memoize the session per base URL + email for the whole run (concurrent
  callers share one in-flight login; failures are cached too so a bad or
  throttled login is not retried per key).
- A 401 on a session call logs in again once and retries (not for
  COINPAY_ROTATE_TOKEN).
- Login failures name the cause: 401 wrong credentials, 429 rate limited,
  402 paywall throttle, otherwise status + short body. No secrets printed.

Co-authored-by: riotcoder <riotcoder@profullstack.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-11-22 02:57:37 -08:00 • committed by GitHub
parent 5716bad54e
commit d8a08c006b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 204 additions and 33 deletions

View file

@ -196,7 +196,11 @@ health-check, then revoke the old one.
- Keys: `COINPAY_API_KEY`, `COINPAYPORTAL_API_KEY`, `COINPAY_*_API_KEY`,
`COINPAY_X402_KEY`.
- Needs a merchant session for the business owner: `COINPAY_ROTATE_TOKEN`, or
`COINPAY_ROTATE_EMAIL` + `COINPAY_ROTATE_PASSWORD`.
`COINPAY_ROTATE_EMAIL` + `COINPAY_ROTATE_PASSWORD`. With email + password the
CLI logs in once per run and every CoinPay key reuses that session (sign-in
is limited to 10/min per address); a 401 mid-run logs in again once. A failed
login is reported as its cause: wrong credentials (401), rate limited (429),
or the site's paywall throttle (402).
- Mint: the old key finds its business (`GET /api/businesses`), then `POST
/api/businesses/<id>/api-keys` creates a scoped key with the old key's scopes
(`*` for the legacy key). Old and new both work.