Explorar o código

Fix server-side progress calculation issue in generation_queue.cpp

- Fixed the first generation callback handling to properly ignore incoming genProgress value
- Ensured progress starts at exactly 50% when transitioning from queued to processing state
- Added debug logging to show the ignored genProgress value for troubleshooting
- This prevents queue items from starting at ~80% instead of 50% when transitioning states
Fszontagh hai 3 meses
pai
achega
dcabe0c6ae
Modificáronse 1 ficheiros con 15 adicións e 18 borrados
  1. 15 18
      src/generation_queue.cpp

+ 15 - 18
src/generation_queue.cpp

@@ -180,13 +180,13 @@ public:
                 float finalProgress = activeJobs[request.id].progress;
                 auto completionTime = std::chrono::system_clock::now();
                 auto totalGenerationTime = std::chrono::duration_cast<std::chrono::milliseconds>(completionTime - startTime).count();
-                
+
                 LOG_DEBUG("[TIMING_ANALYSIS] Job " + request.id +
                           " - Total generation time: " + std::to_string(totalGenerationTime) + "ms");
                 LOG_DEBUG("[JOB_COMPLETION] Job " + request.id +
                           " - Status changing to '" + (result.success ? "completed" : "failed") + "'" +
                           " - Progress at completion: " + std::to_string(static_cast<int>(finalProgress * 100.0f)) + "%");
-                
+
                 activeJobs[request.id].status = result.success ? GenerationStatus::COMPLETED : GenerationStatus::FAILED;
                 activeJobs[request.id].endTime = endTime;
 
@@ -254,7 +254,7 @@ public:
         if (it != activeJobs.end()) {
             // Clamp model loading progress to valid range [0.0, 1.0]
             modelProgress = std::max(0.0f, std::min(1.0f, modelProgress));
-            
+
             it->second.modelLoadProgress = modelProgress;
             it->second.generationProgress = 0.0f;
             // Overall progress during model loading is just the model loading progress
@@ -283,7 +283,7 @@ public:
         if (it != activeJobs.end()) {
             // Clamp generation progress to valid range [0.0, 1.0]
             genProgress = std::max(0.0f, std::min(1.0f, genProgress));
-            
+
             it->second.generationProgress = genProgress;
             it->second.currentStep = step;
             it->second.totalSteps = totalSteps;
@@ -291,19 +291,20 @@ public:
 
             // Handle first generation callback specially
             if (it->second.firstGenerationCallback) {
-                // This is the first callback, reset generation progress to start from 0.0
+                // This is the first callback, ignore the incoming genProgress value
                 // and set overall progress to exactly 50% (model loading complete)
                 it->second.generationProgress = 0.0f;
                 it->second.progress = 0.5f;
                 it->second.firstGenerationCallback = false; // Mark that we've handled the first callback
-                
+
                 LOG_DEBUG("First generation callback for job " + jobId +
-                          " - Reset generation progress to 0.0 and overall progress to 50%");
+                          " - Ignored genProgress (" + std::to_string(genProgress) +
+                          "), reset generation progress to 0.0 and overall progress to 50%");
             } else {
                 // For subsequent callbacks, calculate overall progress normally: 50% for model loading + 50% for generation
                 it->second.progress = 0.5f + (genProgress * 0.5f);
             }
-            
+
             // Clamp overall progress to valid range [0.0, 1.0]
             it->second.progress = std::max(0.0f, std::min(1.0f, it->second.progress));
 
@@ -341,8 +342,6 @@ public:
             return result;
         }
 
-        // Update job status to MODEL_LOADING if model needs to be loaded
-        bool modelNeededLoading = false;
         if (!modelManager->isModelLoaded(request.modelName)) {
             // Update status to show model is being loaded
             {
@@ -382,8 +381,6 @@ public:
                 return result;
             }
 
-            modelNeededLoading = true;
-
             // Reset status after successful model loading
             {
                 std::lock_guard<std::mutex> lock(jobsMutex);
@@ -570,18 +567,18 @@ public:
             // Save generated images to files
             LOG_DEBUG("[TIMING_ANALYSIS] Job " + request.id + " - Starting post-processing (image saving) phase");
             auto postProcessingStart = std::chrono::system_clock::now();
-            
+
             for (size_t i = 0; i < generatedImages.size(); i++) {
                 const auto& image = generatedImages[i];
                 LOG_DEBUG("[TIMING_ANALYSIS] Job " + request.id + " - Saving image " + std::to_string(i+1) + "/" + std::to_string(generatedImages.size()));
                 auto imageSaveStart = std::chrono::system_clock::now();
-                
+
                 std::string imagePath = saveImageToFile(image, request.id, i);
-                
+
                 auto imageSaveEnd = std::chrono::system_clock::now();
                 auto imageSaveTime = std::chrono::duration_cast<std::chrono::milliseconds>(imageSaveEnd - imageSaveStart).count();
                 LOG_DEBUG("[TIMING_ANALYSIS] Job " + request.id + " - Image " + std::to_string(i+1) + " save took " + std::to_string(imageSaveTime) + "ms");
-                
+
                 if (!imagePath.empty()) {
                     result.imagePaths.push_back(imagePath);
                 } else {
@@ -589,7 +586,7 @@ public:
                     return result;
                 }
             }
-            
+
             auto postProcessingEnd = std::chrono::system_clock::now();
             auto postProcessingTime = std::chrono::duration_cast<std::chrono::milliseconds>(postProcessingEnd - postProcessingStart).count();
             LOG_DEBUG("[TIMING_ANALYSIS] Job " + request.id + " - Post-processing completed in " + std::to_string(postProcessingTime) + "ms");
@@ -1272,7 +1269,7 @@ public:
         return ss.str();
     }
 
-    
+
     // Helper function to populate JobInfo from GenerationRequest
     void populateJobInfoFromRequest(JobInfo& jobInfo, const GenerationRequest& request) {
         // Model information