@@ -501,7 +501,7 @@ const ModernizationPage = () => {
501501 const [ isZipButtonDisabled , setIsZipButtonDisabled ] = useState ( true ) ;
502502 const [ fileLoading , setFileLoading ] = useState ( false ) ;
503503 const [ lastActivityTime , setLastActivityTime ] = useState < number > ( Date . now ( ) ) ;
504- const [ pageLoadTime ] = useState < number > ( Date . now ( ) ) ;
504+ // const [pageLoadTime] = useState<number>(Date.now());
505505
506506 // Fetch file content when a file is selected
507507 useEffect ( ( ) => {
@@ -595,18 +595,9 @@ const ModernizationPage = () => {
595595 fetchBatchData ( batchId ) ;
596596 } , [ batchId ] ) ;
597597
598- // Listen for startProcessing completion and navigate to batch view
599- useEffect ( ( ) => {
600- if ( batchState && ! batchState . loading && batchState . status === "Processing completed" ) {
601- console . log ( "Start processing API completed successfully - processing is done!" ) ;
602-
603- // Check if we have the response with batch_id that matches current batchId
604- if ( batchState . batchId === batchId ) {
605- console . log ( "Processing completed for current batch, navigating to batch view page" ) ;
606- navigate ( `/batch-view/${ batchId } ` ) ;
607- }
608- }
609- } , [ batchState . loading , batchState . status , batchState . batchId , batchId , navigate ] ) ;
598+ // Do NOT navigate based on Redux startProcessing state.
599+ // The start-processing API may return 504 even if backend work is ongoing.
600+ // Navigation is ONLY triggered by actual file completion via WebSocket/polling.
610601
611602 const handleDownloadZip = async ( ) => {
612603 if ( batchId ) {
@@ -803,37 +794,17 @@ const ModernizationPage = () => {
803794 const latestBatch = await fetchBatchSummary ( batchId ! ) ;
804795 setBatchSummary ( latestBatch ) ;
805796
806- // Check if all files are in terminal states OR if the batch itself is marked as completed
797+ // Only complete when all files reach terminal states.
807798 const allFilesDone = latestBatch . files . every ( file =>
808799 [ "completed" , "failed" , "error" ] . includes ( file . status ?. toLowerCase ( ) || "" )
809800 ) ;
810-
811- // Also check if batch status indicates completion (for cases where some files remain queued)
812- const batchCompleted = latestBatch . status ?. toLowerCase ( ) === "completed" ||
813- latestBatch . status ?. toLowerCase ( ) === "failed" ;
814-
815- // Special handling for stuck processing files - if no completed files and long time passed
816- const hasProcessingFiles = latestBatch . files . some ( file =>
817- file . status ?. toLowerCase ( ) === "in_process"
818- ) ;
819- const hasCompletedFiles = latestBatch . files . some ( file =>
820- file . status ?. toLowerCase ( ) === "completed"
821- ) ;
822- const timeSinceLastActivity = Date . now ( ) - lastActivityTime ;
823- const likelyStuckProcessing = hasProcessingFiles &&
824- ! hasCompletedFiles &&
825- timeSinceLastActivity > 60000 ; // 60 seconds of no activity
826-
827- // Consider processing done if either all files are terminal OR batch is marked complete OR files appear stuck
828- const processingComplete = allFilesDone || batchCompleted || likelyStuckProcessing ;
801+
802+ const processingComplete = allFilesDone ;
829803
830804 if ( processingComplete ) {
831805 console . log ( "Processing complete detected:" , {
832806 allFilesDone,
833- batchCompleted,
834- likelyStuckProcessing,
835- batchStatus : latestBatch . status ,
836- timeSinceActivity : timeSinceLastActivity
807+ batchStatus : latestBatch . status
837808 } ) ;
838809 setAllFilesCompleted ( true ) ;
839810 const hasUsableFile = latestBatch . files . some ( file =>
@@ -860,8 +831,8 @@ const ModernizationPage = () => {
860831 return updated ;
861832 } ) ;
862833
863- // Navigate to batch view page when processing is complete
864- console . log ( "Processing complete (either all files done or batch completed ), navigating to batch view page" ) ;
834+ // Navigate only after all files have reached terminal states.
835+ console . log ( "Processing complete (all files done), navigating to batch view page" ) ;
865836 navigate ( `/batch-view/${ batchId } ` ) ;
866837 }
867838 } catch ( err ) {
@@ -942,17 +913,8 @@ useEffect(() => {
942913 file . id === "summary" || // skip summary
943914 [ "completed" , "failed" , "error" ] . includes ( file . status ?. toLowerCase ( ) || "" )
944915 ) ;
945-
946- // Also check if we have at least one completed file and no files currently processing
947- const hasCompletedFiles = files . some ( file =>
948- file . id !== "summary" && file . status === "completed"
949- ) ;
950- const hasProcessingFiles = files . some ( file =>
951- file . id !== "summary" && file . status === "in_process"
952- ) ;
953-
954- // Consider done if all terminal OR (has completed files and no processing files)
955- const effectivelyDone = areAllFilesTerminal || ( hasCompletedFiles && ! hasProcessingFiles ) ;
916+
917+ const effectivelyDone = areAllFilesTerminal ;
956918
957919 if ( files . length > 1 && effectivelyDone && ! allFilesCompleted ) {
958920 console . log ( "Files processing appears complete, checking batch status" ) ;
@@ -1016,44 +978,23 @@ useEffect(() => {
1016978 return ( ) => clearTimeout ( loadingTimeout ) ;
1017979 } , [ progressPercentage , showLoading ] ) ;
1018980
1019- // Add timeout mechanism to navigate if no activity for 30 seconds
981+ // Poll summary status during inactivity, but do not force completion/navigation by timeout.
1020982 useEffect ( ( ) => {
1021983 const checkInactivity = setInterval ( ( ) => {
1022984 const timeSinceLastActivity = Date . now ( ) - lastActivityTime ;
1023985 const hasCompletedFiles = files . some ( file =>
1024986 file . id !== "summary" && file . status === "completed"
1025987 ) ;
1026- const hasProcessingFiles = files . some ( file =>
1027- file . id !== "summary" && file . status === "in_process"
1028- ) ;
1029- const nonSummaryFiles = files . filter ( f => f . id !== "summary" ) ;
1030988
1031- // If we have completed files and no activity for 30 seconds, check if we should navigate
989+ // If we have completed files and no activity for 30 seconds, refresh status.
1032990 if ( hasCompletedFiles && timeSinceLastActivity > 30000 && ! allFilesCompleted ) {
1033991 console . log ( "No activity for 30 seconds with completed files, checking final status" ) ;
1034992 updateSummaryStatus ( ) ;
1035993 }
1036-
1037- // Special case: If only harmful files that are stuck in processing for 60+ seconds
1038- if ( nonSummaryFiles . length > 0 &&
1039- hasProcessingFiles &&
1040- ! hasCompletedFiles &&
1041- timeSinceLastActivity > 60000 &&
1042- ! allFilesCompleted ) {
1043- console . log ( "Files stuck in processing for 60+ seconds, likely failed - checking batch status" ) ;
1044- updateSummaryStatus ( ) ;
1045- }
1046-
1047- // Ultimate fallback: If on page for 2+ minutes with no completion, force navigation
1048- const timeSincePageLoad = Date . now ( ) - pageLoadTime ;
1049- if ( timeSincePageLoad > 120000 && ! allFilesCompleted && nonSummaryFiles . length > 0 ) {
1050- console . log ( "Page loaded for 2+ minutes without completion, forcing navigation to batch view" ) ;
1051- navigate ( `/batch-view/${ batchId } ` ) ;
1052- }
1053994 } , 5000 ) ; // Check every 5 seconds
1054995
1055996 return ( ) => clearInterval ( checkInactivity ) ;
1056- } , [ lastActivityTime , files , allFilesCompleted , updateSummaryStatus , pageLoadTime , navigate , batchId ] ) ;
997+ } , [ lastActivityTime , files , allFilesCompleted , updateSummaryStatus , navigate , batchId ] ) ;
1057998
1058999
10591000 useEffect ( ( ) => {
0 commit comments