Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 15, 2025

Summary

This PR fixes issue #7131 where the Orchestrator mode incorrectly assumes that subsequent calls to the same mode (particularly Architect mode) retain context from previous calls. Each new task was starting with a clean slate, causing confusion when the Orchestrator tried to reference previous work.

Problem

When the Orchestrator mode calls the Architect mode multiple times:

  1. First call: "Create a system design"
  2. Second call: "Add authentication to the design" (assumes Architect remembers the first design)

The second call would fail because the Architect had no memory of the previous task.

Solution

Implemented context preservation by:

  1. Added subtaskContextByMode Map to the Task class to track completion results by mode
  2. Enhanced message in newTaskTool to include context from previous subtasks of the same mode
  3. Updated resumePausedTask to store subtask results for future reference
  4. Limited context history to the last 3 subtasks per mode to avoid overwhelming the model

Changes

  • Modified src/core/tools/newTaskTool.ts to prepend context from previous same-mode subtasks
  • Updated src/core/task/Task.ts to track and store subtask context
  • Added comprehensive tests in src/core/tools/__tests__/newTaskTool.spec.ts

Testing

  • ✅ All existing tests pass
  • ✅ Added 5 new test cases for context preservation
  • ✅ Type checking passes
  • ✅ Linting passes

Example

When Orchestrator calls Architect mode multiple times, the second call now receives:

[Context from previous 🏗️ Architect subtasks]
Previous 🏗️ Architect subtask 1 result: Created initial system design with 3 microservices

[Current task]
Add authentication to the design

Fixes #7131


Important

Fixes context loss in Orchestrator by preserving subtask results across multiple calls to the same mode.

  • Behavior:
    • Fixes context loss in Orchestrator when calling the same mode multiple times by preserving subtask results.
    • Limits context history to last 3 subtasks per mode to prevent overload.
  • Implementation:
    • Adds subtaskContextByMode and currentSubtaskMode to Task class in Task.ts.
    • Updates resumePausedTask() in Task.ts to store subtask results.
    • Modifies newTaskTool() in newTaskTool.ts to prepend context to messages.
  • Testing:
    • Adds tests in newTaskTool.spec.ts for context preservation across multiple mode calls.

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

- Add subtaskContextByMode Map to track completion results by mode
- Enhance new task messages with context from previous subtasks of same mode
- Store subtask results in resumePausedTask for future reference
- Add comprehensive tests for context preservation functionality

Fixes #7131
Copy link
Contributor Author

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

Reviewing my own code because apparently I trust no one, not even myself.

contexts.shift()
}
// Extract a concise summary from the result message
const summary = lastMessage.length > 200 ? lastMessage.substring(0, 200) + "..." : lastMessage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is 200 characters intentional for the context truncation? This seems quite aggressive for complex subtask results. Consider increasing to 500 characters or making it configurable to preserve more meaningful context.

// Store the subtask result as context for future calls to the same mode
if (this.currentSubtaskMode && lastMessage) {
if (!this.subtaskContextByMode) {
this.subtaskContextByMode = new Map()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider adding error handling for Map operations. While unlikely, memory constraints with very large context histories could cause issues. A try-catch block here would make the code more robust.

isPaused: boolean = false
pausedModeSlug: string = defaultModeSlug
private pauseInterval: NodeJS.Timeout | undefined
subtaskContextByMode?: Map<string, string[]>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These new properties would benefit from JSDoc comments explaining their purpose and lifecycle. Consider adding:

)
})

describe("context preservation", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good test coverage! Consider adding edge case tests for:

  • Verifying FIFO behavior when context exceeds 3 items
  • Handling empty or null result messages
  • Behavior with very long context messages that get truncated

These would make the test suite even more robust.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 16, 2025
@daniel-lxs daniel-lxs closed this Aug 18, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 18, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Orchestrator mode: subsequent call to architect mode assumes architect mode still has previous context in memory

4 participants