Skip to content

Stuck at showing only 2 repos #6

@noelsaw1

Description

@noelsaw1

Possible fixes by Claude Opus:

KISS Smart Batch Installer - Progressive Loading Debug Analysis

🔴 Critical Issue Identified

Problem: Progressive loading stops after 2 repositories despite having 33 available repos and a limit setting of 5.

Visual Evidence:

  • Console shows: "Found 33 repositories to process (limit 5)"
  • Table only displays 2 repository rows
  • No error messages after the 2nd repository
  • Processing appears to stop silently

🔍 Root Cause Analysis

Primary Suspect: JavaScript Execution Flow Issue

The progressive loading mechanism in admin.js is likely experiencing one of these issues:

  1. Processing Queue Lock: The processingQueue flag may be getting stuck in true state
  2. Active Request Not Clearing: The activeRequest handle might not be properly cleared
  3. Silent JavaScript Error: An uncaught exception might be stopping execution
  4. Race Condition: Overlapping AJAX requests causing state corruption

Code Flow Trace

// Current flow in admin.js (lines ~180-280)
1. startProgressiveLoading()  fetches list of 33 repos 
2. Sets totalRepositories = 33 
3. Applies limit: repositories.slice(0, 5) 
4. Starts processNextRepository() 
5. Processes repository 1 
6. Processes repository 2 
7. STOPS HERE  (should continue to 3, 4, 5)

🛠️ Debugging Steps

Step 1: Add Detailed Console Logging

Add these debug statements to src/Admin/RepositoryManager.php in the render_scripts() method:

function processNextRepository() {
    console.log('🔍 processNextRepository called', {
        currentIndex: currentIndex,
        totalRepositories: totalRepositories,
        processingQueue: processingQueue,
        activeRequest: activeRequest,
        isLoading: isLoading
    });
    
    // Add guard clause debugging
    if (processingQueue || activeRequest !== null) {
        console.warn('⚠️ BLOCKED: processingQueue=' + processingQueue + ', activeRequest=' + (activeRequest !== null));
        return;
    }
    
    if (currentIndex >= totalRepositories) {
        console.log('✅ All repositories processed');
        // ... rest of completion logic
        return;
    }
    
    // ... rest of function
}

Step 2: Check AJAX Response Handling

The issue likely occurs in the response handling after repository #2:

activeRequest = $.post(ajaxurl, requestData)
.done(function(response) {
    console.log('✅ Repository processed:', repo.name, response);
    activeRequest = null; // THIS MIGHT NOT BE EXECUTING
    
    // Check if response.success exists
    if (typeof response.success === 'undefined') {
        console.error('❌ Invalid response structure:', response);
    }
    
    // ... rest of done handler
})
.fail(function(xhr, status, error) {
    console.error('❌ Request failed:', {
        repo: repo.name,
        status: status,
        error: error,
        xhr: xhr
    });
    activeRequest = null; // THIS MIGHT NOT BE EXECUTING
    // ... rest of fail handler
})
.always(function() {
    console.log('🔄 Request complete for:', repo.name);
    // ADD THIS to ensure cleanup:
    activeRequest = null;
    processingQueue = false;
});

🔧 Proposed Fixes

Fix 1: Ensure State Reset in All Cases

// Replace the advance logic with more robust state management
var advanceAfter = function(delayMs) {
    console.log('➡️ Advancing to next repository after', delayMs, 'ms');
    
    // CRITICAL: Always reset these
    activeRequest = null;
    processingQueue = false;
    currentIndex++;
    
    if (currentIndex >= totalRepositories) {
        console.log('🏁 Completed all repositories');
        $('#sbi-loading-progress').hide();
        updateItemCount();
        isLoading = false;
        return;
    }
    
    var ms = delayMs || 5000;
    setTimeout(function() { 
        processNextRepository(); 
    }, ms);
};

Fix 2: Add Error Recovery

