fix(cost): worker crash incremenental case (#3885)

This commit is contained in:
Vikhyath Mondreti
2026-04-01 11:42:19 -07:00
committed by GitHub
parent 42fb434354
commit 2ede12aa0e
2 changed files with 13 additions and 6 deletions

View File

@@ -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 } })

View File

@@ -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