Repository navigation
fix: guard docStoreConn.delete with index_exist in parse and stop_parsing - #15876
Conversation
…sing
Both the POST /chunks (parse) and DELETE /chunks (stop_parsing) paths
called settings.docStoreConn.delete unconditionally. When the tenant/dataset
index has not been created yet (fresh dataset, first parse interrupted before
any chunks were indexed, or index manually removed), the delete throws and
the handler returns HTTP 500 after the document state was already mutated to
RUNNING (parse path) or CANCEL with zeroed counters (stop path).
The newer parse_documents path in document_api.py already uses index_exist
before deleting:
if settings.docStoreConn.index_exist(search.index_name(tenant_id), doc.kb_id):
settings.docStoreConn.delete(...)
Apply the same guard to both sites in chunk_api.py.
Closes infiniflow#15874
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR guards two chunk datastore delete calls in ChangesChunk Datastore Deletion Guards
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related issues
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.
🧹 Nitpick comments (1)
api/apps/restful_apis/chunk_api.py (1)
192-193: ⚡ Quick winAdd logging for the new “skip delete when index is missing” path.
Both guarded branches silently skip cleanup. Add an info/warning log so operators can trace why chunk deletion was not attempted for a document during parse/stop flows.
Proposed patch
- if settings.docStoreConn.index_exist(search.index_name(tenant_id), dataset_id): - settings.docStoreConn.delete({"doc_id": id}, search.index_name(tenant_id), dataset_id) + if settings.docStoreConn.index_exist(search.index_name(tenant_id), dataset_id): + settings.docStoreConn.delete({"doc_id": id}, search.index_name(tenant_id), dataset_id) + else: + logging.info( + "Skip docStore delete in parse: index missing. tenant_id=%s dataset_id=%s doc_id=%s", + tenant_id, + dataset_id, + id, + ) @@ - if settings.docStoreConn.index_exist(search.index_name(tenant_id), dataset_id): - settings.docStoreConn.delete({"doc_id": doc[0].id}, search.index_name(tenant_id), dataset_id) + if settings.docStoreConn.index_exist(search.index_name(tenant_id), dataset_id): + settings.docStoreConn.delete({"doc_id": doc[0].id}, search.index_name(tenant_id), dataset_id) + else: + logging.info( + "Skip docStore delete in stop_parsing: index missing. tenant_id=%s dataset_id=%s doc_id=%s", + tenant_id, + dataset_id, + doc[0].id, + )As per coding guidelines,
**/*.py: “Add logging for new flows”.Also applies to: 243-244
🤖 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/chunk_api.py` around lines 192 - 193, The guarded deletion currently silently skips when the index is missing; add a log entry (logger.info or logger.warning) immediately inside the else/skip path where settings.docStoreConn.index_exist(search.index_name(tenant_id), dataset_id) is false so operators can trace why settings.docStoreConn.delete({"doc_id": id}, search.index_name(tenant_id), dataset_id) was not attempted; include clear context (tenant_id, dataset_id, doc_id/id, and the resolved search.index_name(tenant_id)) and mirror the same logging change at the other guarded branch later in the file where delete is conditionally skipped so both parse/stop flows are observable.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.
Nitpick comments:
In `@api/apps/restful_apis/chunk_api.py`:
- Around line 192-193: The guarded deletion currently silently skips when the
index is missing; add a log entry (logger.info or logger.warning) immediately
inside the else/skip path where
settings.docStoreConn.index_exist(search.index_name(tenant_id), dataset_id) is
false so operators can trace why settings.docStoreConn.delete({"doc_id": id},
search.index_name(tenant_id), dataset_id) was not attempted; include clear
context (tenant_id, dataset_id, doc_id/id, and the resolved
search.index_name(tenant_id)) and mirror the same logging change at the other
guarded branch later in the file where delete is conditionally skipped so both
parse/stop flows are observable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 81f3d827-1c8f-4ec5-993a-88ff1f542b17
📒 Files selected for processing (1)
api/apps/restful_apis/chunk_api.py
Address CodeRabbit review on infiniflow#15876 by emitting info logs in parse and stop_parsing when docStoreConn.index_exist returns false. Co-authored-by: Cursor <[email protected]>
|
Addressed CodeRabbit review feedback in the latest push (logging, non-dict JSON guard, consecutive header merge + tests). Ready for another look. |
1 similar comment
|
Addressed CodeRabbit review feedback in the latest push (logging, non-dict JSON guard, consecutive header merge + tests). Ready for another look. |
|
@wangq8 @kiannidev Small XS bugfix for #15874 — guards |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15876 +/- ##
=======================================
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?
Closes #15874
Both the
POST /api/v1/datasets/<dataset_id>/chunks(re-parse) andDELETE /api/v1/datasets/<dataset_id>/chunks(stop-parsing) handlers calledsettings.docStoreConn.deleteunconditionally. When the tenant/dataset index has not been created yet — fresh dataset, first parse interrupted before any chunks were indexed, or index manually removed — the delete call throws and the handler returns HTTP 500 after the document state was already mutated (RUNNING with zeroed counters for the parse path; CANCEL with zeroed counters for the stop path), leaving the document in an inconsistent state.The newer
parse_documentspath indocument_api.pyalready usesindex_existbefore deleting:How to fix?
Apply the same
index_existguard to both call sites inchunk_api.py:parse(POST path, line ~192): guard the delete beforeTaskService.filter_delete.stop_parsing(DELETE path, line ~242): guard the delete afterDocumentService.update_by_id.Both sites already have the correct
search.index_name(tenant_id)anddataset_idparameters; the guard is a one-line addition at each site.Type of change