fix(agents): prevent backlog groomer from closing PRs as duplicates of their tracking issues #1325

Merged
freemo merged 1 commits from improvement/backlog-groomer-pr-vs-issue-distinction into master 2026-04-03 07:09:24 +00:00
+23 -3
View File
@@ -87,8 +87,13 @@ LOOP FOREVER:
all_prs = query Forgejo for all open and recently closed PRs
# ── Step 2: Run all analysis passes ──────────────────────────
# IMPORTANT: Filter out pull requests before duplicate detection.
# PRs are NOT issues — they deliver code for issues. A PR that
# "Closes #N" is the implementation of #N, NOT a duplicate.
issues_only = [i for i in all_issues if i.pull_request is None]
findings = []
findings += check_duplicates(all_issues)
findings += check_duplicates(issues_only) # Issues only, never PRs
findings += check_orphans(all_issues)
findings += check_stale_issues(all_issues)
findings += check_label_quality(all_issues)
@@ -153,14 +158,25 @@ LOOP FOREVER:
### 1. Duplicate Detection
Compare every pair of open issues for similarity:
Compare every pair of open **issues** for similarity:
- **Title similarity** — issues with very similar titles (>80% word overlap)
- **Description similarity** — issues describing the same work
- **Same branch name** — two issues with the same branch in metadata
**CRITICAL: Pull Requests are NOT duplicates of their linked issues.**
A PR that contains `Closes #N` in its body is the **implementation delivery
vehicle** for issue #N — it is NOT a duplicate. Never close a PR because it
references or implements a tracking issue. Duplicate detection applies ONLY
to issue-vs-issue comparisons, never to PR-vs-issue comparisons.
When scanning for duplicates, **skip all pull requests entirely**. Only
compare issues (items where `pull_request` is null in the Forgejo API
response) against other issues. PRs have a different lifecycle and purpose
than issues — they deliver code, while issues track work.
**Action:** Post a comment on the newer issue noting the potential duplicate.
If confidence is very high (same branch name, near-identical title), close
the newer issue as duplicate.
the newer issue as duplicate. **Never close a pull request as a duplicate.**
### 2. Orphan Detection
@@ -403,6 +419,10 @@ No exceptions — every comment, every issue body, every PR description.
- **Be conservative with closes.** Only close issues when you are CERTAIN
the work is done or it is clearly a duplicate. When in doubt, comment
instead of closing.
- **NEVER close pull requests as duplicates of their tracking issues.**
A PR that says `Closes #N` is the implementation of issue #N, not a
duplicate. PRs and issues serve fundamentally different purposes. Only
apply duplicate detection to issue-vs-issue comparisons.
- **Be helpful, not noisy.** Don't post comments on every issue every cycle.
Only post when you find an actionable problem.
- **Respect human decisions.** If an issue has a comment from a human