Skip to content

Commit 4135fdc

Browse files
committed
chore(billing): remove implementation-decision comments
1 parent d4b1593 commit 4135fdc

File tree

5 files changed

+0
-13
lines changed

5 files changed

+0
-13
lines changed

apps/sim/app/api/billing/update-cost/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export async function POST(req: NextRequest) {
100100
additionalStats.totalMcpCopilotCalls = sql`total_mcp_copilot_calls + 1`
101101
}
102102

103-
// Atomic write: usage_log INSERT + userStats UPDATE in one transaction
104103
await recordUsage({
105104
userId,
106105
entries: [

apps/sim/app/api/wand/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ async function updateUserStatsForWand(
134134
costToStore = modelCost * costMultiplier
135135
}
136136

137-
// Atomic write: usage_log INSERT + userStats UPDATE in one transaction
138137
await recordUsage({
139138
userId,
140139
entries: [

apps/sim/lib/billing/core/usage-log.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,22 @@ export async function recordUsage(params: RecordUsageParams): Promise<void> {
8484

8585
const { userId, entries, workspaceId, workflowId, executionId, additionalStats } = params
8686

87-
// Filter to entries with positive cost and derive total
8887
const validEntries = entries.filter((e) => e.cost > 0)
8988
const totalCost = validEntries.reduce((sum, e) => sum + e.cost, 0)
9089

91-
// Nothing to write: no cost entries and no counter increments
9290
if (
9391
validEntries.length === 0 &&
9492
(!additionalStats || Object.keys(additionalStats).length === 0)
9593
) {
9694
return
9795
}
9896

99-
// Keys managed by recordUsage — callers must not override these via additionalStats
10097
const RESERVED_KEYS = new Set(['totalCost', 'currentPeriodCost', 'lastActive'])
10198
const safeStats = additionalStats
10299
? Object.fromEntries(Object.entries(additionalStats).filter(([k]) => !RESERVED_KEYS.has(k)))
103100
: undefined
104101

105102
await db.transaction(async (tx) => {
106-
// Step 1: Insert usage_log entries (only if there are positive-cost entries)
107103
if (validEntries.length > 0) {
108104
await tx.insert(usageLog).values(
109105
validEntries.map((entry) => ({
@@ -121,7 +117,6 @@ export async function recordUsage(params: RecordUsageParams): Promise<void> {
121117
)
122118
}
123119

124-
// Step 2: Update userStats — core billing fields + source-specific counters
125120
const updateFields: Record<string, SQL | Date> = {
126121
lastActive: new Date(),
127122
...(totalCost > 0 && {

apps/sim/lib/logs/execution/logger.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ export class ExecutionLogger implements IExecutionLoggerService {
645645
return
646646
}
647647

648-
// Build usage entries from cost summary
649648
const entries: Array<{
650649
category: 'model' | 'fixed'
651650
source: 'workflow'
@@ -691,7 +690,6 @@ export class ExecutionLogger implements IExecutionLoggerService {
691690
additionalStats[triggerCounter.key] = sql`${sql.raw(triggerCounter.column)} + 1`
692691
}
693692

694-
// Atomic write: usage_log INSERT + userStats UPDATE in one transaction
695693
await recordUsage({
696694
userId,
697695
entries,

apps/sim/tools/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,6 @@ async function processHostedKeyCost(
284284

285285
if (!userId) return { cost, metadata }
286286

287-
// Tool hosting costs are included in the provider response's cost.total
288-
// (see providers/index.ts sumToolCosts), which flows into the execution's
289-
// costSummary and gets recorded atomically via recordUsage() at completion.
290-
// No separate log entry is needed here — that would double-count the cost.
291287
logger.debug(
292288
`[${requestId}] Hosted key cost for ${tool.id}: $${cost}`,
293289
metadata ? { metadata } : {}

0 commit comments

Comments
 (0)