Skip to content

Commit 8884baf

Browse files
Copilotpardeike
andauthored
Fix infinite loop in PlanChunking tool chunking logic (#35)
* Initial plan * Fix hanging test in PlanChunking tool (TODO-003) Co-authored-by: pardeike <853584+pardeike@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pardeike <853584+pardeike@users.noreply.github.com>
1 parent 253e6f5 commit 8884baf

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

TODO.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,18 @@ This document contains comprehensive TODOs and recommendations based on a detail
3131
- More concise syntax
3232
- Aligns with original design intent
3333

34-
### TODO-003: Fix Hanging Test in PlanChunking Tool
34+
### TODO-003: Fix Hanging Test in PlanChunking Tool ✅ COMPLETED
3535
**Priority**: High | **Complexity**: Medium
36-
**Context**: The test `PlanChunking_WithValidMember_ReturnsChunkPlan` in `ToolImplementationTests.cs` hangs indefinitely and never completes, causing CI/testing issues.
37-
38-
**Root Cause Analysis**:
39-
- Test calls `PlanChunkingTool.PlanChunking()` which internally calls `DecompilerService.DecompileMember()` and `GetSourceSlice()`
40-
- Issue likely in decompilation process rather than chunking logic itself
41-
- DecompilerService decompiles entire containing type for methods/fields/properties (lines 153, 158, 163, 168 in DecompilerService.cs)
42-
- Potential infinite loop or very slow decompilation when processing test assembly members
43-
- Test times out after 10+ seconds, indicating genuine hang rather than slow operation
44-
45-
**Investigation Needed**:
46-
- Add timeout protection to decompilation calls in PlanChunking tool
47-
- Identify which specific member ID causes the hang (test finds first non-constructor method)
48-
- Consider caching issues or circular reference in decompiler
49-
- May need fallback mechanism or early termination for problematic members
50-
51-
**Immediate Fix**: Add timeout wrapper around decompilation calls in PlanChunking tool to prevent infinite hangs.
36+
**Context**: The test `PlanChunking_WithValidMember_ReturnsChunkPlan` in `ToolImplementationTests.cs` was hanging indefinitely due to an infinite loop in the chunking logic.
37+
38+
**Root Cause**: The infinite loop prevention logic in PlanChunking tool was flawed. When `currentStart = currentEnd + 1 - overlap`, if the overlap was large enough, `currentStart` would not advance, causing an infinite loop.
39+
40+
**Fix Applied**:
41+
- Simplified and fixed the infinite loop prevention logic to ensure `currentStart` always advances
42+
- Changed the logic to `if (nextStart <= currentStart) { nextStart = currentStart + 1; }`
43+
- Test now passes reliably in ~1 second instead of hanging indefinitely
44+
45+
**Status**: ✅ COMPLETED - Fix verified, all tests passing
5246

5347
### TODO-004: Standardize Pagination Across All Tools
5448
**Priority**: High | **Complexity**: Low

Tools/PlanChunking.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ public static string PlanChunking(string memberId, int targetChunkSize = 6000, i
9696
(currentEnd - currentStart + 1) * avgCharsPerLine));
9797

9898
// Move to next chunk with overlap consideration
99-
currentStart = currentEnd + 1 - overlap;
99+
var nextStart = currentEnd + 1 - overlap;
100100

101-
// Prevent infinite loop if overlap is too large
102-
if (currentStart <= currentEnd - targetLinesPerChunk + overlap)
101+
// Prevent infinite loop by ensuring we always advance
102+
if (nextStart <= currentStart)
103103
{
104-
currentStart = currentEnd + 1;
104+
nextStart = currentStart + 1;
105105
}
106+
107+
currentStart = nextStart;
106108
}
107109

108110
result = new ChunkPlanResult(

0 commit comments

Comments
 (0)