Skip to content

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

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/billing-audit-followups-v0966
Nov 27, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/billing-audit-followups-v0966

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • A paid invoice now unblocks an org's members whenever any member is still blocked for payment. The pre-check read only the owner's row, so members stayed blocked for good once the owner's row was cleared another way (another org's recovery, or ownership moving to someone who joined after the block)
  • Plan switches read the subscription and its usage pool in one repeatable-read snapshot under the admission claim, and compute from that read. A seat sync takes no claim, so the old path could price the old seat count against a limit already raised for a new seat
  • A hosted-key plan check that can't read the credit balance fails with a plain message instead of the raw database error
  • The "end your trial before Team" message now covers a trial that was canceled (restore it first, or wait it out)

Type of Change

  • Bug fix

Testing

  • New lib/billing/webhooks/invoices.integration.ts (3): owner already unblocked, another invoice still failing, nobody blocked skips the Stripe listing. The first fails on the current staging invoices.ts
  • plan-allowance.integration.ts (25), including a new case for a seat added after the request read the plan, which fails when the switch computes from the stale read
  • Unit: invoices.test.ts, access.test.ts, tools/index.test.ts, switch-plan/route.test.ts, authorization.test.ts, byok.test.ts (334 passed)
  • biome, check:test-patterns, check:source-conventions, check:comment-hygiene, check:explicit-any

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)

@vercel

vercel Bot commented Nov 27, 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 27, 2026 4:00am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no new actionable issues remain.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues remain.

Summary

This PR fixes payment recovery and makes plan switches read the subscription and usage pool together.

  • Paid invoices can clear payment blocks from every affected organization member.
  • Plan switches use matching subscription and usage details to set the new limit.
  • Hosted-key plan checks show a plain retry message when balance lookup fails.
  • Team-upgrade errors explain what to do with a canceled Pro trial.

The earlier downgrade-retry finding is fixed. waleedlatif1 accepted the seat-sync behavior as intentional because seat sync only raises the limit to the plan-plus-credit floor; it does not preserve a fixed amount of spending room above that floor.

No new actionable issues were found. Tests were inspected but not run.

Reviews (3) · Last reviewed commit: "fix(billing): price a retried switch's o..." · 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 10 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

@waleedlatif1
waleedlatif1 force-pushed the fix/billing-audit-followups-v0966 branch from 0297579 to 6b6da31 Compare November 27, 2026 03:49
@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 27, 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.

3 issues found across 10 files

Confidence score: 3/5

  • In invoices.ts, a member’s personal or other-organization payment_failed row can be mistaken for this organization’s block, so a successful invoice may clear the wrong block. Match the row to the organization’s subscription before unblocking.
  • In switch-plan/route.ts, a subscription transfer between the scope check and recordPlanSwitch can leave the route using stale organization scope and pool data. Revalidate the subscription before recording the switch.
  • In invoices.integration.ts, the paid-invoice fixture does not match the subscription’s Stripe customer, and the mock ignores the customer filter. Use the fixture customer so this test can catch customer-filtering regressions.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/billing/webhooks/invoices.integration.ts">

<violation number="1" location="apps/sim/lib/billing/webhooks/invoices.integration.ts:92">
P2: This fixture does not associate the paid invoice with the subscription's Stripe customer, and the mocked listing ignores its customer filter. Return the fixture customer from `createTeam` and use it in `paidOverageInvoice`, then assert the listing receives that customer so this integration test models the production invoice relationship.</violation>
</file>

<file name="apps/sim/lib/billing/webhooks/invoices.ts">

<violation number="1" location="apps/sim/lib/billing/webhooks/invoices.ts:650">
P1: This check cannot distinguish an organization block from a `payment_failed` row created by a member’s personal or different organization subscription. A successful invoice for this organization can therefore call `unblockOrgMembers` and restore access while the unrelated invoice is still unpaid; scope the block source to the payer/subscription before deciding which rows to clear.</violation>
</file>

<file name="apps/sim/app/api/billing/switch-plan/route.ts">

<violation number="1" location="apps/sim/app/api/billing/switch-plan/route.ts:240">
P2: `basis.subscription` can be re-homed after the initial scope check, but this route still passes the old `orgScoped` and pool snapshot into `recordPlanSwitch`. If a subscription transfer commits between those reads, the switch updates the plan while rebasing the wrong usage pool, leaving the actual allowance stale; validate the reference/scope in the snapshot or reject a re-homed basis before recording.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

- a paid invoice unblocks every member still blocked for payment, not only when the org owner is
- a plan switch reads the subscription and its usage pool in one snapshot under its claim, so a seat
  sync cannot price one seat count against a limit set for another
- a hosted-key plan check that cannot read the balance fails with a plain message, not the raw
  database error
- the Team-during-trial message covers a canceled trial
A seat sync takes no switch claim and can land while Stripe applies the change, so the new
allowance comes from the subscription row locked in the recording transaction. The integration
fixture builds its event with the shared Stripe event helper.
… left

A retry finds the subscription webhook may already have recorded the new plan, so the old
allowance always comes from the request's plan and interval, with the locked seat count for the
live limit. A switch is refused when the subscription moved to another payer since it was read.
The invoice fixture pays from the subscription's own Stripe customer.
@waleedlatif1
waleedlatif1 force-pushed the fix/billing-audit-followups-v0966 branch from 6b6da31 to 6524d22 Compare November 27, 2026 04:00
@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 27, 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 10 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 e691123 into staging Nov 27, 2026
84 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/billing-audit-followups-v0966 branch November 27, 2026 04:11

This branch was previously deployed

1 inactive deployment
Preview — 6524d220 Deployed Nov 27, 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