From b5407756d8a6c2fb00bb7cae520eb48f62c38e93 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Wed, 1 Apr 2026 11:29:04 -0700 Subject: [PATCH] fix(cost): worker crash incremenental case --- apps/sim/lib/logs/execution/logging-session.test.ts | 10 ++++++---- apps/sim/lib/logs/execution/logging-session.ts | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/sim/lib/logs/execution/logging-session.test.ts b/apps/sim/lib/logs/execution/logging-session.test.ts index a44bc5e72d5..dfc2a306d2e 100644 --- a/apps/sim/lib/logs/execution/logging-session.test.ts +++ b/apps/sim/lib/logs/execution/logging-session.test.ts @@ -391,10 +391,12 @@ describe('LoggingSession completion retries', () => { await session.onBlockComplete('block-2', 'Transform', 'function', { endedAt: '2025-01-01T00:00:01.000Z', - output: { value: true }, - cost: { total: 1, input: 1, output: 0 }, - tokens: { input: 1, output: 0, total: 1 }, - model: 'test-model', + output: { + value: true, + cost: { total: 1, input: 1, output: 0 }, + tokens: { input: 1, output: 0, total: 1 }, + model: 'test-model', + }, }) const completionPromise = session.safeComplete({ finalOutput: { ok: true } }) diff --git a/apps/sim/lib/logs/execution/logging-session.ts b/apps/sim/lib/logs/execution/logging-session.ts index 7fb72bc1d73..3b0a20bd642 100644 --- a/apps/sim/lib/logs/execution/logging-session.ts +++ b/apps/sim/lib/logs/execution/logging-session.ts @@ -294,11 +294,16 @@ export class LoggingSession { }) ) - if (!output?.cost || typeof output.cost.total !== 'number' || output.cost.total <= 0) { + const blockOutput = output?.output + if ( + !blockOutput?.cost || + typeof blockOutput.cost.total !== 'number' || + blockOutput.cost.total <= 0 + ) { return } - const { cost, tokens, model } = output + const { cost, tokens, model } = blockOutput this.accumulatedCost.total += cost.total || 0 this.accumulatedCost.input += cost.input || 0