Three tables have orphaned rows that cause recurring quality gate failures on every /api/quality-gates scan:
- debate_rounds: rows where session_id has no matching debate_sessions row
- agent_performance: rows where analysis_id has no matching analyses row
- knowledge_edges: rows where analysis_id has no matching analyses row
Steps:
1. COUNT orphaned rows in each table (before record)
2. DELETE orphaned rows (use DELETE ... WHERE NOT EXISTS subquery matching api.py:4585-4623)
3. Verify quality gates for these three types show 0 count after cleanup
4. Consider FK constraints or ON DELETE CASCADE to prevent future orphans
Acceptance criteria:
- orphaned_debate_rounds, orphaned_agent_performance, orphaned_knowledge_edges gate counts all = 0 after cleanup
- Before/after row counts logged in spec
Triage source: task:7828a688-1494-4465-a9b3-c128f94879a0
Git Commits (2)
[Verify] Orphaned RI records cleanup verified — already resolved [task:f61e6b0d-141c-4417-940a-c539cb33a5ac]2026-04-21
[Senate] Clean up orphaned RI records; add FK constraints [task:f61e6b0d-141c-4417-940a-c539cb33a5ac]2026-04-21