Skip to content

improvement(billing): duplicate checks for bypasses, logger billing actor consistency, run from block - #3107

Merged
icecrasher321 merged 5 commits into
stagingfrom
fix/billing-checks-extra
Feb 2, 2026
Merged

improvement(billing): duplicate checks for bypasses, logger billing actor consistency, run from block#3107
icecrasher321 merged 5 commits into
stagingfrom
fix/billing-checks-extra

Conversation

@icecrasher321

Copy link
Copy Markdown
Collaborator

Summary

  • Run from block should call preprocess executions for billing checks
  • Duplicate active subs should loudly error
  • Logger should hit billing actor similar to preprocess
  • Consolidate into helpers for dup checks, block/unblock users

Type of Change

  • Bug fix
  • Other: Code Improvement

Testing

Tested manually

Checklist

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

@vercel

vercelBot commented Feb 1, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
docsSkippedSkippedFeb 2, 2026 6:12pm

Request Review

@greptile-apps

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR strengthens billing integrity by adding duplicate subscription checks, ensuring billing actor consistency, and extending billing enforcement to run-from-block executions.

Key Changes

  • Run-from-block billing enforcement: execute-from-block route now calls preprocessExecution to enforce billing checks, usage limits, and rate limits before execution
  • Duplicate subscription prevention: Added hasActiveSubscription checks across checkout, subscription transfer, and organization creation flows to prevent multiple active subscriptions on the same referenceId
  • Logger billing consistency: ExecutionLogger now uses workspace billed account resolution (via getWorkspaceBilledAccountUserId) matching the preprocessing logic
  • Consolidated blocking helpers: Created blockOrgMembers and unblockOrgMembers functions to centralize organization member blocking/unblocking logic
  • Enhanced dispute handling: Dispute webhook now blocks all org members (not just owner) and handles warning_closed status for unblocking
  • Organization deletion safety: Subscription deletion now checks for other active subscriptions before deleting organizations

Architecture Impact

The changes consolidate billing logic into reusable helpers and ensure consistent billing actor resolution across execution paths. The duplicate subscription checks create multiple defense layers at authorization, checkout, transfer, and organization creation points.

Confidence Score: 5/5

  • Safe to merge - improves billing integrity with defensive checks
  • All changes are defensive improvements to billing logic. The duplicate subscription checks prevent edge cases, billing actor consistency ensures correct cost attribution, and the run-from-block enforcement closes a bypass. Code is well-structured with proper error handling.
  • No files require special attention

Important Files Changed

FilenameOverview
apps/sim/app/api/workflows/[id]/execute-from-block/route.tsAdded preprocessExecution call to enforce billing checks, rate limits, and usage limits for run-from-block executions
apps/sim/lib/logs/execution/logger.tsUpdated to use workspace billed account for cost tracking, matching billing actor logic from preprocessing
apps/sim/lib/billing/organizations/membership.tsAdded helper functions blockOrgMembers, unblockOrgMembers, and getOrgMemberIds to centralize organization member blocking logic
apps/sim/lib/billing/authorization.tsAdded duplicate subscription check in authorization to prevent multiple active subscriptions on same referenceId
apps/sim/lib/billing/webhooks/invoices.tsRefactored to use blockOrgMembers and unblockOrgMembers helpers for consistent member blocking on payment failures

Sequence Diagram

sequenceDiagram
participant Client
participant ExecuteAPI as Execute-from-Block API
participant Preprocessing as preprocessExecution
participant Billing as Billing Module
participant Logger as ExecutionLogger
participant DB as Database
Client->>ExecuteAPI: POST /workflows/{id}/execute-from-block
ExecuteAPI->>Preprocessing: Check billing & limits
Preprocessing->>DB: Fetch workflow record
DB-->>Preprocessing: Workflow details
Preprocessing->>Billing: Get workspace billed account
Billing-->>Preprocessing: actorUserId
Preprocessing->>Billing: Check usage limits
Billing-->>Preprocessing: Usage check result
alt Usage exceeded or blocked
Preprocessing-->>ExecuteAPI: Error (402/403)
ExecuteAPI-->>Client: Execution blocked
else Checks passed
Preprocessing-->>ExecuteAPI: Success with actorUserId
ExecuteAPI->>ExecuteAPI: Execute workflow
ExecuteAPI->>Logger: Log execution with costs
Logger->>Billing: Get workspace billed account
Billing-->>Logger: billingUserId
Logger->>DB: Update userStats (billing actor)
DB-->>Logger: Updated
Logger-->>ExecuteAPI: Logged
ExecuteAPI-->>Client: Execution result
end
Loading

@greptile-appsgreptile-appsBot 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.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Comment threadapps/sim/lib/billing/organizations/membership.ts
Comment threadapps/sim/lib/billing/webhooks/disputes.ts
@icecrasher321

Copy link
Copy Markdown
CollaboratorAuthor

@cursor review

Comment threadapps/sim/lib/billing/core/subscription.ts
@icecrasher321

Copy link
Copy Markdown
CollaboratorAuthor

@cursor review

Comment threadapps/sim/lib/billing/authorization.ts
@icecrasher321

Copy link
Copy Markdown
CollaboratorAuthor

@cursor review

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@icecrasher321
icecrasher321 merged commit 0449804 into stagingFeb 2, 2026
12 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/billing-checks-extra branch February 3, 2026 18:04
royceP2 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Mar 3, 2026
…ctor consistency, run from block (simstudioai#3107)
* improvement(billing): improve against direct subscription creation bypasses
* more usage of block/unblock helpers
* address bugbot comments
* fail closed
* only run dup check for orgs
Sign up for freeto 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

@icecrasher321