Skip to content

Commit cb12ceb

Browse files
fix(preproc-errors): should not charge base execution cost in this case (#2719)
* fix(preproc-errors): should not charge base execution cost in this case * remove comment
1 parent 0f32310 commit cb12ceb

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

apps/sim/lib/execution/preprocessing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ async function logPreprocessingError(params: {
541541
stackTrace: undefined,
542542
},
543543
traceSpans: [],
544+
skipCost: true, // Preprocessing errors should not charge - no execution occurred
544545
})
545546

546547
logger.debug(`[${requestId}] Logged preprocessing error to database`, {

apps/sim/lib/logs/execution/logging-session.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface SessionErrorCompleteParams {
4545
stackTrace?: string
4646
}
4747
traceSpans?: TraceSpan[]
48+
skipCost?: boolean
4849
}
4950

5051
export interface SessionCancelledParams {
@@ -342,27 +343,39 @@ export class LoggingSession {
342343
}
343344

344345
try {
345-
const { endedAt, totalDurationMs, error, traceSpans } = params
346+
const { endedAt, totalDurationMs, error, traceSpans, skipCost } = params
346347

347348
const endTime = endedAt ? new Date(endedAt) : new Date()
348349
const durationMs = typeof totalDurationMs === 'number' ? totalDurationMs : 0
349350
const startTime = new Date(endTime.getTime() - Math.max(1, durationMs))
350351

351352
const hasProvidedSpans = Array.isArray(traceSpans) && traceSpans.length > 0
352353

353-
const costSummary = hasProvidedSpans
354-
? calculateCostSummary(traceSpans)
355-
: {
356-
totalCost: BASE_EXECUTION_CHARGE,
354+
const costSummary = skipCost
355+
? {
356+
totalCost: 0,
357357
totalInputCost: 0,
358358
totalOutputCost: 0,
359359
totalTokens: 0,
360360
totalPromptTokens: 0,
361361
totalCompletionTokens: 0,
362-
baseExecutionCharge: BASE_EXECUTION_CHARGE,
362+
baseExecutionCharge: 0,
363363
modelCost: 0,
364364
models: {},
365365
}
366+
: hasProvidedSpans
367+
? calculateCostSummary(traceSpans)
368+
: {
369+
totalCost: BASE_EXECUTION_CHARGE,
370+
totalInputCost: 0,
371+
totalOutputCost: 0,
372+
totalTokens: 0,
373+
totalPromptTokens: 0,
374+
totalCompletionTokens: 0,
375+
baseExecutionCharge: BASE_EXECUTION_CHARGE,
376+
modelCost: 0,
377+
models: {},
378+
}
366379

367380
const message = error?.message || 'Execution failed before starting blocks'
368381

0 commit comments

Comments
 (0)