Summary
deleteSlice() in src/resources/extensions/gsd/gsd-db.ts (line ~2150 at 33c00aaff) manually cascades verification_evidence → tasks → slice_dependencies (both directions) → slices, but does not delete quality_gates rows — and quality_gates carries a true foreign key to slices:
-- db-base-schema.ts:275
FOREIGN KEY (milestone_id, slice_id) REFERENCES slices(milestone_id, id)
Deleting any slice that has quality_gates rows fails with FOREIGN KEY constraint failed (with FK enforcement on), or silently leaves orphan gate rows.
Four more tables reference the deleted slice by (milestone_id, slice_id) without an FK→slices — gate_runs, replan_history, assessments, artifacts — and are left as orphan rows. deleteMilestone already does equivalent orphan cleanup for its scope, so deleteSlice is inconsistent with the established pattern.
Reproduction
- Create a milestone + slice; let a gate definition write a
quality_gates row for the slice.
- Call
deleteSlice(milestoneId, sliceId).
- Observe
FOREIGN KEY constraint failed (FKs on) or orphaned quality_gates rows (FKs off).
Schema audit (why exactly these five tables)
| Table |
FK→slices? |
Handled by deleteSlice today? |
| tasks |
YES |
yes |
| slice_dependencies |
YES (both directions) |
yes |
| quality_gates |
YES (db-base-schema.ts:275) |
no — the actual FK bug |
| gate_runs |
no |
no — orphan rows |
| replan_history |
no (FK→milestones) |
no — orphan rows |
| assessments |
no (FK→milestones) |
no — orphan rows |
| artifacts |
no |
no — orphan rows |
Proposed fix
Add five manual DELETEs to the existing cascade (matching the current manual-DELETE style, no schema migration): quality_gates before tasks, then gate_runs / replan_history / assessments / artifacts orphan cleanup, then the existing flow. I have this working locally with a regression test and will submit a PR referencing this issue.
Prior art: #5698 / #5787 (both closed) touched adjacent lifecycle areas but not this FK gap.
Summary
deleteSlice()insrc/resources/extensions/gsd/gsd-db.ts(line ~2150 at33c00aaff) manually cascadesverification_evidence→tasks→slice_dependencies(both directions) →slices, but does not deletequality_gatesrows — andquality_gatescarries a true foreign key to slices:Deleting any slice that has
quality_gatesrows fails withFOREIGN KEY constraint failed(with FK enforcement on), or silently leaves orphan gate rows.Four more tables reference the deleted slice by
(milestone_id, slice_id)without an FK→slices —gate_runs,replan_history,assessments,artifacts— and are left as orphan rows.deleteMilestonealready does equivalent orphan cleanup for its scope, sodeleteSliceis inconsistent with the established pattern.Reproduction
quality_gatesrow for the slice.deleteSlice(milestoneId, sliceId).FOREIGN KEY constraint failed(FKs on) or orphanedquality_gatesrows (FKs off).Schema audit (why exactly these five tables)
Proposed fix
Add five manual DELETEs to the existing cascade (matching the current manual-DELETE style, no schema migration):
quality_gatesbeforetasks, thengate_runs/replan_history/assessments/artifactsorphan cleanup, then the existing flow. I have this working locally with a regression test and will submit a PR referencing this issue.Prior art: #5698 / #5787 (both closed) touched adjacent lifecycle areas but not this FK gap.