Skip to content

fix: KEEP-1331 decode billing subscription response (overageCharges array + usage keys) - #113

Merged
suisuss merged 3 commits into
mainfrom
fix/KEEP-1331-billing-status-parse
Sep 8, 2026
Merged

fix: KEEP-1331 decode billing subscription response (overageCharges array + usage keys)#113
suisuss merged 3 commits into
mainfrom
fix/KEEP-1331-billing-status-parse

Conversation

@suisuss

@suisuss suisuss commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

What

kh billing status (and kh billing usage) crashed while decoding GET /api/billing/subscription:

decoding response: json: cannot unmarshal array into Go struct field SubscriptionResponse.overageCharges of type float64

Root cause: the server returns overageCharges as an array of up to five recent overage line-items (a .limit(5) select in app/api/billing/subscription/route.ts), but the CLI typed the field as float64.

While fixing that, a second silent mismatch surfaced in the same response: the CLI read usage.executions / usage.limit, but the server sends usage.executionsUsed / usage.executionLimit, so both decoded to 0 and the command reported Executions: 0 / 0 regardless of real usage.

Changes

  • SubscriptionResponse.OverageCharges is now []OverageCharge, a struct mirroring the server element shape (periodStart, periodEnd, overageCount, totalChargeCents, status, createdAt, nullable providerInvoiceId). The existing single Overage: $X.XX line is now fed by TotalOverageDollars(), which sums the line-item totalChargeCents.
  • usage JSON tags corrected to executionsUsed / executionLimit so the quota line renders real numbers.
  • Tests: decode the real server payload shape (overage array + usage keys) and assert the parsed values; a permitted/rendered path asserts Overage: $4.75 and non-zero usage.

Verification

go test ./cmd/billing/..., go build ./..., go vet ./cmd/billing/... all pass (run in golang:1.25; host has no Go).

Out of scope (flagged for follow-up)

--json mode re-serializes only the modelled fields, so it still drops server-only fields (gasCredits, gasCreditCaps, trial, richer subscription). Pre-existing; not addressed here.

The server returns overageCharges as an array of recent overage billing
line-items, but the CLI typed it as float64, so kh billing status and
kh billing usage crashed on response decoding. Type it as a slice of
OverageCharge and render the summed line-item total as the dollar figure.
… keys

The CLI struct tagged usage as executions/limit, but the server sends
executionsUsed/executionLimit, so Go silently decoded both to zero and
kh billing status/usage reported "0 / 0" regardless of real usage. Align
the JSON tags with the server and guard it with a decode test.
…owed

TotalOverageDollars summed every recent overage record, including ones
already pushed to a provider invoice or in a non-pending status, so the
CLI overstated the bill (re-billing settled charges). Match the billing
UI: sum only records with providerInvoiceId==nil and status=="pending".
@suisuss
suisuss merged commit 13e5b44 into main Sep 8, 2026
6 checks passed
@suisuss
suisuss deleted the fix/KEEP-1331-billing-status-parse branch September 8, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant