AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-234
  5. plan
  6. context.json
context.json(3.9 KB)· Apr 2, 2026
{
  "meta": {
    "agent": "planner",
    "task_id": "234",
    "title": "fix: replan/restart must invalidate cached plan and PR association",
    "created_at": "2026-04-02T12:00:00Z"
  },
  "inputs": [
    {
      "name": "issue-234",
      "type": "context",
      "ref": "https://github.com/AgentSDE/agent-core/issues/234",
      "notes": "Replan/restart reuses stale plan + PR"
    },
    {
      "name": "task.entity.ts",
      "type": "file",
      "ref": "src/database/entities/task.entity.ts",
      "notes": "Missing replanAttempt field"
    },
    {
      "name": "task-state.service.ts",
      "type": "file",
      "ref": "src/task-state/task-state.service.ts",
      "notes": "Has resetForRestart but no resetForReplan"
    },
    {
      "name": "directive.service.ts",
      "type": "file",
      "ref": "src/directive/directive.service.ts",
      "notes": "Replan clears PR inline; restart does not clear PR at all"
    },
    {
      "name": "artefacts.service.ts",
      "type": "file",
      "ref": "src/artefacts/artefacts.service.ts",
      "notes": "No plan artefact cleanup method"
    }
  ],
  "outputs": [
    {
      "name": "plan.md",
      "type": "plan",
      "format": "md",
      "content": "Implementation plan for replan/restart invalidation"
    }
  ],
  "files": [
    {
      "path": "src/database/entities/task.entity.ts",
      "action": "modify",
      "reason": "Add replanAttempt column"
    },
    {
      "path": "src/task-state/task-state.service.ts",
      "action": "modify",
      "reason": "Add resetForReplan() method"
    },
    {
      "path": "src/directive/directive.service.ts",
      "action": "modify",
      "reason": "Use resetForReplan, add PR supersede comment, clear PR on restart, add replan_attempt telemetry"
    },
    {
      "path": "src/artefacts/artefacts.service.ts",
      "action": "modify",
      "reason": "Add clearPlanArtefacts() method"
    },
    {
      "path": "src/task-state/task-state.service.spec.ts",
      "action": "modify",
      "reason": "Test resetForReplan"
    },
    {
      "path": "src/directive/directive.service.spec.ts",
      "action": "modify",
      "reason": "Test replan/restart invalidation"
    }
  ],
  "steps": [
    {
      "id": "S1",
      "summary": "Add replanAttempt column to TaskEntity and resetForReplan() to TaskStateService",
      "acceptance": [
        "TaskEntity has replanAttempt integer column with default 0",
        "resetForReplan() resets all phases, nullifies prNumber/prBranch, increments replanAttempt",
        "Unit tests cover resetForReplan happy path and idempotent re-entry"
      ],
      "depends_on": []
    },
    {
      "id": "S2",
      "summary": "Add clearPlanArtefacts() to ArtefactsService and update DirectiveService replan handler",
      "acceptance": [
        "clearPlanArtefacts removes plan.md, context.json, prd.json from task plan directory",
        "Replan handler uses resetForReplan(), calls clearPlanArtefacts(), records replan_attempt event",
        "Open PR gets superseded comment before closing",
        "Closed/merged PR is left untouched",
        "No-op when no prior artefacts exist"
      ],
      "depends_on": [
        "S1"
      ]
    },
    {
      "id": "S3",
      "summary": "Update restart handler to clear PR state and add comprehensive tests",
      "acceptance": [
        "Restart directive clears prNumber and prBranch",
        "Restart closes open PR with superseded comment if exists",
        "Unit tests cover: restart clears PR, replan increments counter, no-op with no prior state",
        "npm run test and npm run lint pass"
      ],
      "depends_on": [
        "S1"
      ]
    }
  ],
  "risks": [
    {
      "risk": "SQLite column addition may need explicit migration if not using synchronize",
      "mitigation": "TypeORM synchronize handles it; verify in CI"
    },
    {
      "risk": "Restart PR cleanup changes existing behavior",
      "mitigation": "Issue explicitly requires it; document in PR"
    }
  ],
  "assumptions": [
    "TypeORM synchronize mode handles new column addition without manual migration",
    "ArtefactsService has access to task directory paths or can receive them as parameters",
    "GitHubService.closePR handles already-closed PRs gracefully (no error)"
  ],
  "open_questions": []
}
Plan