Skip to content

Conversation

@hassoncs
Copy link
Contributor

@hassoncs hassoncs commented Aug 4, 2025

The rootTask and parentTask properties in the Task class were incorrectly initialized, preventing sub-tasks from properly reporting their results back to the main Orchestrator task. This commit fixes the initialization to ensure correct task hierarchy and result propagation.

The issue is with how TypeScript handles readonly properties when they have explicit initializers. Let me demonstrate:

readonly rootTask: Task | undefined
readonly parentTask: Task | undefined
readonly rootTask: Task | undefined = undefined
readonly parentTask: Task | undefined = undefined

When you declare a readonly property with an explicit initializer like = undefined, TypeScript treats this as a definitive assignment that happens at the class field level, before the constructor runs.

Here's what happens:

  1. Class is instantiated

  2. Constructor runs

  3. this.parentTask = parentTask successfully assigns the parent task

  4. Property now contains the actual parent task reference

  5. Class is instantiated

  6. TypeScript immediately sets this.parentTask = undefined due to the field initializer

  7. Constructor runs

  8. this.parentTask = parentTask tries to assign, but TypeScript may optimize this away or the field initializer takes precedence

  9. Property remains undefined even though we tried to assign it

Gif of the working fix:
2025-08-04 15 08 21

Fixes: Kilo-Org/kilocode#1742


Important

Fixes incorrect initialization of rootTask and parentTask in Task class to ensure proper sub-task result reporting in Orchestrator mode.

  • Behavior:
    • Fixes incorrect initialization of rootTask and parentTask in Task class in Task.ts, ensuring sub-tasks report results correctly in Orchestrator mode.
  • Technical Details:
    • Removes explicit initializers for readonly rootTask and readonly parentTask properties to prevent TypeScript from overriding constructor assignments.

This description was created by Ellipsis for 42bd8b9. You can customize this summary. It will automatically update as commits are pushed.

The `rootTask` and `parentTask` properties in the `Task` class were
incorrectly initialized, preventing sub-tasks from properly reporting
their results back to the main Orchestrator task. This commit fixes
the initialization to ensure correct task hierarchy and result propagation.

The issue is with how TypeScript handles `readonly` properties when they have explicit initializers. Let me demonstrate:

```typescript
readonly rootTask: Task | undefined
readonly parentTask: Task | undefined
```

```typescript
readonly rootTask: Task | undefined = undefined
readonly parentTask: Task | undefined = undefined
```

When you declare a `readonly` property with an explicit initializer like `= undefined`, TypeScript treats this as a **definitive assignment** that happens at the class field level, **before** the constructor runs.

Here's what happens:

1. Class is instantiated
2. Constructor runs
3. `this.parentTask = parentTask` successfully assigns the parent task
4. Property now contains the actual parent task reference

1. Class is instantiated
2. **TypeScript immediately sets `this.parentTask = undefined` due to the field initializer**
3. Constructor runs
4. `this.parentTask = parentTask` tries to assign, but TypeScript may optimize this away or the field initializer takes precedence
5. Property remains `undefined` even though we tried to assign it

Fixes RooCodeInc#1742
@hassoncs hassoncs requested review from cte, jr and mrubens as code owners August 4, 2025 13:25
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 4, 2025
@hassoncs hassoncs changed the title fix: Correctly report sub-task results in Orchestrator mode fix: Cannot report sub-task results in Orchestrator mode Aug 4, 2025
@dosubot dosubot bot added the bug Something isn't working label Aug 4, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! I've reviewed the changes and the fix correctly addresses the TypeScript initialization issue. The PR description provides excellent context explaining the problem and solution.

Suggestions:

  1. Add unit tests: Consider adding tests for the rootTask and parentTask functionality to prevent regression of this bug. Currently, there are no tests covering these properties, and having tests would ensure sub-task result reporting continues to work correctly in Orchestrator mode.

  2. Documentation: Consider updating any relevant documentation about the Orchestrator mode to ensure it reflects that sub-task result reporting is now working correctly.


readonly rootTask: Task | undefined = undefined
readonly parentTask: Task | undefined = undefined
readonly rootTask: Task | undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Good fix! This correctly addresses the TypeScript initialization issue. However, consider adding a brief comment explaining why these properties don't have explicit initializers, as this subtle behavior might not be obvious to all developers:

Suggested change
readonly rootTask: Task | undefined
// Note: No explicit initializers to allow constructor assignment
readonly rootTask: Task | undefined
readonly parentTask: Task | undefined

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 4, 2025
@daniel-lxs
Copy link
Member

Hey @hassoncs I'm not entirely sure what problem is being solved here, I tested both main and production and the subtask result seems to be visible to the parent task, am I missing something?

@daniel-lxs daniel-lxs moved this from Triage to PR [Changes Requested] in Roo Code Roadmap Aug 4, 2025
@hannesrudolph hannesrudolph added PR - Changes Requested and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 4, 2025
@hassoncs
Copy link
Contributor Author

hassoncs commented Aug 4, 2025

Hmm, the bug we were seeing is that Orchestrator dispatches a sub-task, but that sub-task is unable to report completion to the parent. When I debugged it, the problem was the readonly on the rootTask made it so it couldn't be reassigned. But just now, I tried to reproduce the original bug and I can't seem to!

Maybe this was only a bug on our side?? I'll do some more testing and close this if I can't reproduce it! Sorry for the confusion

@hassoncs
Copy link
Contributor Author

hassoncs commented Aug 4, 2025

@daniel-lxs, yeah I can't seem to reproduce it!! I assumed the bug would be the same 😬

Closing this! Sorry 😅

@hassoncs hassoncs closed this Aug 4, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Aug 4, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 4, 2025
@daniel-lxs
Copy link
Member

@hassoncs No problem, thank you for taking the time to fix a potential issue!

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

Labels

bug Something isn't working PR - Changes Requested size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Orchestrator sub-tasks do not properly report their results to the parent

3 participants