From 79a1f36a11451770b19c63543c896af8de53f9eb Mon Sep 17 00:00:00 2001 From: yltw27 Date: Thu, 12 Mar 2026 11:15:24 +0000 Subject: [PATCH 1/2] fix: call onResult callback for failed rows in BatchEvaluator The onResult callback was only invoked on the success path (executeRowEvaluation), silently skipping failed rows. This meant consumers relying on onResult for logging/persistence never saw errors. Extract shared emitResult helper used by both success and error paths, which also eliminates callback logic duplication and reduces handleRowError cyclomatic complexity. Co-Authored-By: Claude Opus 4.6 --- src/batch/batch-evaluator.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) 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); } From e09274a2699966bd3b8de8784cde1f6506f2cf16 Mon Sep 17 00:00:00 2001 From: yltw27 Date: Thu, 12 Mar 2026 12:12:34 +0000 Subject: [PATCH 2/2] chore: add changeset for onResult fix Co-Authored-By: Claude Opus 4.6 --- .changeset/fix-on-result-failed-rows.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-on-result-failed-rows.md 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.