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:
40
server.py
40
server.py
@@ -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):
|
if run.username not in (username, actor_id):
|
||||||
raise HTTPException(403, "Access denied")
|
raise HTTPException(403, "Access denied")
|
||||||
|
|
||||||
# Check if activity exists for this run
|
# Failed runs can always be deleted (no output to protect)
|
||||||
activity = cache_manager.get_activity(run_id)
|
if run.status != "failed":
|
||||||
|
# Check if activity exists for this run
|
||||||
|
activity = cache_manager.get_activity(run_id)
|
||||||
|
|
||||||
if activity:
|
if activity:
|
||||||
# Use activity manager deletion rules
|
# Use activity manager deletion rules
|
||||||
can_discard, reason = cache_manager.can_discard_activity(run_id)
|
can_discard, reason = cache_manager.can_discard_activity(run_id)
|
||||||
if not can_discard:
|
if not can_discard:
|
||||||
raise HTTPException(400, f"Cannot discard run: {reason}")
|
raise HTTPException(400, f"Cannot discard run: {reason}")
|
||||||
|
|
||||||
# Discard the activity (cleans up cache entries)
|
# Discard the activity (cleans up cache entries)
|
||||||
success, msg = cache_manager.discard_activity(run_id)
|
success, msg = cache_manager.discard_activity(run_id)
|
||||||
if not success:
|
if not success:
|
||||||
raise HTTPException(500, f"Failed to discard: {msg}")
|
raise HTTPException(500, f"Failed to discard: {msg}")
|
||||||
else:
|
else:
|
||||||
# Legacy run without activity record - check L2 shared status manually
|
# Legacy run without activity record - check L2 shared status manually
|
||||||
items_to_check = list(run.inputs or [])
|
items_to_check = list(run.inputs or [])
|
||||||
if run.output_hash:
|
if run.output_hash:
|
||||||
items_to_check.append(run.output_hash)
|
items_to_check.append(run.output_hash)
|
||||||
|
|
||||||
for content_hash in items_to_check:
|
for content_hash in items_to_check:
|
||||||
if cache_manager.l2_checker.is_shared(content_hash):
|
if cache_manager.l2_checker.is_shared(content_hash):
|
||||||
raise HTTPException(400, f"Cannot discard run: item {content_hash[:16]}... is published to L2")
|
raise HTTPException(400, f"Cannot discard run: item {content_hash[:16]}... is published to L2")
|
||||||
|
|
||||||
# Remove from Redis
|
# Remove from Redis
|
||||||
redis_client.delete(f"{RUNS_KEY_PREFIX}{run_id}")
|
redis_client.delete(f"{RUNS_KEY_PREFIX}{run_id}")
|
||||||
|
|||||||
Reference in New Issue
Block a user