From bdf381a2c8a0337f7459000f487a80f9cbbbdd2f Mon Sep 17 00:00:00 2001
From: YurenHao0426 <blackhao0426@gmail.com>
Date: Sat, 14 Feb 2026 03:40:31 +0000
Subject: Add background task persistence for debate & council operations

Decouple debate/council execution from SSE connection lifecycle so tasks
survive browser disconnects. Backend runs work as asyncio.Tasks with
progressive disk persistence; frontend can reconnect and recover state.

- New backend/app/services/tasks.py: task registry, broadcast pattern,
  disk persistence at milestones, stale task cleanup on startup
- New endpoints: POST start_debate/start_council, GET task stream/poll
- Frontend stores taskId on nodes, recovers running tasks on page load
- _applyPartialEvents rebuilds stage text + data from accumulated events

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---
 frontend/src/components/LeftSidebar.tsx | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'frontend/src/components/LeftSidebar.tsx')

diff --git a/frontend/src/components/LeftSidebar.tsx b/frontend/src/components/LeftSidebar.tsx
index 54c2527..441b7e0 100644
--- a/frontend/src/components/LeftSidebar.tsx
+++ b/frontend/src/components/LeftSidebar.tsx
@@ -30,6 +30,7 @@ const LeftSidebar: React.FC<LeftSidebarProps> = ({ isOpen, onToggle }) => {
     deleteFile,
     readBlueprintFile,
     loadBlueprint,
+    recoverBackgroundTasks,
     saveBlueprintFile,
     saveCurrentBlueprint,
     createProjectFolder,
@@ -266,6 +267,8 @@ const LeftSidebar: React.FC<LeftSidebarProps> = ({ isOpen, onToggle }) => {
       if (vp) {
         setViewport(vp);
       }
+      // Recover any background tasks that were running before page refresh
+      recoverBackgroundTasks();
     } catch (e) {
       console.error(e);
       alert('Not a valid blueprint JSON.');
-- 
cgit v1.2.3

