fix: Resolve real-time agent progress update issues
- Modify StreamHandler to send current agent statuses immediately upon WebSocket connection - Switch AnalysisService to use asynchronous graph streaming (astream) to prevent event loop blocking - Clean up debug logging in frontend and backend
This commit is contained in:
parent
b4c0d46681
commit
9fad42ad76
|
|
@ -143,7 +143,7 @@ class AnalysisService:
|
|||
|
||||
# Stream the analysis
|
||||
trace = []
|
||||
for chunk in graph.graph.stream(init_agent_state, **args):
|
||||
async for chunk in graph.graph.astream(init_agent_state, **args):
|
||||
if update_callback:
|
||||
await self._process_chunk(chunk, update_callback, analysis_id, request.analysts)
|
||||
trace.append(chunk)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
from datetime import datetime
|
||||
from typing import Dict, Set
|
||||
from fastapi import WebSocket, WebSocketDisconnect
|
||||
from ..models.schemas import StreamUpdate
|
||||
|
|
@ -64,6 +65,15 @@ class StreamHandler:
|
|||
"timestamp": ""
|
||||
})
|
||||
|
||||
# Send current agent statuses
|
||||
current_statuses = self.analysis_service.agent_statuses.get(analysis_id, {})
|
||||
for agent, status in current_statuses.items():
|
||||
await websocket.send_json({
|
||||
"type": "agent_status",
|
||||
"data": {"agent": agent, "status": status},
|
||||
"timestamp": datetime.now().isoformat()
|
||||
})
|
||||
|
||||
# Keep connection alive and forward updates
|
||||
while True:
|
||||
# Wait for any incoming messages (ping/pong or close)
|
||||
|
|
|
|||
|
|
@ -94,16 +94,14 @@ export default function AnalysisPage() {
|
|||
Analysis: {statusData?.ticker || "Loading..."} - {statusData?.analysis_date || ""}
|
||||
</h1>
|
||||
<div className="flex items-center space-x-4">
|
||||
<span className={`px-3 py-1 rounded-full text-sm ${
|
||||
status === "completed" ? "bg-green-100 text-green-800" :
|
||||
<span className={`px-3 py-1 rounded-full text-sm ${status === "completed" ? "bg-green-100 text-green-800" :
|
||||
status === "running" ? "bg-blue-100 text-blue-800" :
|
||||
"bg-gray-100 text-gray-800"
|
||||
}`}>
|
||||
"bg-gray-100 text-gray-800"
|
||||
}`}>
|
||||
{status}
|
||||
</span>
|
||||
<span className={`px-3 py-1 rounded-full text-sm ${
|
||||
isConnected ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"
|
||||
}`}>
|
||||
<span className={`px-3 py-1 rounded-full text-sm ${isConnected ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"
|
||||
}`}>
|
||||
{isConnected ? "Connected" : "Disconnected"}
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue