Fix infinite loop in PlanChunking tool chunking logic #35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The test
PlanChunking_WithValidMember_ReturnsChunkPlanwas hanging indefinitely due to a flawed infinite loop prevention mechanism in the PlanChunking tool's chunking algorithm.Root Cause
The chunking logic had a bug where
currentStartwould not advance under certain conditions, causing an infinite loop:With test parameters:
targetChunkSize: 1000, overlap: 1avgCharsPerLine: 16(calculated from sample)totalLines: 52(from test assembly method)targetLinesPerChunk: 62(1000/16)The algorithm would get stuck when:
currentEnd = 52nextStart = 52 + 1 - 1 = 52(no advancement!)while (52 <= 52)remains trueFix
Simplified the logic to ensure
currentStartalways advances:Verification
The fix maintains the intended overlap behavior while preventing the infinite loop that occurred when overlap calculations would prevent proper advancement through the source lines.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.