Task non recusive calls#1821
Conversation
|
There was a problem hiding this comment.
Pull Request Overview
Refactors the recursive recursivelyMakeClineRequests method to use an iterative stack-based approach to prevent potential stack overflow issues in deep conversation loops.
- Introduces a new
makeRequestmethod that implements the same logic as the recursive version using an explicit stack - Replaces the recursive call with the new non-recursive implementation
- Uses a state machine approach with stack frames to manage the request flow
| this.isStreaming = true | ||
|
|
||
| try { | ||
| // kilocode change: use manual iterator instead of for ... of |
There was a problem hiding this comment.
The comment contains a grammatical error. It should be 'use manual iterator instead of for...of' (with proper spacing around the ellipsis).
| // kilocode change: use manual iterator instead of for ... of | |
| // kilocode change: use manual iterator instead of for...of |
| } | ||
|
|
||
| // Instead of recursive call, push new frame to stack | ||
| stack.push({ |
There was a problem hiding this comment.
[nitpick] The stack-based approach continues the loop with continue after pushing a new frame, but the comment suggests this replaces a recursive call. Consider adding a comment explaining why continue is used here instead of a more explicit control flow to make the intent clearer.
|
|
||
| while (stack.length > 0) { | ||
| const frame = stack[stack.length - 1] | ||
|
|
There was a problem hiding this comment.
The stack-based approach processes frames sequentially but could potentially build up a large stack for deeply nested conversations. Consider adding a maximum stack depth check to prevent excessive memory usage.
| // Before pushing a new frame, check stack depth | |
| const pushFrame = (newFrame: StackFrame) => { | |
| if (stack.length >= MAX_STACK_DEPTH) { | |
| throw new Error(`[KiloCode#request] Maximum stack depth (${MAX_STACK_DEPTH}) exceeded in task ${this.taskId}.${this.instanceId}. Possible infinite or excessively deep conversation nesting.`); | |
| } | |
| stack.push(newFrame); | |
| }; |
Co-authored-by: opencode <noreply@opencode.ai> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Dax <mail@thdxr.com>
Context
Refactors the recursive recursivelyMakeClineRequests method to use an iterative stack-based approach to prevent potential stack overflow issues in deep conversation loops.
Implementation