|
| 1 | +# PR Review Summary for #6177: Implement Sticky Task Mode |
| 2 | + |
| 3 | +## Executive Summary |
| 4 | + |
| 5 | +This PR implements a "sticky mode" feature that persists the last used mode when reopening a task from history. While the implementation is functional and follows existing patterns, there are critical issues with test coverage and some minor architectural concerns that should be addressed. |
| 6 | + |
| 7 | +## Critical Issues (must fix) |
| 8 | + |
| 9 | +### 1. **Breaking Change in new_task Tool** |
| 10 | + |
| 11 | +The current implementation has a critical issue with the `new_task` tool that will break with sticky mode: |
| 12 | + |
| 13 | +**Problem:** In [`newTaskTool.ts`](src/core/tools/newTaskTool.ts:84), the mode is switched BEFORE creating the new task: |
| 14 | + |
| 15 | +```typescript |
| 16 | +// Line 84: Switch mode first, then create new task instance. |
| 17 | +await provider.handleModeSwitch(mode) |
| 18 | +``` |
| 19 | + |
| 20 | +With sticky mode, this means: |
| 21 | + |
| 22 | +1. Parent task switches to the new mode |
| 23 | +2. Parent task's mode is saved as the new mode (not its original mode) |
| 24 | +3. When the subtask completes and parent resumes, it will have the wrong mode |
| 25 | + |
| 26 | +**Required Fix:** The mode switch must happen AFTER the new task is created: |
| 27 | + |
| 28 | +```typescript |
| 29 | +// Create new task first (preserving parent's current mode) |
| 30 | +const newCline = await provider.initClineWithTask(unescapedMessage, undefined, cline) |
| 31 | + |
| 32 | +// Then switch the new task to the desired mode |
| 33 | +await provider.handleModeSwitch(mode) |
| 34 | +``` |
| 35 | + |
| 36 | +This ensures the parent task's mode is preserved correctly in its history. |
| 37 | + |
| 38 | +### 2. **Missing Test Coverage for Core Functionality** |
| 39 | + |
| 40 | +The PR lacks specific tests for the new sticky mode feature: |
| 41 | + |
| 42 | +- No tests verify that the mode is correctly saved to `taskMetadata` when switching modes |
| 43 | +- No tests verify that the mode is restored when reopening a task from history |
| 44 | +- The existing test files (`Task.spec.ts` and `ClineProvider.spec.ts`) were not updated to cover the new functionality |
| 45 | + |
| 46 | +**Evidence:** |
| 47 | + |
| 48 | +- Searched for `handleModeSwitch`, `initClineWithHistoryItem`, and `taskMetadata` in test files |
| 49 | +- Found no tests specifically validating the persistence and restoration of mode in task metadata |
| 50 | + |
| 51 | +**Recommendation:** Add comprehensive test coverage: |
| 52 | + |
| 53 | +```typescript |
| 54 | +// In ClineProvider.spec.ts |
| 55 | +it("should save mode to task metadata when switching modes", async () => { |
| 56 | + // Test that handleModeSwitch updates task history with new mode |
| 57 | +}) |
| 58 | + |
| 59 | +it("should restore mode from history item when reopening task", async () => { |
| 60 | + // Test that initClineWithHistoryItem restores the saved mode |
| 61 | +}) |
| 62 | + |
| 63 | +// In Task.spec.ts |
| 64 | +it("should include current mode in task metadata", async () => { |
| 65 | + // Test that saveClineMessages includes mode in metadata |
| 66 | +}) |
| 67 | +``` |
| 68 | + |
| 69 | +## Pattern Inconsistencies |
| 70 | + |
| 71 | +### 1. **Inconsistent Mode Persistence Approach** |
| 72 | + |
| 73 | +The implementation adds mode persistence at the task level, but the codebase already has a pattern for persisting mode-specific API configurations (`modeApiConfigs`). This creates two different approaches for mode-related persistence. |
| 74 | + |
| 75 | +**Current patterns:** |
| 76 | + |
| 77 | +- Mode-specific API configs: `providerSettingsManager.setModeConfig()` |
| 78 | +- Task-specific mode: Added to `HistoryItem` and `taskMetadata` |
| 79 | + |
| 80 | +**Recommendation:** Document why task-level mode persistence is needed in addition to the existing mode configuration system. |
| 81 | + |
| 82 | +## Architecture Concerns |
| 83 | + |
| 84 | +### 1. **Tight Coupling Between Task and Mode** |
| 85 | + |
| 86 | +The implementation creates a direct dependency between tasks and modes by adding the `mode` field to `HistoryItem`. This could make it harder to refactor the mode system in the future. |
| 87 | + |
| 88 | +**Consider:** Using a more flexible approach like storing mode in a separate metadata object that could be extended with other task preferences in the future. |
| 89 | + |
| 90 | +## Minor Suggestions |
| 91 | + |
| 92 | +### 1. **Type Safety Enhancement** |
| 93 | + |
| 94 | +The `mode` field is typed as `string` in both `HistoryItem` and `taskMetadata`. Consider using the `Mode` type for better type safety: |
| 95 | + |
| 96 | +```typescript |
| 97 | +// In packages/types/src/history.ts |
| 98 | +mode: z.enum(['code', 'architect', 'ask', 'debug', ...]).optional() |
| 99 | +``` |
| 100 | + |
| 101 | +### 2. **Documentation** |
| 102 | + |
| 103 | +Add JSDoc comments to explain the purpose of the mode field: |
| 104 | + |
| 105 | +```typescript |
| 106 | +/** |
| 107 | + * The mode that was active when this task was last saved. |
| 108 | + * Used to restore the user's preferred mode when reopening the task. |
| 109 | + */ |
| 110 | +mode?: string |
| 111 | +``` |
| 112 | + |
| 113 | +## Test Coverage Issues |
| 114 | + |
| 115 | +The PR claims "All existing tests pass" but provides no new tests for the feature. This is concerning for a feature that modifies core task persistence behavior. |
| 116 | + |
| 117 | +**Required tests:** |
| 118 | + |
| 119 | +1. Mode is saved when task history is updated |
| 120 | +2. Mode is restored when task is reopened |
| 121 | +3. Mode persistence works correctly with subtasks |
| 122 | +4. Null/undefined mode is handled gracefully |
| 123 | + |
| 124 | +## Summary |
| 125 | + |
| 126 | +This PR has two critical issues that must be addressed: |
| 127 | + |
| 128 | +1. **The new_task tool implementation is incompatible with sticky mode** - The mode switch happens before task creation, which will cause the parent task to save the wrong mode. This is a breaking change that will affect subtask functionality. |
| 129 | + |
| 130 | +2. **Complete lack of test coverage** - The feature modifies important task persistence behavior without any tests to ensure it works correctly or to prevent regressions. |
| 131 | + |
| 132 | +**Verdict:** Request changes - Fix the new_task tool implementation and add comprehensive test coverage before merging. |
| 133 | + |
| 134 | +## Additional Implementation Notes |
| 135 | + |
| 136 | +The fix for the new_task tool should: |
| 137 | + |
| 138 | +1. Create the new task first (which will preserve the parent's current mode in its history) |
| 139 | +2. Then switch the newly created task to the desired mode |
| 140 | +3. This ensures parent tasks maintain their original mode when resuming after subtasks complete |
0 commit comments