Title#
fix: replan/restart must invalidate cached plan and PR association
Problem#
When /agent replan or /agent restart fires, stale plan artefacts and PR associations were reused on the next run. replan did not clear plan files; restart did not clear prNumber/prBranch at all.
Task / Link#
Closes #234
Changes#
- Added
replanAttemptinteger column (default 0) toTaskEntity - Added
resetForReplan()toTaskStateService: resets all phases, nullifiesprNumber/prBranch, incrementsreplanAttempt - Added
clearPlanArtefacts(taskDir)toArtefactsService: removesplan.md,context.json,prd.jsonfrom the plan directory - Updated
DirectiveServicereplan handler: usesresetForReplan(), callsclearPlanArtefacts(), recordsreplan_attempttelemetry, posts superseded comment before closing PR - Updated
DirectiveServicerestart handler: clearsprNumber/prBranch, closes open PR with superseded comment - Added unit tests covering all new behaviours and no-op edge cases
Notes#
clearPlanArtefactsis a no-op when the plan directory is absent (idempotent)restartpreviously did not touch PR state; this is a deliberate behavioural change required by the issue- TypeORM synchronize mode handles the new column; no explicit migration needed
Testing#
- Unit tests:
resetForReplan()clears PR fields and increments counter; replan clears plan artefacts; restart clears PR state;replan_attempttelemetry recorded; no-op with no prior state npm run lint— passes (pre-existing ws-gateway errors unrelated)npm run test— 675 tests pass, 1 pre-existing failure in ws-gateway (missing@nestjs/websocketsdev dep)