Skip to content

Commit d29d613

Browse files
author
Theodore Li
committed
Fix usage log double logging data
1 parent 427627a commit d29d613

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

apps/sim/providers/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ export function prepareToolExecution(
11541154
? { isDeployedContext: request.isDeployedContext }
11551155
: {}),
11561156
...(request.callChain ? { callChain: request.callChain } : {}),
1157+
skipFixedUsageLog: true,
11571158
},
11581159
}
11591160
: {}),

apps/sim/tools/index.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -277,24 +277,30 @@ async function processHostedKeyCost(
277277

278278
if (!userId) return { cost, metadata }
279279

280-
// Log to usageLog table for audit trail
281-
try {
282-
await logFixedUsage({
283-
userId,
284-
source: 'workflow',
285-
description: `tool:${tool.id}`,
286-
cost,
287-
workspaceId: wsId,
288-
workflowId: wfId,
289-
executionId: executionContext?.executionId,
290-
metadata,
291-
})
280+
const skipLog = !!ctx?.skipFixedUsageLog
281+
if (!skipLog) {
282+
try {
283+
await logFixedUsage({
284+
userId,
285+
source: 'workflow',
286+
description: `tool:${tool.id}`,
287+
cost,
288+
workspaceId: wsId,
289+
workflowId: wfId,
290+
executionId: executionContext?.executionId,
291+
metadata,
292+
})
293+
logger.debug(
294+
`[${requestId}] Logged hosted key cost for ${tool.id}: $${cost}`,
295+
metadata ? { metadata } : {}
296+
)
297+
} catch (error) {
298+
logger.error(`[${requestId}] Failed to log hosted key usage for ${tool.id}:`, error)
299+
}
300+
} else {
292301
logger.debug(
293-
`[${requestId}] Logged hosted key cost for ${tool.id}: $${cost}`,
294-
metadata ? { metadata } : {}
302+
`[${requestId}] Skipping fixed usage log for ${tool.id} (cost will be tracked via provider tool loop)`
295303
)
296-
} catch (error) {
297-
logger.error(`[${requestId}] Failed to log hosted key usage for ${tool.id}:`, error)
298304
}
299305

300306
return { cost, metadata }

0 commit comments

Comments
 (0)