# MR-to-Issue Closure Gap - **Command:** `lore closure-gaps` - **Confidence:** 88% - **Tier:** 2 - **Status:** proposed - **Effort:** low — single join query ## What Find entity_references where reference_type='closes' AND the target issue is still open AND the source MR is merged. These represent broken auto-close links where a merge should have closed an issue but didn't. ## Why Simple, definitive, actionable. If a merged MR says "closes #42" but #42 is still open, something is wrong. Either auto-close failed (wrong target branch), the reference was incorrect, or the issue needs manual attention. ## Data Required All exists today: - `entity_references` (reference_type='closes') - `merge_requests` (state='merged') - `issues` (state='opened') ## Implementation Sketch ```sql SELECT mr.iid as mr_iid, mr.title as mr_title, mr.merged_at, mr.target_branch, i.iid as issue_iid, i.title as issue_title, i.state as issue_state, p.path_with_namespace FROM entity_references er JOIN merge_requests mr ON er.source_entity_type = 'merge_request' AND er.source_entity_id = mr.id JOIN issues i ON er.target_entity_type = 'issue' AND er.target_entity_id = i.id JOIN projects p ON er.project_id = p.id WHERE er.reference_type = 'closes' AND mr.state = 'merged' AND i.state = 'opened'; ``` ## Human Output ``` Closure Gaps — merged MRs that didn't close their referenced issues group/backend !234 merged 3d ago → #42 still OPEN "Refactor auth middleware" should have closed "Login timeout bug" Target branch: develop (default: main) — possible branch mismatch group/frontend !45 merged 1w ago → #38 still OPEN "Update dashboard" should have closed "Dashboard layout broken" ``` ## Downsides - Could be intentional (MR merged to wrong branch, issue tracked across branches) - Cross-project references may not be resolvable if target project not synced - GitLab auto-close only works when merging to default branch ## Extensions - Flag likely cause: branch mismatch (target_branch != project.default_branch) - `lore closure-gaps --auto-close` — actually close the issues via API (dangerous, needs confirmation)