# Stale Discussion Finder

- **Command:** `lore stale-discussions [--days <N>]`
- **Confidence:** 90%
- **Tier:** 1
- **Status:** proposed
- **Effort:** low — single query, minimal formatting

## What

List unresolved, resolvable discussions where `last_note_at` is older than a
threshold (default 14 days), grouped by parent entity. Prioritize by discussion
count per entity (more stale threads = more urgent).

## Why

Unresolved discussions are silent blockers. They prevent MR merges, stall
decision-making, and represent forgotten conversations. This surfaces them so teams
can take action: resolve, respond, or explicitly mark as won't-fix.

## Data Required

All exists today:
- `discussions` (resolved, resolvable, last_note_at)
- `issues` / `merge_requests` (for parent entity context)

## Implementation Sketch

```sql
SELECT
    d.id,
    d.noteable_type,
    CASE WHEN d.issue_id IS NOT NULL THEN i.iid ELSE mr.iid END as entity_iid,
    CASE WHEN d.issue_id IS NOT NULL THEN i.title ELSE mr.title END as entity_title,
    p.path_with_namespace,
    d.last_note_at,
    ((?1 - d.last_note_at) / 86400000) as days_stale,
    COUNT(*) OVER (PARTITION BY COALESCE(d.issue_id, d.merge_request_id), d.noteable_type) as stale_count_for_entity
FROM discussions d
JOIN projects p ON d.project_id = p.id
LEFT JOIN issues i ON d.issue_id = i.id
LEFT JOIN merge_requests mr ON d.merge_request_id = mr.id
WHERE d.resolved = 0
  AND d.resolvable = 1
  AND d.last_note_at < ?1
ORDER BY days_stale DESC;
```

## Human Output Format

```
Stale Discussions (14+ days without activity)

group/backend !234 — Refactor auth middleware (3 stale threads)
  Discussion #a1b2c3  (28d stale)  "Should we use JWT or session tokens?"
  Discussion #d4e5f6  (21d stale)  "Error handling for expired tokens"
  Discussion #g7h8i9  (14d stale)  "Performance implications of per-request validation"

group/backend #90 — Rate limiting design (1 stale thread)
  Discussion #j0k1l2  (18d stale)  "Redis vs in-memory rate counter"
```

## Robot Mode Output

```json
{
  "ok": true,
  "data": {
    "threshold_days": 14,
    "total_stale": 4,
    "entities": [
      {
        "type": "merge_request",
        "iid": 234,
        "title": "Refactor auth middleware",
        "project": "group/backend",
        "stale_discussions": [
          {
            "discussion_id": "a1b2c3",
            "days_stale": 28,
            "first_note_preview": "Should we use JWT or session tokens?"
          }
        ]
      }
    ]
  }
}
```

## Downsides

- Some discussions are intentionally left open (design docs, long-running threads)
- Could produce noise in repos with loose discussion hygiene
- Doesn't distinguish "stale and blocking" from "stale and irrelevant"

## Extensions

- `lore stale-discussions --mr-only` — focus on MR review threads (most actionable)
- `lore stale-discussions --author alice` — "threads I started that went quiet"
- `lore stale-discussions --assignee bob` — "threads on my MRs that need attention"
