Skip to content

feat(coding-plans): show current quota in Subscription Center - #5071

Merged
jeanduplessis merged 2 commits into
mainfrom
visualize-cloud-usage-2
Aug 6, 2026
Merged

feat(coding-plans): show current quota in Subscription Center#5071
jeanduplessis merged 2 commits into
mainfrom
visualize-cloud-usage-2

Conversation

@lambertjosh

@lambertjosh lambertjosh commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Show normalized MiniMax and BytePlus Coding Plan quota in Subscription Center summary cards and detail pages.

Why this change is needed

Customers cannot currently see their remaining managed-plan quota in Kilo. BytePlus also requires a control-plane seat lookup because its usage API is authorized with Kilo-managed AK/SK credentials and addresses quota by seat ID rather than inference API key.

How this is addressed

  • Show compact quota summaries on live Coding Plan cards and a full quota card with retry support on detail pages.
  • Normalize MiniMax and BytePlus usage into the same ordered quota-window contract.
  • Resolve and verify BytePlus seats during inventory upload, storing the seat ID as server-only inventory metadata.
  • Authorize BytePlus usage with optional server-only management credentials without decrypting its inference key.
  • Cache successful normalized usage snapshots for 60 seconds and coalesce matching requests.
  • Keep provider failures isolated from subscription metadata.
  • Add the additive upstream_usage_id database column and provider-scoped partial unique index.
  • Update admin upload guidance and the Coding Plan specifications for provider-specific upstream identifiers.
  • Harden assignment readiness and replacement errors so seat IDs, credentials, and database parameters cannot reach API responses.
  • Existing BytePlus inventory will be revoked and uploaded again rather than backfilled.

Human Verification

  • Focused BytePlus control-plane, normalization, inventory-validation, usage-service, router, lifecycle, and inventory tests passed.
  • Existing responsive quota states were checked for compact and detail layouts, loading, unavailable, retry, boosted quota, and low-quota presentation.

Reviewer Notes

Human Reviewer Flags

  • BytePlus uses a scoped Provider Management Credential plus a verified seat ID; MiniMax continues to use its assigned managed inference credential.
  • BytePlus usernames remain reconciliation metadata, while resolved seat IDs remain server-only usage subjects.
  • Existing BytePlus inventory is intentionally not backfilled. Operators will revoke and reload those keys.
  • The migration is additive, but BytePlus usage remains unavailable for any row without a verified seat ID or when either management credential is absent.

Code Reviewer Agent

Code Reviewer Notes
  • The control-plane client fixes host, region, service, API version, action, and project; signs deterministic request bodies; uses a five-second timeout; bounds responses to 64 KiB; and returns sanitized errors.
  • Usage cache keys remain inventory-based and do not contain usernames or seat IDs.
  • canQueryUsage requires the assigned inventory row to match the subscription owner, plan, and provider.
  • Database failures during credential replacement are converted to safe domain errors before reaching tRPC.
  • BytePlus Lite and Pro share the same adapter and render ordered 5-hour, weekly, and monthly windows.

@kilo-code-bot

kilo-code-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental review at c7f7275 covering the new BytePlus usage integration commit and rebase deltas since the previous review: HMAC-signed control-plane client with bounded/validated responses and safe error taxonomy, fail-closed seat resolution with constant-time key comparison, owner-scoped usage flow gated by SQL-derived capability flags, sanitized replacement/upload error messages, partial unique index on upstream_usage_id matching recent migration conventions, and comprehensive tests (ownership isolation, seat-metadata non-leakage, signature determinism, error mapping). Previously-reviewed UI files verified unchanged.

Files Reviewed (31 files)
  • .env.local.example
  • .specs/coding-plans.md
  • .specs/subscription-center.md
  • ENVIRONMENT.md
  • apps/web/src/app/admin/coding-plans/CodingPlansOperationsContent.tsx
  • apps/web/src/components/subscriptions/SubscriptionCard.tsx
  • apps/web/src/components/subscriptions/coding-plans/CodingPlanDetail.tsx
  • apps/web/src/components/subscriptions/coding-plans/CodingPlanUsage.tsx
  • apps/web/src/components/subscriptions/coding-plans/CodingPlansGroup.tsx
  • apps/web/src/components/subscriptions/coding-plans/coding-plan-usage-format.test.ts
  • apps/web/src/components/subscriptions/coding-plans/coding-plan-usage-format.ts
  • apps/web/src/lib/coding-plans/billing-lifecycle-cron.test.ts
  • apps/web/src/lib/coding-plans/byteplus-control-plane.test.ts
  • apps/web/src/lib/coding-plans/byteplus-control-plane.ts
  • apps/web/src/lib/coding-plans/byteplus-usage.test.ts
  • apps/web/src/lib/coding-plans/byteplus-usage.ts
  • apps/web/src/lib/coding-plans/index.test.ts
  • apps/web/src/lib/coding-plans/index.ts
  • apps/web/src/lib/coding-plans/inventory-validation.test.ts
  • apps/web/src/lib/coding-plans/inventory-validation.ts
  • apps/web/src/lib/coding-plans/revocation.ts
  • apps/web/src/lib/coding-plans/usage-contract.ts
  • apps/web/src/lib/coding-plans/usage.test.ts
  • apps/web/src/lib/coding-plans/usage.ts
  • apps/web/src/lib/config.server.ts
  • apps/web/src/lib/redis-keys.ts
  • apps/web/src/routers/coding-plans-router.test.ts
  • apps/web/src/routers/coding-plans-router.ts
  • packages/db/src/migrations/0207_rich_azazel.sql
  • packages/db/src/schema.test.ts
  • packages/db/src/schema.ts

Generated migration snapshot/journal files (0207_snapshot.json, _journal.json) were excluded from review per policy.

Previous Review Summary (commit c34a1f4)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c34a1f4)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (13 files)
  • .specs/subscription-center.md
  • apps/web/src/components/subscriptions/SubscriptionCard.tsx
  • apps/web/src/components/subscriptions/coding-plans/CodingPlanDetail.tsx
  • apps/web/src/components/subscriptions/coding-plans/CodingPlanUsage.tsx
  • apps/web/src/components/subscriptions/coding-plans/CodingPlansGroup.tsx
  • apps/web/src/components/subscriptions/coding-plans/coding-plan-usage-format.test.ts
  • apps/web/src/components/subscriptions/coding-plans/coding-plan-usage-format.ts
  • apps/web/src/lib/coding-plans/usage-contract.ts
  • apps/web/src/lib/coding-plans/usage.test.ts
  • apps/web/src/lib/coding-plans/usage.ts
  • apps/web/src/lib/redis-keys.ts
  • apps/web/src/routers/coding-plans-router.test.ts
  • apps/web/src/routers/coding-plans-router.ts

Reviewed by kimi-k3 · Input: 100.6K · Output: 18.2K · Cached: 926.7K

Review guidance: REVIEW.md from base branch main

@lambertjosh

Copy link
Copy Markdown
Contributor Author
image image

@jeanduplessis
jeanduplessis force-pushed the visualize-cloud-usage-2 branch from c34a1f4 to c7f7275 Compare August 6, 2026 12:16
@jeanduplessis
jeanduplessis merged commit 2e568b4 into main Aug 6, 2026
52 checks passed
@jeanduplessis
jeanduplessis deleted the visualize-cloud-usage-2 branch August 6, 2026 12:28
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.

2 participants