Guard genlocke data integrity edge cases

Block deletion of runs linked to a genlocke leg, prevent reactivating
completed/failed genlocke-linked runs, and guard encounter deletion
against genlocke transfer references with clear 400 errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Julian Tabel
2026-02-09 12:03:58 +01:00
parent d3b65e3c79
commit f0307f0625
4 changed files with 59 additions and 9 deletions

View File

@@ -173,6 +173,17 @@ async def update_run(
)
update_data["completed_at"] = datetime.now(timezone.utc)
# Block reactivating a completed/failed run that belongs to a genlocke
if "status" in update_data and update_data["status"] == "active" and run.status != "active":
leg_result = await session.execute(
select(GenlockeLeg).where(GenlockeLeg.run_id == run_id)
)
if leg_result.scalar_one_or_none() is not None:
raise HTTPException(
status_code=400,
detail="Cannot reactivate a genlocke-linked run. The genlocke controls leg progression.",
)
for field, value in update_data.items():
setattr(run, field, value)
@@ -211,6 +222,16 @@ async def delete_run(
if run is None:
raise HTTPException(status_code=404, detail="Run not found")
# Block deletion if run is linked to a genlocke leg
leg_result = await session.execute(
select(GenlockeLeg).where(GenlockeLeg.run_id == run_id)
)
if leg_result.scalar_one_or_none() is not None:
raise HTTPException(
status_code=400,
detail="Cannot delete a run that belongs to a genlocke. Remove the leg or delete the genlocke first.",
)
# Delete associated boss results first
boss_results = await session.execute(
select(BossResult).where(BossResult.run_id == run_id)