Allow failed runs to always be deleted

Failed runs have no output to protect, so they can be deleted
without checking L2 shared status or activity records.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-08 01:48:23 +00:00
parent 0e4f596401
commit 6142c8bbab

View File

@@ -406,28 +406,30 @@ async def discard_run(run_id: str, username: str = Depends(get_required_user)):
if run.username not in (username, actor_id):
raise HTTPException(403, "Access denied")
# Check if activity exists for this run
activity = cache_manager.get_activity(run_id)
# Failed runs can always be deleted (no output to protect)
if run.status != "failed":
# Check if activity exists for this run
activity = cache_manager.get_activity(run_id)
if activity:
# Use activity manager deletion rules
can_discard, reason = cache_manager.can_discard_activity(run_id)
if not can_discard:
raise HTTPException(400, f"Cannot discard run: {reason}")
if activity:
# Use activity manager deletion rules
can_discard, reason = cache_manager.can_discard_activity(run_id)
if not can_discard:
raise HTTPException(400, f"Cannot discard run: {reason}")
# Discard the activity (cleans up cache entries)
success, msg = cache_manager.discard_activity(run_id)
if not success:
raise HTTPException(500, f"Failed to discard: {msg}")
else:
# Legacy run without activity record - check L2 shared status manually
items_to_check = list(run.inputs or [])
if run.output_hash:
items_to_check.append(run.output_hash)
# Discard the activity (cleans up cache entries)
success, msg = cache_manager.discard_activity(run_id)
if not success:
raise HTTPException(500, f"Failed to discard: {msg}")
else:
# Legacy run without activity record - check L2 shared status manually
items_to_check = list(run.inputs or [])
if run.output_hash:
items_to_check.append(run.output_hash)
for content_hash in items_to_check:
if cache_manager.l2_checker.is_shared(content_hash):
raise HTTPException(400, f"Cannot discard run: item {content_hash[:16]}... is published to L2")
for content_hash in items_to_check:
if cache_manager.l2_checker.is_shared(content_hash):
raise HTTPException(400, f"Cannot discard run: item {content_hash[:16]}... is published to L2")
# Remove from Redis
redis_client.delete(f"{RUNS_KEY_PREFIX}{run_id}")