diff --git a/server.py b/server.py index ada0d10..d10162a 100644 --- a/server.py +++ b/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): 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}")