From a5a72efb8a4ffc1212f3259e4fdefd825c9c9fb8 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Wed, 7 Jan 2026 14:43:00 -0800 Subject: [PATCH 1/2] fix(preproc-errors): should not charge base execution cost in this case --- apps/sim/lib/execution/preprocessing.ts | 1 + .../sim/lib/logs/execution/logging-session.ts | 28 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/sim/lib/execution/preprocessing.ts b/apps/sim/lib/execution/preprocessing.ts index b0fcc6c1b9..cab28145e0 100644 --- a/apps/sim/lib/execution/preprocessing.ts +++ b/apps/sim/lib/execution/preprocessing.ts @@ -541,6 +541,7 @@ async function logPreprocessingError(params: { stackTrace: undefined, }, traceSpans: [], + skipCost: true, // Preprocessing errors should not charge - no execution occurred }) logger.debug(`[${requestId}] Logged preprocessing error to database`, { diff --git a/apps/sim/lib/logs/execution/logging-session.ts b/apps/sim/lib/logs/execution/logging-session.ts index 37004d688d..cc689f49a9 100644 --- a/apps/sim/lib/logs/execution/logging-session.ts +++ b/apps/sim/lib/logs/execution/logging-session.ts @@ -45,6 +45,7 @@ export interface SessionErrorCompleteParams { stackTrace?: string } traceSpans?: TraceSpan[] + skipCost?: boolean } export interface SessionCancelledParams { @@ -342,7 +343,7 @@ export class LoggingSession { } try { - const { endedAt, totalDurationMs, error, traceSpans } = params + const { endedAt, totalDurationMs, error, traceSpans, skipCost } = params const endTime = endedAt ? new Date(endedAt) : new Date() const durationMs = typeof totalDurationMs === 'number' ? totalDurationMs : 0 @@ -350,19 +351,34 @@ export class LoggingSession { const hasProvidedSpans = Array.isArray(traceSpans) && traceSpans.length > 0 - const costSummary = hasProvidedSpans - ? calculateCostSummary(traceSpans) - : { - totalCost: BASE_EXECUTION_CHARGE, + // When skipCost is true (preprocessing errors), don't charge anything + // When we have trace spans, calculate actual cost from them + // Otherwise, charge the base execution fee for errors that occurred during execution + const costSummary = skipCost + ? { + totalCost: 0, totalInputCost: 0, totalOutputCost: 0, totalTokens: 0, totalPromptTokens: 0, totalCompletionTokens: 0, - baseExecutionCharge: BASE_EXECUTION_CHARGE, + baseExecutionCharge: 0, modelCost: 0, models: {}, } + : hasProvidedSpans + ? calculateCostSummary(traceSpans) + : { + totalCost: BASE_EXECUTION_CHARGE, + totalInputCost: 0, + totalOutputCost: 0, + totalTokens: 0, + totalPromptTokens: 0, + totalCompletionTokens: 0, + baseExecutionCharge: BASE_EXECUTION_CHARGE, + modelCost: 0, + models: {}, + } const message = error?.message || 'Execution failed before starting blocks' From 7fd63a4f7b41e5754035317386892066f2df557e Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Wed, 7 Jan 2026 14:44:49 -0800 Subject: [PATCH 2/2] remove comment --- apps/sim/lib/logs/execution/logging-session.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/sim/lib/logs/execution/logging-session.ts b/apps/sim/lib/logs/execution/logging-session.ts index cc689f49a9..d618be12bc 100644 --- a/apps/sim/lib/logs/execution/logging-session.ts +++ b/apps/sim/lib/logs/execution/logging-session.ts @@ -351,9 +351,6 @@ export class LoggingSession { const hasProvidedSpans = Array.isArray(traceSpans) && traceSpans.length > 0 - // When skipCost is true (preprocessing errors), don't charge anything - // When we have trace spans, calculate actual cost from them - // Otherwise, charge the base execution fee for errors that occurred during execution const costSummary = skipCost ? { totalCost: 0,