Skip to content

Task non recusive calls#1821

Closed
catrielmuller wants to merge 2 commits into
mainfrom
catrielmuller/task-non-recursive
Closed

Task non recusive calls#1821
catrielmuller wants to merge 2 commits into
mainfrom
catrielmuller/task-non-recursive

Conversation

@catrielmuller

@catrielmuller catrielmuller commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

Context

Refactors the recursive recursivelyMakeClineRequests method to use an iterative stack-based approach to prevent potential stack overflow issues in deep conversation loops.

Implementation

  • Introduces a new makeRequest method 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

@catrielmuller
catrielmuller requested a review from Copilot August 7, 2025 12:32
@changeset-bot

changeset-bot Bot commented Aug 7, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b39fc0d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 makeRequest method 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

Comment thread src/core/task/Task.ts Outdated
this.isStreaming = true

try {
// kilocode change: use manual iterator instead of for ... of

Copilot AI Aug 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment contains a grammatical error. It should be 'use manual iterator instead of for...of' (with proper spacing around the ellipsis).

Suggested change
// kilocode change: use manual iterator instead of for ... of
// kilocode change: use manual iterator instead of for...of

Copilot uses AI. Check for mistakes.
Comment thread src/core/task/Task.ts Outdated
}

// Instead of recursive call, push new frame to stack
stack.push({

Copilot AI Aug 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copilot uses AI. Check for mistakes.
Comment thread src/core/task/Task.ts Outdated

while (stack.length > 0) {
const frame = stack[stack.length - 1]

Copilot AI Aug 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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);
};

Copilot uses AI. Check for mistakes.
@EamonNerbonne
EamonNerbonne deleted the catrielmuller/task-non-recursive branch November 3, 2025 13:23
slamj1 pushed a commit to slamj1/kilocode that referenced this pull request May 16, 2026
Co-authored-by: opencode <noreply@opencode.ai>
Co-authored-by: Dax Raad <d@ironbay.co>
Co-authored-by: Dax <mail@thdxr.com>
jliounis pushed a commit to jliounis/kilocode that referenced this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants