Skip to content

fix(billing): release audit follow-ups for v0.9.66 - #10433

Merged
waleedlatif1 merged 4 commits into
stagingfrom
fix/release-audit-billing-v0966
Nov 26, 2026
Merged

waleedlatif1 merged 4 commits into
stagingfrom
fix/release-audit-billing-v0966

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Migrations 0471, 0473 and 0474 are now replay-safe. 0470's embedded COMMIT leaves later pending files in autocommit, and a lock-timeout retry replays them from the top. They now use IF NOT EXISTS and FKs guarded on pg_constraint.
  • A Team upgrade is refused while the personal Pro plan is still trialing. Stripe keeps the trial across the price change, so the team would otherwise run free without the trial's cap.
  • Ending a trial early uses payment_behavior: 'error_if_incomplete', maps a card decline to a payer error, and refuses a trial already cancelled at period end.
  • If a free payer's credit balance can't be read, the hosted-key gate now throws instead of denying. The run fails as a fault and no longer disables the schedule as "paid plan required". A model call with the payer's own key still falls back to it.
  • The Web Search refusal no longer suggests BYOK, which Search doesn't support. The schedule-disabled copy now matches.
  • Annual Team seat-months advance only from the count they were computed from (compare-and-set), so racing seat syncs, webhooks or sweeps can't rebase the limit twice. The sweep's interval backfill now only fills an empty column.
  • Plan switch:
    • keeps the on-demand headroom read before the Stripe update, even when the webhook raised the limit first
    • on an interval change, records the period Stripe restarted, so threshold billing never prices a year of usage against a month's allowance
    • rounds rebased limits to cents
  • Payment-succeeded skips the open-invoice listing for a payer who isn't blocked, and logs the real reason when it skips an unblock.
  • Cleanups:
    • reuse formatMonthlyPlanPrice, a shared AVERAGE_MONTH_MS, and the deletion's resolved owner id for the plan-ended email
    • run independent reads in parallel
    • the end-trial mutation refetches on success only
    • drop a unit test that restated a two-line helper

Type of Change

  • Bug fix

Testing

  • Integration against real Postgres (bun run test:integration):
    • plan-allowance 22/22, free-plan 13/13, trial 27/27, enterprise-self-serve 13/13
    • red→green: each new case fails with its fix reverted (pre-switch headroom, restarted period, Search copy, end-trial payment_behavior/cancel/decline, trial→Team guard)
  • Migrations 0471/0473/0474 applied twice on a scratch Postgres 17: the second pass is a no-op, with each FK present once
  • Vitest: invoices.test.ts, switch-plan/route.test.ts, subscriptions/utils.test.ts, byok.test.ts, tools/index.test.ts
  • bun run lint, bun run check:migrations origin/staging. Type-check and audits run in CI.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

- migrations 0471, 0473 and 0474 are replay-safe after 0470's embedded COMMIT
- a Team upgrade is refused while the personal Pro plan is still trialing
- ending a trial early never starts a past-due plan on a declined card, and refuses a cancelled trial
- a credit balance that can't be read fails a hosted-key run as a fault, not as the free plan, so a schedule is not disabled for it
- the Web Search refusal no longer offers BYOK, which Search does not support
- annual seat-months advance only from the count they were computed from, so racing syncs cannot rebase twice
- a plan switch keeps the headroom read before Stripe applied it, and records the period Stripe restarted on an interval change
- payment-succeeded skips the open-invoice listing for an unblocked payer
- reuse formatMonthlyPlanPrice, AVERAGE_MONTH_MS and the deletion's owner id; parallel independent reads
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 26, 2026 8:15pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The changes since the last review appear safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the last review appear safe to merge.

Summary

This PR fixes billing follow-ups around migration retries, trial payments, hosted keys, and plan allowances.

Since the last review:

  • Plan switches keep the usage choices made before the change.
  • Annual Team seat changes update the allowance only from current data.
  • A Pro trial must end before its owner can upgrade to Team.
  • Hosted-key checks fail as faults when a free payer's balance is unavailable.
  • Web Search no longer suggests adding an API key it cannot use.
  • Paid invoices skip extra checks when the payer is not blocked.
  • The trial and annual billing migrations can run again without duplicating objects.
  • Billing notices reuse the owner already found for a subscription event.
  • Billing settings use the shared monthly price display.
  • The standalone weekly-refresh test is removed.

No new actionable issues were found in these changes.

Reviews (4) · Last reviewed commit: "fix(billing): serialize plan switches pe..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 28 files

This PR changes payment, billing, or quota logic. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/billing/organization.ts Resolved
Comment thread apps/sim/hooks/queries/subscription.ts Resolved
Comment thread apps/sim/lib/billing/authorization.ts Resolved
…tries, tighter seat-month claim

- the plan-switch rebase reads headroom from the limit and credit balance read before Stripe, keeping the exact-floor guard for a retry
- a retry that finds Stripe already on the target price records the retrieved item's period
- the annual seat-month claim also matches plan, period, seats and interval
- only a personal Pro trial blocks a Team upgrade
- end-trial refetches on settle, since a lost response can hide a completed charge
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 28 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

…the Stripe switch

A pre-switch snapshot predates any webhook, so a limit in it at the new allowance is headroom the payer chose. A retry that finds Stripe already switched takes no snapshot and keeps the live-limit guard.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 28 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

A switch takes the billing reference's checkout admission claim and re-checks that the subscription still holds the plan and interval it computed from, so a concurrent switch cannot snapshot another's new allowance as chosen headroom.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 28 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 212567b into staging Nov 26, 2026
84 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/release-audit-billing-v0966 branch November 26, 2026 21:31

This branch was previously deployed

1 inactive deployment
Preview — 97840daf Deployed Nov 26, 2026 by vercel[bot]
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