mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 05:39:20 +08:00
* fix(knowledge): drop visual assets on every document-delete path Extracted figures are tracked in `visual_assets/` (manifest + image files) and were only cleaned by the HTTP delete-file route, which called `VisualAssetStore.remove_source` itself. `remove_raw_document` has three callers - that route plus the GitHub and web source syncs - so the two sync paths deleted the document and left its figures and manifest entries behind forever. Images are capped at 5 MB each, so a sync that drops figure-heavy documents leaks a lot of disk. Reproduced before the fix: a KB with one raw PDF and a matching asset entry, then `remove_raw_document(kb, doc)` (exactly what both syncs do) -> the doc was gone while the asset file and its manifest entry both remained. Cleanup now happens in `remove_raw_document`, the single layer all three deletion paths share, keyed by the module's existing `_raw_hash_key` - the same rule indexing uses to record `source_path`, so nested raw/ paths cannot be missed. The route's now-redundant call is removed rather than left as a second owner: it also removes a second, lexical relative-path computation, and the old uncaught call could 500 a delete on a corrupt manifest, which contradicts the "cleanup never fails a user's delete" contract. Best-effort like the surrounding code: a corrupt or read-only manifest logs a warning and never turns a delete into an error. `VisualAssetStore.__init__` only assigns paths, and `remove_source` returns before writing when no entry matches, so KBs that never had images are not given an empty `visual_assets/` directory (pinned by a test). Verified: 7 new tests; mutation check shows disabling the cleanup fails 4 of them. Independent checks: nested `papers/2024/` asset removed while a sibling document's asset is preserved; no `visual_assets/` created for an image-free KB; re-running the original repro now reports no leak. Tests: 264 passed (knowledge, visual assets, source sync, HTTP file deletion). Note: assets for an older parser signature are deliberately kept so a rollback to an older index version still resolves its figures; that is retention, not a leak, and is unchanged here. * fix(api): 更新路由索引指纹 重新生成 knowledge 路由变更后的索引。原生引擎和路由加载器的 18 个测试均已通过。 --------- Co-authored-by: zszz3 <zszz3@users.noreply.github.com>