Skip to content

Promote test → main: free-tier card gate + instant backfill drain (chat#1796)#672

Merged
sweetmantech merged 1 commit into
mainfrom
test
Jun 16, 2026
Merged

Promote test → main: free-tier card gate + instant backfill drain (chat#1796)#672
sweetmantech merged 1 commit into
mainfrom
test

Conversation

@sweetmantech

@sweetmantech sweetmantech commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Promote #671 from test to main (prod).

  • Free-tier card-on-file link — the Songstats gate now issues a Stripe mode:"setup" ($0, no subscription) checkout instead of the $99/mo subscription.
  • Instant backfill drain — a historical job kicks songstatsBackfillWorkflow immediately (budget-gated, SKIP LOCKED; cron stays backstop). Verified on preview: enqueue → done in ~10s.

After this lands, a fresh prod agent key on a historical job returns the new $0 setup checkout link.


Summary by cubic

Switches the Songstats gate to a free-tier card-on-file checkout and starts historical backfill immediately after enqueue to reduce wait time.

  • New Features
    • Free-tier card gate: added createCardOnFileSession using Stripe Checkout mode: "setup" ($0, no subscription). Used when no customer or no default payment method.
    • Instant backfill drain: after enqueuing a historical job, call start from workflow/api to run songstatsBackfillWorkflow right away. Budget-gated and SKIP LOCKED; only triggers when items were enqueued.

Written for commit f99277e. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

Release Notes

  • Improvements
    • Enhanced payment method collection process with a dedicated card setup flow for secure payment information storage.
    • Improved reliability of background data synchronization with better error handling to ensure uninterrupted data consistency.

…ckfill drain (#671)

Two chat#1796 refinements on the historical (Songstats) path:

1. Free-tier card-on-file link. The gate was issuing the paid subscription
   checkout ($99/mo after a 30-day trial). New createCardOnFileSession uses
   Stripe Checkout `mode: "setup"` — collects a card for $0, no subscription,
   no Stripe product. The account then pays only for metered usage via credits.

2. Instant drain. After enqueuing a historical job, fire-and-forget
   start(songstatsBackfillWorkflow) so the backfill begins immediately instead
   of waiting up to 24h for the cron. Safe by reuse: the workflow's budget gate
   (limit − reserve − rolling-30d ledger) caps it to the Songstats quota and
   SKIP LOCKED prevents double-claiming with the daily cron, which stays as the
   backstop. Only kicks when something was actually enqueued.

26 new/updated unit tests; research+stripe+workflows suite 453 green; tsc/lint/format clean.
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api Building Building Preview Jun 16, 2026 4:41pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fe2665b5-8878-44d4-9f44-939c83e1f059

📥 Commits

Reviewing files that changed from the base of the PR and between dfd9004 and f99277e.

⛔ Files ignored due to path filters (3)
  • lib/research/measurement_jobs/__tests__/enqueueHistoricalBackfill.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
  • lib/research/measurement_jobs/__tests__/ensureSongstatsPaymentMethod.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
  • lib/stripe/__tests__/createCardOnFileSession.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (3)
  • lib/research/measurement_jobs/enqueueHistoricalBackfill.ts
  • lib/research/measurement_jobs/ensureSongstatsPaymentMethod.ts
  • lib/stripe/createCardOnFileSession.ts

📝 Walkthrough

Walkthrough

Adds a new createCardOnFileSession utility that creates a Stripe Checkout mode: "setup" session for card-on-file storage. ensureSongstatsPaymentMethod is updated to use this instead of createStripeSession. Additionally, enqueueHistoricalBackfill now conditionally starts songstatsBackfillWorkflow when at least one item is enqueued, with errors caught and logged.

Changes

Songstats Measurement Job Improvements

Layer / File(s) Summary
Card-on-file Stripe session creation
lib/stripe/createCardOnFileSession.ts
New module exports createCardOnFileSession(accountId, successUrl), which resolves a Stripe customer and creates a mode: "setup" Checkout session with client_reference_id, metadata, and success_url.
Payment method guard wiring
lib/research/measurement_jobs/ensureSongstatsPaymentMethod.ts
Replaces createStripeSession import with createCardOnFileSession; the call site passes accountId and CREDIT_AUTO_RECHARGE_FALLBACK_SUCCESS_URL, and the resulting session.url is returned in the existing 402 response.
Backfill drain workflow kick
lib/research/measurement_jobs/enqueueHistoricalBackfill.ts
Imports start and songstatsBackfillWorkflow; after enqueue, starts the drain workflow when enqueued > 0, wrapped in try/catch to isolate scheduling failures from the enqueue success path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • recoupable/api#668: Directly touches enqueueHistoricalBackfill.ts and the Songstats backfill enqueue/drain coordination logic that this PR extends with the workflow kick.

Poem

A card slips on file, no plan in the way,
Setup mode whispers "you're good for today."
The backfill is queued, the workflow ignites,
A try/catch stands guard through the scheduling nights.
Clean, solid, and wired — the pipeline's delight! 🎸

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sweetmantech sweetmantech merged commit e10217e into main Jun 16, 2026
5 of 7 checks passed
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