Uh oh!
There was an error while loading. Please reload this page.
fix(billing): atomize usage_log and userStats writes via central recordUsage() - #3767
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Migrates callers to the new path. Updates the billing cost update API, Prevents tool-cost double counting and removes dead flags. Stops logging hosted-key tool costs as separate fixed usage entries (costs are expected to flow through provider totals), removes Written by Cursor Bugbot for commit d1e72b4. Configure here. |
Uh oh!
There was an error while loading. Please reload this page.
Greptile SummaryThis PR fixes cost-drift between Key changes:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller as Caller<br/>(ExecutionLogger / update-cost / wand)
participant RU as recordUsage()
participant TX as Postgres Transaction
participant UL as usage_log table
participant US as userStats table
Caller->>RU: recordUsage({ userId, entries, additionalStats })
alt billing disabled
RU-->>Caller: return (no-op)
else no valid entries AND no additionalStats
RU-->>Caller: return (no-op)
else
RU->>RU: filter entries (cost > 0), sum totalCost
RU->>RU: strip RESERVED_KEYS from additionalStats → safeStats
RU->>TX: begin transaction
alt validEntries.length > 0
TX->>UL: INSERT rows (one per entry)
end
TX->>US: UPDATE SET totalCost+=, currentPeriodCost+=, lastActive, ...safeStats WHERE userId
alt userStats row not found
TX-->>RU: result = []
RU->>TX: THROW (rollback)
TX-->>Caller: error propagated
else
TX-->>RU: commit
RU-->>Caller: void (success)
end
end
Reviews (2): Last reviewed commit: "chore(lint): fix formatting in hubspot l..." | Re-trigger Greptile |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
cd79dcf to
d1e72b4Comparewaleedlatif1
commented
Mar 25, 2026
waleedlatif1
commented
Mar 25, 2026
@cursor review |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…rdUsage (#3767) * fix(billing): atomize usage_log and userStats writes via central recordUsage() * fix(billing): address PR review — re-throw errors, guard reserved keys, handle zero-cost counters * chore(lint): fix formatting in hubspot list_lists.ts from staging * fix(billing): tighten early-return guard to handle empty additionalStats object * lint * chore(billing): remove implementation-decision comments
…rdUsage (#3767) * fix(billing): atomize usage_log and userStats writes via central recordUsage() * fix(billing): address PR review — re-throw errors, guard reserved keys, handle zero-cost counters * chore(lint): fix formatting in hubspot list_lists.ts from staging * fix(billing): tighten early-return guard to handle empty additionalStats object * lint * chore(billing): remove implementation-decision comments
…rdUsage (#3767) * fix(billing): atomize usage_log and userStats writes via central recordUsage() * fix(billing): address PR review — re-throw errors, guard reserved keys, handle zero-cost counters * chore(lint): fix formatting in hubspot list_lists.ts from staging * fix(billing): tighten early-return guard to handle empty additionalStats object * lint * chore(billing): remove implementation-decision comments
Summary
recordUsage()wraps usage_log INSERT + userStats UPDATE in a single Postgres transaction, fixing drift betweencurrentPeriodCostandusage_logrecordUsage()logFixedUsage) — tool costs already included in model totals via provider responseskipFixedUsageLog, old helper functions, stale test mocksType of Change
Testing
Checklist