diff --git a/.changeset/fix-on-result-failed-rows.md b/.changeset/fix-on-result-failed-rows.md new file mode 100644 index 0000000..3562b7a --- /dev/null +++ b/.changeset/fix-on-result-failed-rows.md @@ -0,0 +1,5 @@ +--- +"@loveholidays/eval-kit": patch +--- + +Fix onResult callback not being called for failed rows in BatchEvaluator. Previously, errors were silently dropped and consumers relying on onResult for logging or persistence never received failure notifications. diff --git a/src/batch/batch-evaluator.ts b/src/batch/batch-evaluator.ts index d71b210..db92ffd 100644 --- a/src/batch/batch-evaluator.ts +++ b/src/batch/batch-evaluator.ts @@ -339,7 +339,7 @@ export class BatchEvaluator { } const durationMs = Date.now() - ctx.startTime; - this.results.push({ + const result: BatchEvaluationResult = { rowId: ctx.rowId, rowIndex: ctx.index, input: ctx.row, @@ -348,8 +348,9 @@ export class BatchEvaluator { durationMs, retryCount: ctx.retryCount, error: errorMessage, - }); + }; + await this.emitResult(result); this.processedRowIndices.add(ctx.index); this.progressTracker?.recordFailure(durationMs); @@ -369,6 +370,14 @@ export class BatchEvaluator { : baseDelay; } + private async emitResult(result: BatchEvaluationResult): Promise { + const callbackResult = this.config.onResult?.(result); + if (callbackResult instanceof Promise) { + await callbackResult; + } + this.results.push(result); + } + private async executeRowEvaluation(ctx: { inputData: BatchInputRow; index: number; @@ -393,14 +402,7 @@ export class BatchEvaluator { retryCount: ctx.retryCount, }; - if (this.config.onResult) { - const callbackResult = this.config.onResult(result); - if (callbackResult instanceof Promise) { - await callbackResult; - } - } - - this.results.push(result); + await this.emitResult(result); this.processedRowIndices.add(ctx.index); this.progressTracker?.recordSuccess(durationMs, tokensUsed); }