Pulastya B commited on
Commit
8b3cf97
·
1 Parent(s): b362856

Fix real-time progress tracking - clear stale progress, filter by request timestamp, improve status formatting

Browse files
FRRONTEEEND/components/ChatInterface.tsx CHANGED
@@ -75,10 +75,12 @@ export const ChatInterface: React.FC<{ onBack: () => void }> = ({ onBack }) => {
75
  updateSession(activeSessionId, newMessages);
76
  setInput('');
77
  setIsTyping(true);
 
78
 
79
- // Start polling for progress updates
80
  const sessionKey = activeSessionId || 'default';
81
  let progressInterval: NodeJS.Timeout | null = null;
 
82
 
83
  const pollProgress = async () => {
84
  try {
@@ -88,14 +90,28 @@ export const ChatInterface: React.FC<{ onBack: () => void }> = ({ onBack }) => {
88
  const progressData = await progressResponse.json();
89
  const steps = progressData.steps || [];
90
 
91
- // Find the most recent running step, or last completed step
92
- const runningSteps = steps.filter((s: any) => s.status === 'running');
 
 
 
 
 
 
 
93
  if (runningSteps.length > 0) {
94
  const lastStep = runningSteps[runningSteps.length - 1];
95
- setCurrentStep(lastStep.tool);
96
- } else if (steps.length > 0) {
 
 
 
 
 
 
 
97
  // No running steps - check if there are completed steps
98
- const completedSteps = steps.filter((s: any) => s.status === 'completed');
99
  if (completedSteps.length > 0) {
100
  // Only show if very recent (workflow still in progress)
101
  const lastCompleted = completedSteps[completedSteps.length - 1];
 
75
  updateSession(activeSessionId, newMessages);
76
  setInput('');
77
  setIsTyping(true);
78
+ setCurrentStep(''); // Clear previous step immediately when new request starts
79
 
80
+ // Start polling for progress updates - use consistent session key
81
  const sessionKey = activeSessionId || 'default';
82
  let progressInterval: NodeJS.Timeout | null = null;
83
+ const requestStartTime = Date.now();
84
 
85
  const pollProgress = async () => {
86
  try {
 
90
  const progressData = await progressResponse.json();
91
  const steps = progressData.steps || [];
92
 
93
+ // Only show progress from this request (filter by timestamp)
94
+ const thisRequestSteps = steps.filter((s: any) => {
95
+ if (!s.timestamp) return true;
96
+ const stepTime = s.timestamp * 1000; // Convert to ms
97
+ return stepTime >= requestStartTime - 1000; // Allow 1s margin
98
+ });
99
+
100
+ // Find the most recent running step
101
+ const runningSteps = thisRequestSteps.filter((s: any) => s.status === 'running');
102
  if (runningSteps.length > 0) {
103
  const lastStep = runningSteps[runningSteps.length - 1];
104
+ // Format tool name nicely: "generate_interactive_scatter" -> "Generating Interactive Scatter"
105
+ const toolName = lastStep.tool
106
+ .replace(/^(generate|train|clean|encode|create|analyze)_/, '')
107
+ .replace(/_/g, ' ')
108
+ .split(' ')
109
+ .map((w: string) => w.charAt(0).toUpperCase() + w.slice(1))
110
+ .join(' ');
111
+ setCurrentStep(`${['Generating', 'Training', 'Cleaning', 'Encoding', 'Creating', 'Analyzing'][0]} ${toolName}`);
112
+ } else if (thisRequestSteps.length > 0) {
113
  // No running steps - check if there are completed steps
114
+ const completedSteps = thisRequestSteps.filter((s: any) => s.status === 'completed');
115
  if (completedSteps.length > 0) {
116
  // Only show if very recent (workflow still in progress)
117
  const lastCompleted = completedSteps[completedSteps.length - 1];
src/api/app.py CHANGED
@@ -96,9 +96,15 @@ async def root():
96
  @app.get("/api/progress/{session_id}")
97
  async def get_progress(session_id: str):
98
  """Get progress updates for a specific session."""
 
 
 
 
 
 
99
  return {
100
  "session_id": session_id,
101
- "steps": progress_store.get(session_id, [])
102
  }
103
 
104
 
 
96
  @app.get("/api/progress/{session_id}")
97
  async def get_progress(session_id: str):
98
  """Get progress updates for a specific session."""
99
+ steps = progress_store.get(session_id, [])
100
+
101
+ # Filter out stale progress (older than 5 minutes)
102
+ current_time = time.time()
103
+ fresh_steps = [s for s in steps if current_time - s.get('timestamp', 0) < 300]
104
+
105
  return {
106
  "session_id": session_id,
107
+ "steps": fresh_steps
108
  }
109
 
110