Skip to content

Commit 70ff60a

Browse files
committed
code cleanup?
1 parent 5a3ff0f commit 70ff60a

File tree

1 file changed

+56
-73
lines changed

1 file changed

+56
-73
lines changed

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

Lines changed: 56 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -330,89 +330,72 @@ export class LoggingSession {
330330
async safeComplete(params: SessionCompleteParams = {}): Promise<void> {
331331
try {
332332
await this.complete(params)
333-
} catch (error) {
334-
logger.warn(
335-
`[${this.requestId || 'unknown'}] Logging completion failed for execution ${this.executionId} - attempting cost-only fallback`
336-
)
337-
338-
try {
339-
const costSummary = calculateCostSummary(params.traceSpans || [])
340-
const endTime = params.endedAt || new Date().toISOString()
341-
const duration = params.totalDurationMs || 0
342-
343-
await executionLogger.completeWorkflowExecution({
344-
executionId: this.executionId,
345-
endedAt: endTime,
346-
totalDurationMs: duration,
347-
costSummary,
348-
finalOutput: { _fallback: true, error: 'Trace spans too large to store' },
349-
traceSpans: [],
350-
isResume: this.isResume,
351-
})
352-
353-
logger.info(
354-
`[${this.requestId || 'unknown'}] Cost-only fallback succeeded for execution ${this.executionId}`
355-
)
356-
} catch (fallbackError) {
357-
logger.error(
358-
`[${this.requestId || 'unknown'}] Cost-only fallback also failed for execution ${this.executionId}:`,
359-
{
360-
error: fallbackError instanceof Error ? fallbackError.message : String(fallbackError),
361-
}
362-
)
363-
}
333+
} catch {
334+
await this.completeWithCostOnlyLog({
335+
traceSpans: params.traceSpans,
336+
endedAt: params.endedAt,
337+
totalDurationMs: params.totalDurationMs,
338+
errorMessage: 'Trace spans too large to store',
339+
})
364340
}
365341
}
366342

367343
async safeCompleteWithError(params?: SessionErrorCompleteParams): Promise<void> {
368344
try {
369345
await this.completeWithError(params)
370-
} catch (error) {
371-
logger.warn(
372-
`[${this.requestId || 'unknown'}] Error logging completion failed for execution ${this.executionId} - attempting cost-only fallback`
373-
)
346+
} catch {
347+
await this.completeWithCostOnlyLog({
348+
traceSpans: params?.traceSpans,
349+
endedAt: params?.endedAt,
350+
totalDurationMs: params?.totalDurationMs,
351+
errorMessage: params?.error?.message || 'Execution failed, trace spans too large to store',
352+
})
353+
}
354+
}
374355

375-
try {
376-
const costSummary = params?.traceSpans
377-
? calculateCostSummary(params.traceSpans)
378-
: {
379-
totalCost: BASE_EXECUTION_CHARGE,
380-
totalInputCost: 0,
381-
totalOutputCost: 0,
382-
totalTokens: 0,
383-
totalPromptTokens: 0,
384-
totalCompletionTokens: 0,
385-
baseExecutionCharge: BASE_EXECUTION_CHARGE,
386-
modelCost: 0,
387-
models: {},
388-
}
356+
private async completeWithCostOnlyLog(params: {
357+
traceSpans?: TraceSpan[]
358+
endedAt?: string
359+
totalDurationMs?: number
360+
errorMessage: string
361+
}): Promise<void> {
362+
logger.warn(
363+
`[${this.requestId || 'unknown'}] Logging completion failed for execution ${this.executionId} - attempting cost-only fallback`
364+
)
389365

390-
const endTime = params?.endedAt || new Date().toISOString()
391-
const duration = params?.totalDurationMs || 0
366+
try {
367+
const costSummary = params.traceSpans?.length
368+
? calculateCostSummary(params.traceSpans)
369+
: {
370+
totalCost: BASE_EXECUTION_CHARGE,
371+
totalInputCost: 0,
372+
totalOutputCost: 0,
373+
totalTokens: 0,
374+
totalPromptTokens: 0,
375+
totalCompletionTokens: 0,
376+
baseExecutionCharge: BASE_EXECUTION_CHARGE,
377+
modelCost: 0,
378+
models: {},
379+
}
392380

393-
await executionLogger.completeWorkflowExecution({
394-
executionId: this.executionId,
395-
endedAt: endTime,
396-
totalDurationMs: duration,
397-
costSummary,
398-
finalOutput: {
399-
_fallback: true,
400-
error: params?.error?.message || 'Execution failed, trace spans too large to store',
401-
},
402-
traceSpans: [],
403-
})
381+
await executionLogger.completeWorkflowExecution({
382+
executionId: this.executionId,
383+
endedAt: params.endedAt || new Date().toISOString(),
384+
totalDurationMs: params.totalDurationMs || 0,
385+
costSummary,
386+
finalOutput: { _fallback: true, error: params.errorMessage },
387+
traceSpans: [],
388+
isResume: this.isResume,
389+
})
404390

405-
logger.info(
406-
`[${this.requestId || 'unknown'}] Cost-only fallback succeeded for execution ${this.executionId}`
407-
)
408-
} catch (fallbackError) {
409-
logger.error(
410-
`[${this.requestId || 'unknown'}] Cost-only fallback also failed for execution ${this.executionId}:`,
411-
{
412-
error: fallbackError instanceof Error ? fallbackError.message : String(fallbackError),
413-
}
414-
)
415-
}
391+
logger.info(
392+
`[${this.requestId || 'unknown'}] Cost-only fallback succeeded for execution ${this.executionId}`
393+
)
394+
} catch (fallbackError) {
395+
logger.error(
396+
`[${this.requestId || 'unknown'}] Cost-only fallback also failed for execution ${this.executionId}:`,
397+
{ error: fallbackError instanceof Error ? fallbackError.message : String(fallbackError) }
398+
)
416399
}
417400
}
418401
}

0 commit comments

Comments
 (0)