diff --git a/src/cli/commands/start.ts b/src/cli/commands/start.ts index b27d162..3e547b7 100644 --- a/src/cli/commands/start.ts +++ b/src/cli/commands/start.ts @@ -104,11 +104,23 @@ export async function claimAndPrintTask(ctx: AgentContext, task: Listed, handoff /* body is optional */ } - const hof = handoffs.find((h) => h.taskId === task.id); + // Pick the LATEST handoff for this task, not the first one created. When a + // task is reopened with a corrective handoff, the newer handoff supersedes + // the older; showing the stale first-created one made agents rebuild against + // an outdated spec — the architect's correction never actually reached them. + // Handoff ids are zero-padded (HOF-0061 > HOF-0056), so a descending string + // sort yields the newest. + const taskHofs = handoffs + .filter((h) => h.taskId === task.id) + .sort((a, b) => String(b.id).localeCompare(String(a.id))); + const hof = taskHofs[0]; if (hof) { try { const hd = ctx.serverUrl ? await remoteClient.getHandoff(ctx.serverUrl, hof.id) : svcGetHandoff(ctx.projectCwd, hof.id); console.log(`\n─ Handoff ${hof.id} ──────────────`); + if (taskHofs.length > 1) { + console.log(`(latest of ${taskHofs.length} handoffs — supersedes ${taskHofs.slice(1).map((h) => h.id).join(', ')})`); + } console.log(hd.handoff.summary); if (hd.body && hd.body.trim()) console.log(hd.body.trim()); } catch {