Repository navigation
fix(api): POST /documents/stop removes partial chunks and resets counters - #15789
Conversation
Align stop_parse_documents with legacy DELETE /chunks so cancelled documents reset progress/chunk_num and remove indexed chunks from the doc store. Fixes infiniflow#15788.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe PR updates POST /documents/stop to set ChangesDocument parsing cancellation cleanup
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
api/apps/restful_apis/document_api.py (1)
1627-1637: ⚡ Quick winAdd logging for the new stop+cleanup flow.
The new cleanup path cancels tasks, resets counters, and deletes chunks, but emits no success/failure log, which makes incident tracing harder.
As per coding guidelines,
**/*.py: Add logging for new flows.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/apps/restful_apis/document_api.py` around lines 1627 - 1637, Add structured logging around the stop+cleanup flow: log an info-level success message after cancel_all_task_of(doc_id), DocumentService.update_by_id(...) and settings.docStoreConn.delete(...) complete (include doc_id, tenant_id, dataset_id and updated run/progress/chunk_num values), and add an error-level log if settings.docStoreConn.delete throws (catch the exception, log doc_id/tenant_id/dataset_id and the exception details, and ensure success_count is only incremented on successful completion). Use the existing symbols cancel_all_task_of, DocumentService.update_by_id, settings.docStoreConn.delete and success_count to locate where to add these logs.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/apps/restful_apis/document_api.py`:
- Line 1636: Wrap the call to settings.docStoreConn.delete that uses
search.index_name(tenant_id), dataset_id and doc.id in a safe guard so it cannot
raise a 500 if the index/table is missing: either check for the index/table
existence first or catch the specific "not found" / missing-index exception
around settings.docStoreConn.delete and swallow/ log it (do not rethrow),
ensuring the document state changes already performed (the CANCEL state and
zeroed counters) remain in place; use the delete call site
(settings.docStoreConn.delete(... search.index_name(tenant_id) ...)) and handle
only the error variants that indicate a missing index rather than all
exceptions.
---
Nitpick comments:
In `@api/apps/restful_apis/document_api.py`:
- Around line 1627-1637: Add structured logging around the stop+cleanup flow:
log an info-level success message after cancel_all_task_of(doc_id),
DocumentService.update_by_id(...) and settings.docStoreConn.delete(...) complete
(include doc_id, tenant_id, dataset_id and updated run/progress/chunk_num
values), and add an error-level log if settings.docStoreConn.delete throws
(catch the exception, log doc_id/tenant_id/dataset_id and the exception details,
and ensure success_count is only incremented on successful completion). Use the
existing symbols cancel_all_task_of, DocumentService.update_by_id,
settings.docStoreConn.delete and success_count to locate where to add these
logs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 73d7b499-47ef-413b-a71c-00a30a71c71a
📒 Files selected for processing (2)
api/apps/restful_apis/document_api.pytest/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py
Check index_exist before deleting partial chunks so cancellation does not return 500 when the doc store index is missing. Fixes infiniflow#15788.
|
Hi, @wangq8 , @Haruko386 , @JinHai-CN @yingfeng @xugangqiang @buua436 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15789 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
POST /api/v1/datasets/{dataset_id}/documents/stop(stop_parse_documents) cancels parsing tasks and setsruntoCANCEL, but it does not remove chunks already indexed in the doc store or resetprogress/chunk_num. REST callers can end up with a “cancelled” document that still returns partial chunks inGET .../chunksand in retrieval.Legacy
DELETE /api/v1/datasets/{dataset_id}/chunks(stop_parsing) already performs full cleanup: it resets counters and callsdocStoreConn.delete. This PR aligns the newer stop endpoint with that behavior so both paths leave the dataset consistent.Fixes #15788.
Type of change
Changes
stop_parse_documentsindocument_api.pyto resetprogressandchunk_numto0and delete partial chunks viadocStoreConn.deleteaftercancel_all_task_of.test_stop_parse_documents_cleans_partial_chunksto assert counters reset and doc store delete is invoked.Test plan
pytest test/testcases/test_http_api/test_file_management_within_dataset/test_doc_sdk_routes_unit.py::TestDocRoutesUnit::test_stop_parse_documents_cleans_partial_chunks -vPOST .../documents/stopwhileRUNNING, verifyGET .../chunksreturns zero chunks and UIchunk_countis 0DELETE .../chunksbehavior unchanged