From 05231233f1e04f32fbffe02da8f0da275380a5f2 Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 3 Jul 2025 21:36:35 +0800 Subject: [PATCH] Feat: Check pending equest_pending after document deletion - Add double-check for pipeline status to prevent race conditions - Implement automatic processing of pending indexing requests after deletion --- lightrag/api/routers/document_routes.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lightrag/api/routers/document_routes.py b/lightrag/api/routers/document_routes.py index 310ab922..c8b74a7d 100644 --- a/lightrag/api/routers/document_routes.py +++ b/lightrag/api/routers/document_routes.py @@ -861,8 +861,13 @@ async def background_delete_documents( successful_deletions = [] failed_deletions = [] - # Set pipeline status to busy for deletion + # Double-check pipeline status before proceeding async with pipeline_status_lock: + if pipeline_status.get("busy", False): + logger.warning("Error: Unexpected pipeline busy state, aborting deletion.") + return # Abort deletion operation + + # Set pipeline status to busy for deletion pipeline_status.update( { "busy": True, @@ -971,12 +976,23 @@ async def background_delete_documents( async with pipeline_status_lock: pipeline_status["history_messages"].append(error_msg) finally: - # Final summary + # Final summary and check for pending requests async with pipeline_status_lock: pipeline_status["busy"] = False completion_msg = f"Deletion completed: {len(successful_deletions)} successful, {len(failed_deletions)} failed" pipeline_status["latest_message"] = completion_msg pipeline_status["history_messages"].append(completion_msg) + + # Check if there are pending document indexing requests + has_pending_request = pipeline_status.get("request_pending", False) + + # If there are pending requests, start document processing pipeline + if has_pending_request: + try: + logger.info("Processing pending document indexing requests after deletion") + await rag.apipeline_process_enqueue_documents() + except Exception as e: + logger.error(f"Error processing pending documents after deletion: {e}") def create_document_routes(