Skip to content

Delegated child tasks get no rootTask and taskNumber 1 #2031

Open

Description

@edelauna

Problem

After delegation, the child task has no root-task pointer. Parent and child both have task number 1.

createTask reads the task registry for both values (src/core/webview/ClineProvider.ts, around lines 3426-3428):

rootTask: this.taskRegistry.getAll()[0],
taskNumber: this.taskRegistry.length + 1,

delegateParentAndOpenChildUnlocked removes the parent from the registry during disposal (around line 3907). It calls createTask for the child afterward (around line 3927). The registry is empty at that point. So rootTask is undefined and taskNumber is 1.

Evidence

A server-state audit of a delegation run showed parent links agree and transcripts parse. Both defects appeared as metadata only. The code path was read but not reproduced at runtime. Confirm with a test before fixing.

Effects

  1. Any consumer of rootTask cannot find the root for a child. Deeper hierarchies (child of child) are the risk.
  2. taskNumber is not unique across a hierarchy.

Proposed fix

Derive both values from the parent when parentTask is set. For example:

  1. rootTask: parentTask?.rootTask ?? parentTask ?? this.taskRegistry.getAll()[0]
  2. A taskNumber rule that does not depend on the emptied registry.

Decide the intended taskNumber meaning first. Check whether the ...options spread after these fields can override them.

Tests

  1. Delegate parent to child. Assert child.rootTask is the parent task.
  2. Delegate to a grandchild. Assert rootTask is the original parent and the task numbers are unique.

Related

This may fit the parallelizable tasks work (#355). It is not related to PR #1906.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions