diff --git a/frontend/src/pages/Automation/AutomationPage.tsx b/frontend/src/pages/Automation/AutomationPage.tsx index c6dc4a74..9284ddec 100644 --- a/frontend/src/pages/Automation/AutomationPage.tsx +++ b/frontend/src/pages/Automation/AutomationPage.tsx @@ -735,13 +735,35 @@ const AutomationPage: React.FC = () => { const isActive = currentRun?.current_stage === stage.number; const isComplete = currentRun && currentRun.current_stage > stage.number; const result = currentRun ? (currentRun[`stage_${stage.number}_result` as keyof AutomationRun] as any) : null; - // FIXED: Use stage-specific key for processed count instead of summing all numeric values + + // FIXED: Get processed count from stage result using correct key const processed = getProcessedFromResult(result, stage.number); - // FIXED: Use initial snapshot for total when available, otherwise fallback to pending + processed - const initialCount = initialSnapshot?.[`stage_${stage.number}_initial` as keyof InitialSnapshot] as number | undefined; - const total = initialCount ?? ((stage.pending ?? 0) + processed); - const remaining = Math.max(0, total - processed); - const progressPercent = total > 0 ? Math.round((processed / total) * 100) : 0; + + // FIXED: For total, prioritize: + // 1. *_total from result (set during active processing, most accurate) + // 2. pending from real-time pipeline_overview (current DB state) + // 3. Fallback to processed (for completed stages) + const totalKeyMap: Record = { + 1: 'keywords_total', + 2: 'clusters_total', + 3: 'ideas_total', + 4: 'tasks_total', + 5: 'content_total', + 6: 'images_total', + 7: 'review_total' + }; + const resultTotal = result?.[totalKeyMap[stage.number]] ?? 0; + + // pending = items still waiting to be processed (real-time from DB) + const pending = stage.pending ?? 0; + + // For active/completed stages: use result total if available, else pending + processed + // For pending stages: just show current pending count + const total = isActive || isComplete + ? (resultTotal > 0 ? resultTotal : pending + processed) + : pending; + + const progressPercent = total > 0 ? Math.min(Math.round((processed / total) * 100), 100) : 0; return (
{
- {/* Queue Metrics */} + {/* Simplified Queue Metrics: Only Pending & Processed */}
- Total Items: - {total} + Pending: + 0 ? stageConfig.textColor : 'text-slate-400 dark:text-gray-500'}`}> + {pending} +
Processed: - {processed} -
-
- Remaining: - - {remaining} + 0 ? 'text-success-600 dark:text-success-400' : 'text-slate-400 dark:text-gray-500'}`}> + {processed}
- {/* Credits and Time - Section 6 Enhancement */} - {result && result.credits_used !== undefined && ( -
- Credits Used: - {result.credits_used} -
- )} - {result && result.time_elapsed && ( -
- Duration: - {result.time_elapsed} + {/* Credits and Duration - only show during/after run */} + {result && (result.credits_used > 0 || result.time_elapsed) && ( +
+ {result.credits_used > 0 && ( + {result.credits_used} credits + )} + {result.time_elapsed && ( + {result.time_elapsed} + )}
)}
@@ -838,13 +856,22 @@ const AutomationPage: React.FC = () => { const isActive = currentRun?.current_stage === stage.number; const isComplete = currentRun && currentRun.current_stage > stage.number; const result = currentRun ? (currentRun[`stage_${stage.number}_result` as keyof AutomationRun] as any) : null; - // FIXED: Use stage-specific key for processed count + + // FIXED: Get processed count from stage result using correct key const processed = getProcessedFromResult(result, stage.number); - // FIXED: Use initial snapshot for total when available - const initialCount = initialSnapshot?.[`stage_${stage.number}_initial` as keyof InitialSnapshot] as number | undefined; - const total = initialCount ?? ((stage.pending ?? 0) + processed); - const remaining = Math.max(0, total - processed); - const progressPercent = total > 0 ? Math.round((processed / total) * 100) : 0; + + // FIXED: Same logic as stages 1-4 + const totalKeyMap: Record = { + 5: 'content_total', + 6: 'images_total', + }; + const resultTotal = result?.[totalKeyMap[stage.number]] ?? 0; + const pending = stage.pending ?? 0; + const total = isActive || isComplete + ? (resultTotal > 0 ? resultTotal : pending + processed) + : pending; + + const progressPercent = total > 0 ? Math.min(Math.round((processed / total) * 100), 100) : 0; return (
{
+ {/* Simplified Queue Metrics: Only Pending & Processed */}
- Total Items: - {total} + Pending: + 0 ? stageConfig.textColor : 'text-slate-400 dark:text-gray-500'}`}> + {pending} +
Processed: - {processed} -
-
- Remaining: - - {remaining} + 0 ? 'text-success-600 dark:text-success-400' : 'text-slate-400 dark:text-gray-500'}`}> + {processed}
- {/* Credits and Time - Section 6 Enhancement */} - {result && result.credits_used !== undefined && ( -
- Credits Used: - {result.credits_used} -
- )} - {result && result.time_elapsed && ( -
- Duration: - {result.time_elapsed} + {/* Credits and Duration - only show during/after run */} + {result && (result.credits_used > 0 || result.time_elapsed) && ( +
+ {result.credits_used > 0 && ( + {result.credits_used} credits + )} + {result.time_elapsed && ( + {result.time_elapsed} + )}
)}
@@ -916,7 +940,7 @@ const AutomationPage: React.FC = () => { {isComplete ? '100' : progressPercent}%
-