'
+
+ run = load_run(run_id)
+ if not run:
+ return '
Run not found
'
+
+ # Check ownership
+ actor_id = f"@{current_user}@{L2_DOMAIN}"
+ if run.username not in (current_user, actor_id):
+ return '
Access denied
'
+
+ # Failed runs can always be deleted
+ if run.status != "failed":
+ # Check if activity exists for this run
+ activity = cache_manager.get_activity(run_id)
+
+ if activity:
+ can_discard, reason = cache_manager.can_discard_activity(run_id)
+ if not can_discard:
+ return f'
Cannot discard: {reason}
'
+
+ success, msg = cache_manager.discard_activity(run_id)
+ if not success:
+ return f'
Failed to discard: {msg}
'
+ else:
+ # Legacy run - check L2 shared status
+ 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):
+ return f'
Cannot discard: item {content_hash[:16]}... is published to L2