Add Autumn prepaid billing#390
Merged
Merged
Conversation
…puter into prepaid-billing # Conflicts: # cloudflare-workers/api-edge/src/autumn_webhook.ts # cloudflare-workers/api-edge/src/dashboard.ts # cloudflare-workers/api-edge/src/index.ts # cloudflare-workers/schema_phase6.sql # cmd/server/main.go # internal/db/usage.go # web/src/api/client.ts # web/src/pages/Billing.tsx
added 2 commits
June 22, 2026 20:10
Both are isolated (nothing references them): the migration CLI is an unverified ops helper for a later deliberate per-org cutover, and the dev script is a local billing/parity test aid. Reintroduce the migrate tool when migrations are actually run + tested.
# Conflicts: # cloudflare-workers/schema_phase6.sql # web/src/pages/Billing.tsx
motatoes
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Autumn prepaid billing
Replaces the legacy free-trial/credit system with prepaid credits on
Autumn. A new org gets $5, tops up at the same
per-second rates, can opt into auto-recharge, and subscribes to
concurrency tiers as a separate paid axis (Base 5 free / Pro 100 / Pro+
600 / Pro++ 1000 / contact-us). Credit ledger, metering, top-ups,
auto-recharge, and concurrency plans all live in Autumn; we keep only
hot-path projections.
TL;DR for reviewers (the 3 things people ask)
only two fields into D1 —
is_haltedandmax_concurrent_sandboxes— so thecreate/wake gates never make a synchronous Autumn call.
centralized at the edge. The cell-side change in
cmd/serveris adeletion: it removes the old per-cell
AutumnReporter. The cell nowonly executes a halt the edge dispatches to it (
/admin/halt-org) — itnever reports billing.
cellstable? No. The only schema change is onorgs(billing_provider,autumn_usage_watermark). TheUPDATE cellsinthe diff is the pre-existing capacity reporter from the multi-cell PR; the
edge only reads
cellsfor routing.Dormant on merge
No-op until activated. Only orgs with
billing_provider='autumn'take theAutumn path; everyone else stays on legacy. New signups go to Autumn only when
AUTUMN_NEW_ORGS=true, and the meter no-ops unlessAUTUMN_SECRET_KEYis set.Existing orgs migrate later via a deliberate, notified process — no org is
ever on both billers.
How billing flows — one source, one biller per provider
This reuses the existing edge-authoritative billing model. Both legacy and
autumn read the same single source (
usage_samplesin D1); they differonly in which biller drains it:
usage_samples(D1)billing-rollupworker → Stripeusage_samples(D1)autumn-meteredge cron → Autumnevents-ingestlands autumn usage intousage_samples(same rows legacy uses).billing-rollupexcludes autumn from its Stripe aggregation → no double-bill.autumn-meter(one worker, 5-min cron) tracks per-tier usage to Autumn off aper-org watermark; on exhaustion it calls
projectOrg(setsis_halted,dispatches a hibernate to the owning cell).
is_halted/max_concurrentprojected to D1; gates read theprojection with an Autumn self-heal. Resume is unblock-only (no auto-wake).
Free tier is going away, so autumn orgs are exempt from the legacy free-tier
size ceiling: memory/CPU unrestricted (metered per GB-second), disk bounded by
per-org
max_disk_mb(default 20GB, raised on request). The cap-token carriesbilling_providerso cell and edge agree.Billing page
Branches on
billing_provider; legacy orgs keep the legacy UI. Prepaid UI:credits balance, per-sandbox usage breakdown, top-up, concurrency tiers,
auto-recharge. Card capture + the auto-recharge arming charge are handled
server-side (Autumn won't fire auto-recharge against a saved-but-never-charged
card, so enabling runs the first recharge once; idempotent, no browser fragility).
Validated on dev (end-to-end)
Prod prerequisites (before/with deploy)
schema_phase7.sqltoopencomputer-prodD1 — addsbilling_providerautumn_usage_watermark(additive, default legacy/0). Must precede theworker deploy (
loadOrgPolicy/ metering / billingSELECT billing_provider).CF_ADMIN_SECRET+EVENT_SECRETalready on the prod edge. At activation:set
AUTUMN_SECRET_KEY+AUTUMN_WEBHOOK_SECRET, register the Autumn webhook,flip
AUTUMN_NEW_ORGS=true. Cron triggers are already inwrangler.prod.toml(no-op until the key is set).
Not in this PR (follow-ups)
AUTUMN_NEW_ORGS) — deliberate, separate.reintroduced when migrations are run + tested. Auto-recharge stays opt-in (ROSCA)