diff --git a/server.py b/server.py index d10162a..f1d06f6 100644 --- a/server.py +++ b/server.py @@ -437,6 +437,55 @@ async def discard_run(run_id: str, username: str = Depends(get_required_user)): return {"discarded": True, "run_id": run_id} +@app.delete("/ui/runs/{run_id}/discard", response_class=HTMLResponse) +async def ui_discard_run(run_id: str, request: Request): + """HTMX handler: discard a run.""" + current_user = get_user_from_cookie(request) + if not current_user: + return '
Login required
' + + 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
' + + # Remove from Redis + redis_client.delete(f"{RUNS_KEY_PREFIX}{run_id}") + + return ''' +
+ Run deleted. Back to runs +
+ ''' + + @app.get("/run/{run_id}") async def run_detail(run_id: str, request: Request): """Run detail. HTML for browsers, JSON for APIs.""" @@ -590,6 +639,22 @@ async def run_detail(run_id: str, request: Request): ''' + # Delete section + delete_html = f''' +
+

Delete Run

+

+ {"This run failed and can be deleted." if run.status == "failed" else "Delete this run and its associated cache entries."} +

+
+ +
+ ''' + output_link = "" if run.output_hash: output_link = f'''
@@ -661,6 +726,7 @@ async def run_detail(run_id: str, request: Request):
{publish_html} + {delete_html} '''