# Feature: Prior Fix Detection (Phase 1 Step 0)

Before any analysis, check if this issue was already fixed by someone else.

## Check order

1. **Git commit search**  -  look for commits referencing this issue ID across all branches:

   ```bash
   git -C $PROJECT_ROOT log --all --oneline --grep="{jiraId}" --since="8 weeks ago"
   ```

2. **Affected file history**  -  after identifying key files (from issue description keywords), check recent changes:

   ```bash
   git -C $PROJECT_ROOT log --oneline --since="4 weeks ago" -- {affected_file_paths}
   ```

3. **Jira comments/status**  -  fetch latest comments to see if someone reported a fix:

   ```bash
   curl -s -H "Authorization: Bearer $JIRA_TOKEN" \
     "$JIRA_BASE/issue/{jiraId}?fields=status,comment&expand=changelog" \
     | jq '.fields.status.name, .fields.comment.comments[-3:][]?.body'
   ```

## If prior fix commit(s) found

```
This issue appears to already have been addressed:
  {hash}  -  {message} (by {author}, {date})

Options:
  1. Verify fix (check if cherry-pick/merge to base branch is needed)
  2. Stop pipeline (already resolved)
  3. Continue anyway (different fix needed)
```

- Option 1 → Check if the commit exists on `baseBranch`. If not, suggest cherry-pick. Pipeline pauses.
- Option 2 → Cleanup and exit:
  1. Checkout back to base branch: `git -C $PROJECT_ROOT checkout {baseBranch}`
  2. Delete the created branch: `git -C $PROJECT_ROOT branch -D {branch}`
  3. If worktree was used: `git -C $PROJECT_ROOT worktree remove {worktreePath} --force`
  4. Set `agent-state.json` status to `"stopped_already_fixed"`. Log and exit.
- Option 3 → Continue to Step 1 as normal.

## If no prior fix found

Continue to Step 1 (Knowledge Injection).
