From a11493502f7706734518722c8a527cdcec5eb0d2 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 21 Jul 2026 17:57:47 +0800 Subject: [PATCH] fix: delete the DB row before files so an interrupted delete can't leave a broken document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Files-first meant a failed DB delete left a valid-looking row whose files were gone: still listed, status completed, dangling file_path, and the surviving file_hash made re-adds dedup onto the broken doc. Row first degrades the same failure to harmless orphan files — the order delete_collection already uses. --- pageindex/backend/local.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pageindex/backend/local.py b/pageindex/backend/local.py index f60b0ef..97bb728 100644 --- a/pageindex/backend/local.py +++ b/pageindex/backend/local.py @@ -245,13 +245,15 @@ class LocalBackend: def delete_document(self, collection: str, doc_id: str) -> None: doc = self._require_document(collection, doc_id) + # DB row first: an interrupted delete then leaves harmless orphan + # files, not a valid-looking document whose files are gone. + self._storage.delete_document(collection, doc_id) if doc.get("file_path"): Path(doc["file_path"]).unlink(missing_ok=True) # Clean up images directory: files/{collection}/{doc_id}/ doc_dir = self._files_dir / collection / doc_id if doc_dir.exists(): shutil.rmtree(doc_dir) - self._storage.delete_document(collection, doc_id) def get_agent_tools(self, collection: str, doc_ids: list[str] | None = None) -> AgentTools: """Build agent tools.