// Add global error handler for uncaught exceptions
window.addEventListener('error', function(event) {
    if (isLoading) {
        console.error('❌ Error during progressive loading:', event.error);
        // Reset state and try to continue
        activeRequest = null;
        processingQueue = false;
        currentIndex++;
        setTimeout(processNextRepository, 1000);
    }
});

Fix 3: Fix Repository Limit Application

Check if the limit is being applied correctly:

// In startProgressiveLoading function
repositories = response.data.repositories;
totalRepositories = repositories.length;

// Debug the limit application
console.log('📊 Before limit:', repositories.length, 'repos');
if (repositoryLimit > 0 && repositories.length > repositoryLimit) {
    repositories = repositories.slice(0, repositoryLimit);
    totalRepositories = repositories.length; // UPDATE THIS!
    console.log('📊 After limit:', repositories.length, 'repos');
}

🐛 Quick Debug Test

Add this temporary debug function to test the queue:

// Add to console for testing
window.debugSBI = function() {
    console.log('SBI Debug State:', {
        currentIndex: currentIndex,
        totalRepositories: totalRepositories,
        repositoriesArray: repositories,
        processingQueue: processingQueue,
        activeRequest: activeRequest,
        isLoading: isLoading,
        repositoryLimit: repositoryLimit
    });
    
    // Force advance if stuck
    if (confirm('Force advance to next repository?')) {
        activeRequest = null;
        processingQueue = false;
        processNextRepository();
    }
};

Then run debugSBI() in console when it gets stuck.

🎯 Most Likely Issue

Based on the symptoms, the most likely issue is:

The totalRepositories variable is set to 33 (full list) but the repositories array is sliced to 5, causing an index mismatch.

When currentIndex reaches 2 and tries to access repositories[2], it might be undefined if the array was sliced but the total count wasn't updated.

Immediate Fix to Try:

In src/Admin/RepositoryManager.php, find the progressive loading success handler and ensure:

repositories = response.data.repositories;

// Apply limit if specified
if (repositoryLimit > 0 && repositories.length > repositoryLimit) {
    repositories = repositories.slice(0, repositoryLimit);
}

// CRITICAL: Use the actual array length, not the original count
totalRepositories = repositories.length; // Should be 5, not 33!

📝 Verification Steps

  1. Clear browser cache and reload page
  2. Open browser console
  3. Set repository limit to 5
  4. Start repository fetch
  5. Watch for console errors after repository 08 23 augment implement other claude fixes #2
  6. Run debugSBI() if it stops
  7. Check if repositories[2] exists in the array

🚨 Emergency Workaround

If you need it working immediately, try setting the delay to 0 instead of 5000ms:

// Change this line in processNextRepository
setTimeout(function() { processNextRepository(); }, 100); // Reduced from 5000ms

📊 Expected Console Output (When Fixed)

🚀 Starting progressive loading for organization: kissplugins
📊 Found 33 repositories to process (limit 5)
📊 After applying limit: 5 repositories to process
🔄 Processing repository 1/5: KISS-Projects-Tasks
✅ Successfully processed repository: kissplugins/KISS-Projects-Tasks
🔄 Processing repository 2/5: NHK-plugin-framework
✅ Successfully processed repository: kissplugins/NHK-plugin-framework
🔄 Processing repository 3/5: [next repo name]
✅ Successfully processed repository: [next repo name]
🔄 Processing repository 4/5: [next repo name]
✅ Successfully processed repository: [next repo name]
🔄 Processing repository 5/5: [next repo name]
✅ Successfully processed repository: [next repo name]
🎉 All repositories processed successfully

🔴 Critical Code Location

The bug is most likely in src/Admin/RepositoryManager.php around line 1100-1200 in the JavaScript section where totalRepositories is set but not updated after slicing the array.

Check specifically:

  • Line where totalRepositories = repositories.length; is set
  • Line where repositories = repositories.slice(0, repositoryLimit); is applied
  • Ensure totalRepositories is updated AFTER the slice operation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions