Skip to content

feat(billing): add cloud usage billing foundation#4646

Draft
pandemicsyn wants to merge 4 commits into
mainfrom
feat/cloud-billing-foundation
Draft

feat(billing): add cloud usage billing foundation#4646
pandemicsyn wants to merge 4 commits into
mainfrom
feat/cloud-billing-foundation

Conversation

@pandemicsyn

@pandemicsyn pandemicsyn commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add the Milestone 1 foundation for usage-based cloud billing: typed container lifecycle RPC contracts, persisted heartbeat/stop retry state, and a new container-usage-meter Worker with a durable SQLite failover buffer.
  • Add immutable, admin-managed cloud_billing_sku products with exact cents-per-second rates, one-way disablement, and primary-backed credit-manager authorization. The restricted admin/API surface exposes create, list, and one-way disable operations only.
  • Add a Cloud Billing SKUs admin page for creating, listing, previewing, and disabling SKUs, including exact decimal price previews and explicit loading, error, permission, validation, and pending states.
  • Validate recordStart against the SKU catalog and durably serialize accepted or rejected start decisions so retries remain consistent across SKU disablement and PostgreSQL outages.
  • Add the PostgreSQL interval schema, Durable Object SQLite migrations, Worker configuration, local-service registration, and generated bindings needed for the foundation. Producer wiring, PostgreSQL interval ingestion, charging, and budget enforcement remain follow-on milestones.

Verification

  • Opened /admin/cloud-billing-skus through the local fake-admin flow and verified the page renders in the existing admin shell with the Financial navigation entry, immutable-SKU guidance, catalog card, and permission-gated create action.
  • Manual create/disable flow was not exercised because the long-lived local PostgreSQL database had already recorded an earlier uncommitted migration with the same sequence; the final schema was instead validated against fresh databases.
  • Additional manual verification details:

Visual Changes

Before After
No Cloud Billing SKUs admin surface New Cloud Billing SKUs catalog and immutable SKU creation workflow; screenshot to attach before review

Reviewer Notes

  • This PR delivers Milestone 1, Foundation.
  • Milestone 1 scope is durable contracts and capture semantics only: no producer is wired, and the meter does not yet apply intervals to PostgreSQL, drain/replay buffered mutations, reconcile stale intervals, or reclaim Durable Object rows.
  • start_admissions (pending | accepted | rejected) and pending_usage_mutations intentionally remain append-only in this PR. Milestone 2 owns safe cleanup after PostgreSQL confirmation: retain pending admissions through validation retries, retain accepted admissions while dependent buffered mutations exist, retain rejected admissions through the idempotency window, and expose TTL/backlog metrics and alerts.
  • Milestone 2, Meter and Shadow: wire Cloud Agent with an explicit SKU, add the PostgreSQL hot path, failover replay and reconciliation, then shadow-record usage and estimated cost without debiting credits.
  • Milestone 3, Charge and Enforce: create auditable usage charges, debit the shared wallet idempotently, return budget verdicts on heartbeats, and pause containers at the configured balance floor.
  • Focus review on the restricted SKU mutation surface, start-admission idempotency across PostgreSQL outages, lifecycle retry/fencing behavior, and the primary-backed creditManagerProcedure authorization change.
  • Review this PR as a Foundation boundary rather than a partially deployed meter: there is deliberately no production producer traffic until Milestone 2 supplies PostgreSQL application, drain/reconciliation, and admission/mutation reclamation together.

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