-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(billing): copilot should directly deduct credit balance #2294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR removes the real-time credit deduction logic from the copilot billing route, which contradicts the PR title and description that state copilot "should directly deduct credit balance." Key Changes:
Critical Issue: This means credits are NOT deducted immediately for copilot usage - they're only applied during invoice generation. If the goal is real-time credit deduction, this PR moves in the opposite direction. Confidence Score: 1/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Copilot
participant UpdateCostAPI
participant DB as Database (userStats)
participant ThresholdBilling
participant Credits as Credit Balance
participant Stripe
Copilot->>UpdateCostAPI: POST /api/billing/update-cost<br/>{userId, cost}
UpdateCostAPI->>UpdateCostAPI: Validate request & auth
UpdateCostAPI->>DB: Check user stats exists
DB-->>UpdateCostAPI: User stats record
Note over UpdateCostAPI,DB: REMOVED: deductFromCredits(userId, cost)
Note over UpdateCostAPI,DB: Now stores FULL cost without credit deduction
UpdateCostAPI->>DB: UPDATE userStats SET<br/>totalCost += cost<br/>currentPeriodCost += cost<br/>totalCopilotCost += cost<br/>currentPeriodCopilotCost += cost
UpdateCostAPI->>ThresholdBilling: checkAndBillOverageThreshold(userId)
ThresholdBilling->>DB: Get subscription & user stats
ThresholdBilling->>ThresholdBilling: Calculate unbilled overage
alt Overage >= threshold AND credits available
ThresholdBilling->>Credits: Deduct credits from balance
Credits-->>ThresholdBilling: Credits applied amount
ThresholdBilling->>Stripe: Create invoice (overage - credits)
Stripe-->>ThresholdBilling: Invoice created
ThresholdBilling->>DB: Update billedOverageThisPeriod
else Overage < threshold OR no credits
Note over ThresholdBilling: No action taken<br/>Credits remain unchanged
end
ThresholdBilling-->>UpdateCostAPI: Complete
UpdateCostAPI-->>Copilot: Success response
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (1)
-
apps/sim/app/api/billing/update-cost/route.ts, line 94-103 (link)logic: This change removes credit deduction from copilot usage tracking, which contradicts both the PR description ("copilot should directly deduct credit balance") and the stated goal of aligning with regular execution cost tracking.
The regular
ExecutionLogger(line 548-563 inlogger.ts) also does NOT calldeductFromCredits- it stores the full cost and defers credit application until threshold billing viacheckAndBillOverageThreshold.However,
checkAndBillOverageThresholdonly applies credits when creating invoices for overage (seethreshold-billing.tslines 164-186 and 406-427). This means:- Credits are NOT deducted in real-time for copilot usage
- Credits are only applied when billing thresholds trigger invoice creation
- The credit balance field won't reflect copilot usage until invoice time
If the intent is to have copilot "directly deduct credit balance" as stated in the PR title and description, this PR actually does the opposite - it removes the only place where credits were being deducted in real-time.
1 file reviewed, 1 comment
Summary
Copilot update cost route directly deducting the credit balance.
Should be in line with regular execution cost tracking.
Type of Change
Testing
Tested manually
Checklist