Skip to content

Commit a5a72ef

Browse files
committed
fix(preproc-errors): should not charge base execution cost in this case
1 parent 730ddf5 commit a5a72ef

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-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: 22 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,42 @@ 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+
// When skipCost is true (preprocessing errors), don't charge anything
355+
// When we have trace spans, calculate actual cost from them
356+
// Otherwise, charge the base execution fee for errors that occurred during execution
357+
const costSummary = skipCost
358+
? {
359+
totalCost: 0,
357360
totalInputCost: 0,
358361
totalOutputCost: 0,
359362
totalTokens: 0,
360363
totalPromptTokens: 0,
361364
totalCompletionTokens: 0,
362-
baseExecutionCharge: BASE_EXECUTION_CHARGE,
365+
baseExecutionCharge: 0,
363366
modelCost: 0,
364367
models: {},
365368
}
369+
: hasProvidedSpans
370+
? calculateCostSummary(traceSpans)
371+
: {
372+
totalCost: BASE_EXECUTION_CHARGE,
373+
totalInputCost: 0,
374+
totalOutputCost: 0,
375+
totalTokens: 0,
376+
totalPromptTokens: 0,
377+
totalCompletionTokens: 0,
378+
baseExecutionCharge: BASE_EXECUTION_CHARGE,
379+
modelCost: 0,
380+
models: {},
381+
}
366382

367383
const message = error?.message || 'Execution failed before starting blocks'
368384

0 commit comments

Comments
 (0)