Skip to content

Commit df28536

Browse files
committed
fix looper
1 parent e8989c2 commit df28536

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

packages/codeflash/runtime/capture.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,21 @@ function getInvocationLoopIndex(invocationKey) {
117117
}
118118

119119
/**
120-
* Increment the batch counter. Called by loop-runner between test file runs.
120+
* Increment the batch counter and reset per-invocation loop counts.
121+
* Called by loop-runner between test file runs.
122+
*
123+
* IMPORTANT: We must reset invocationLoopCounts here because the globalIndex
124+
* formula (currentBatch - 1) * PERF_BATCH_SIZE + localIndex assumes localIndex
125+
* starts at 1 for each batch. Without this reset, localIndex would continue
126+
* incrementing across batches, causing globalIndex to grow too fast and
127+
* triggering early loop termination.
121128
*/
122129
function incrementBatch() {
123130
sharedPerfState.currentBatch++;
131+
// Reset per-invocation loop counts for the new batch
132+
// This ensures localIndex starts at 1 for each batch, making the
133+
// globalIndex calculation correct: (batch-1)*batchSize + localIndex
134+
sharedPerfState.invocationLoopCounts = {};
124135
}
125136

126137
/**

0 commit comments

Comments
 (0)