diff --git a/apps/frontend/src/main/ipc-handlers/task/worktree-handlers.ts b/apps/frontend/src/main/ipc-handlers/task/worktree-handlers.ts index f159983b..f6f1d289 100644 --- a/apps/frontend/src/main/ipc-handlers/task/worktree-handlers.ts +++ b/apps/frontend/src/main/ipc-handlers/task/worktree-handlers.ts @@ -554,23 +554,37 @@ export function registerWorktreeHandlers( } // Persist the status change to implementation_plan.json - const planPath = path.join(specDir, AUTO_BUILD_PATHS.IMPLEMENTATION_PLAN); - try { - if (existsSync(planPath)) { - const { readFileSync, writeFileSync } = require('fs'); - const planContent = readFileSync(planPath, 'utf-8'); - const plan = JSON.parse(planContent); - plan.status = newStatus; - plan.planStatus = planStatus; - plan.updated_at = new Date().toISOString(); - if (staged) { - plan.stagedAt = new Date().toISOString(); - plan.stagedInMainProject = true; + // Issue #243: We must update BOTH the main project's plan AND the worktree's plan (if it exists) + // because ProjectStore prefers the worktree version when deduplicating tasks. + const planPaths = [ + path.join(specDir, AUTO_BUILD_PATHS.IMPLEMENTATION_PLAN), // Main project + path.join(worktreePath, AUTO_BUILD_PATHS.IMPLEMENTATION_PLAN) // Worktree + ]; + + const { readFileSync, writeFileSync } = require('fs'); + + for (const planPath of planPaths) { + try { + if (existsSync(planPath)) { + const planContent = readFileSync(planPath, 'utf-8'); + const plan = JSON.parse(planContent); + plan.status = newStatus; + plan.planStatus = planStatus; + plan.updated_at = new Date().toISOString(); + if (staged) { + plan.stagedAt = new Date().toISOString(); + plan.stagedInMainProject = true; + } + writeFileSync(planPath, JSON.stringify(plan, null, 2)); + } + } catch (persistError) { + // Only log error if main plan fails; worktree plan might legitimately be missing or read-only + if (planPath.includes(specDir)) { + console.error('Failed to persist task status to main plan:', persistError); + } else { + debug('Failed to persist task status to worktree plan (non-critical):', persistError); } - writeFileSync(planPath, JSON.stringify(plan, null, 2)); } - } catch (persistError) { - console.error('Failed to persist task status:', persistError); } const mainWindow = getMainWindow();