AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-234
  5. plan
  6. plan.md
plan.md(2.9 KB)· Apr 2, 2026· 2 min read
  • Summary
  • Files
  • Steps
  • Verification
  • Risks

Plan: Replan/Restart Must Invalidate Cached Plan and PR Association#

Summary#

When /agent replan or /agent restart fires, cached plan artefacts and PR associations must be invalidated so the next run generates a fresh plan and opens a new PR. Currently, replan clears prNumber/prBranch but does not clear plan artefacts or track attempt count; restart does not clear PR state at all.

Files#

FileActionDescription
src/database/entities/task.entity.tsmodifyAdd replanAttempt column (integer, default 0)
src/task-state/task-state.service.tsmodifyAdd resetForReplan() method that clears PR state, increments replanAttempt, and resets phases
src/directive/directive.service.tsmodifyUse resetForReplan() for replan; clear PR state for restart; add replan_attempt telemetry; close open PR with superseded message
src/artefacts/artefacts.service.tsmodifyAdd clearPlanArtefacts(taskDir) to remove plan/*.md/json files on replan
src/task-state/task-state.service.spec.tsmodifyAdd unit tests for resetForReplan()
src/directive/directive.service.spec.tsmodifyAdd tests: replan invalidates plan cache, replan forces new PR branch, restart clears PR state

Steps#

  1. Add replanAttempt to TaskEntity — new nullable integer column with default 0, snake_case replan_attempt.
  2. Add resetForReplan() to TaskStateService — calls resetForRestart(), then nullifies prNumber/prBranch, increments replanAttempt.
  3. Add clearPlanArtefacts() to ArtefactsService — removes files in {taskDir}/plan/ directory (plan.md, context.json, prd.json).
  4. Update DirectiveService replan handler — use resetForReplan() instead of manual field clearing; call clearPlanArtefacts(); record replan_attempt event with attempt number; post superseded comment on open PR before closing.
  5. Update DirectiveService restart handler — clear prNumber/prBranch (currently missing); post superseded comment on open PR if exists.
  6. Add unit tests — cover: resetForReplan() clears PR + increments counter; replan clears plan artefacts; restart clears PR state; no-op when no prior artefacts; replan_attempt telemetry recorded.

Verification#

  • npm run test passes with new unit tests covering replan invalidation, restart PR clearing, and idempotent no-op cases.
  • npm run lint passes with zero warnings.
  • Manually verify: after replan, task.prNumber === null, task.prBranch === null, task.replanAttempt incremented, plan directory cleared.

Risks#

  • SQLite migration: Adding replanAttempt column with DEFAULT 0 is safe for TypeORM synchronize mode, but if the project uses explicit migrations, a migration file may be needed.
  • Restart scope expansion: Adding PR cleanup to restart changes existing behavior — the issue explicitly requires it, but it's a behavioral change to flag in the PR.
ContextPrd