File tree Expand file tree Collapse file tree
packages/codeflash/runtime Expand file tree Collapse file tree Original file line number Diff line number Diff 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 */
122129function 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/**
You can’t perform that action at this time.
0 commit comments