Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-on-result-failed-rows.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 12 additions & 10 deletions src/batch/batch-evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand All @@ -369,6 +370,14 @@ export class BatchEvaluator {
: baseDelay;
}

private async emitResult(result: BatchEvaluationResult): Promise<void> {
const callbackResult = this.config.onResult?.(result);
if (callbackResult instanceof Promise) {
await callbackResult;
}
this.results.push(result);
}

private async executeRowEvaluation(ctx: {
inputData: BatchInputRow;
index: number;
Expand All @@ -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);
}
Expand Down
Loading