From ad03ede7cda0fbf227acaa424174c16170184f42 Mon Sep 17 00:00:00 2001 From: Ted Date: Thu, 4 Dec 2025 19:29:06 +0800 Subject: [PATCH] fix(sdk): add cancel_all_task_of call in stop_parsing endpoint (#11748) ## Problem The SDK API endpoint `DELETE /datasets/{dataset_id}/chunks` only updates database status but does not send cancellation signal via Redis, causing background parsing tasks to continue and eventually complete (status becomes DONE instead of CANCEL). ## Root Cause The SDK endpoint was missing the `cancel_all_task_of(id)` call that the web API ([api/apps/document_app.py](cci:7://file:///d:/workspace1/ragflow-admin/api/apps/document_app.py:0:0-0:0)) uses to properly stop background tasks. ## Solution Added `cancel_all_task_of(id)` call in the [stop_parsing](cci:1://file:///d:/workspace1/ragflow/api/apps/sdk/doc.py:785:0-855:23) function to send cancellation signal via Redis, consistent with the web API behavior. ## Related Issue Fixes #11745 Co-authored-by: tedhappy --- api/apps/sdk/doc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/apps/sdk/doc.py b/api/apps/sdk/doc.py index 23f430a28..d7b918d95 100644 --- a/api/apps/sdk/doc.py +++ b/api/apps/sdk/doc.py @@ -33,7 +33,7 @@ from api.db.services.file_service import FileService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.llm_service import LLMBundle from api.db.services.tenant_llm_service import TenantLLMService -from api.db.services.task_service import TaskService, queue_tasks +from api.db.services.task_service import TaskService, queue_tasks, cancel_all_task_of from api.db.services.dialog_service import meta_filter, convert_conditions from api.utils.api_utils import check_duplicate_ids, construct_json_result, get_error_data_result, get_parser_config, get_result, server_error_response, token_required, \ get_request_json @@ -835,6 +835,8 @@ async def stop_parsing(tenant_id, dataset_id): return get_error_data_result(message=f"You don't own the document {id}.") if int(doc[0].progress) == 1 or doc[0].progress == 0: return get_error_data_result("Can't stop parsing document with progress at 0 or 1") + # Send cancellation signal via Redis to stop background task + cancel_all_task_of(id) info = {"run": "2", "progress": 0, "chunk_num": 0} DocumentService.update_by_id(id, info) settings.docStoreConn.delete({"doc_id": doc[0].id}, search.index_name(tenant_id), dataset_id)