Skip to content

refactor(api): establish dataset application boundaries - #41729

Merged
JohnJyong merged 29 commits into
langgenius:mainfrom
41tair:refactor/api-113
Sep 29, 2026
Merged

JohnJyong merged 29 commits into
langgenius:mainfrom
41tair:refactor/api-113

Conversation

@41tair

@41tair 41tair commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

part of #39993

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [] I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-09-29 08:30:35.707080047 +0000
+++ /tmp/pyrefly_pr.txt	2026-09-29 08:30:26.747064664 +0000
@@ -974,14 +974,14 @@
   --> tests/test_containers_integration_tests/services/test_dataset_service.py:38:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_dataset_service.py:40:58
-ERROR Argument `Literal['invalid_action']` is not assignable to parameter `action` with type `Literal['archive', 'disable', 'enable', 'un_archive']` in function `services.dataset_service.DocumentService.batch_update_document_status` [bad-argument-type]
+ERROR Argument `Literal['invalid_action']` is not assignable to parameter `action` with type `Literal['archive', 'disable', 'enable', 'un_archive']` in function `services.knowledge.dataset_service.DocumentService.batch_update_document_status` [bad-argument-type]
    --> tests/test_containers_integration_tests/services/test_dataset_service_batch_update_document_status.py:738:24
 ERROR Argument `Literal['owner']` is not assignable to parameter `role` with type `SQLCoreOperations[TenantAccountRole] | TenantAccountRole` in function `models.account.TenantAccountJoin.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_dataset_service_create_dataset.py:36:18
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:25:20
+  --> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:26:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:32:20
+  --> tests/test_containers_integration_tests/services/test_dataset_service_delete_dataset.py:33:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/services/test_dataset_service_permissions.py:40:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1363,9 +1363,9 @@
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/tasks/test_add_document_to_index_task.py:63:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py:73:20
+  --> tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py:69:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py:82:20
+  --> tests/test_containers_integration_tests/tasks/test_batch_clean_document_task.py:78:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
    --> tests/test_containers_integration_tests/tasks/test_batch_create_segment_to_index_task.py:101:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1375,87 +1375,87 @@
 ERROR `>` is not supported between `None` and `Literal[0]` [unsupported-operation]
    --> tests/test_containers_integration_tests/tasks/test_batch_create_segment_to_index_task.py:750:16
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:113:20
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:114:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:123:20
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:124:20
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:295:32
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:296:32
 ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:298:22
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:299:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:419:32
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:420:32
 ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:422:22
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:423:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:495:36
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:496:36
 ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:498:26
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:499:26
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:552:32
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:553:32
 ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:555:22
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:556:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:638:36
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:639:36
 ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:641:26
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:642:26
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:751:32
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:752:32
 ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:754:22
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:755:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:845:32
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:846:32
 ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:848:22
+   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:849:22
 ERROR Argument `IndexTechniqueType | None` is not assignable to parameter `indexing_technique` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:999:32
+    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:1000:32
 ERROR Argument `str | None` is not assignable to parameter `doc_form` with type `str` in function `celery.app.task.Task.__call__` [bad-argument-type]
-    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:1002:22
+    --> tests/test_containers_integration_tests/tasks/test_clean_dataset_task.py:1003:22
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:101:23
+  --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:84:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:118:27
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:101:27
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:223:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:206:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:274:27
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:251:27
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:286:27
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:263:27
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:357:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:333:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:369:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:345:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:440:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:416:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:457:27
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:433:27
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:542:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:519:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:554:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:531:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:643:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:621:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:655:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:633:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:736:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:714:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:754:27
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:732:27
 ERROR `num_segments_per_doc` may be uninitialized [unbound-name]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:797:32
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:775:32
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:844:27
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:823:27
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:862:27
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:841:27
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:883:31
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:862:31
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:951:23
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:931:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:977:27
+   --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:957:27
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-    --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:1057:23
+    --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:1038:23
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-    --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:1070:23
+    --> tests/test_containers_integration_tests/tasks/test_clean_notion_document_task.py:1051:23
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_deal_dataset_vector_index_task.py:227:16
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
@@ -1501,91 +1501,95 @@
 ERROR `str | None` is not assignable to upper bound `SupportsDunderGT[Any] | SupportsDunderLT[Any]` of type variable `SupportsRichComparisonT` [bad-specialization]
    --> tests/test_containers_integration_tests/tasks/test_disable_segments_from_index_task.py:725:57
 ERROR Unexpected SQLAlchemy update field `data_source_info` [unexpected-keyword]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_sync_task.py:260:82
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_sync_task.py:262:82
+ERROR `in` is not supported between `Literal['Datasource credential not found']` and `None` [not-iterable]
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_sync_task.py:286:16
+ERROR `in` is not supported between `Literal['Indexing error']` and `None` [not-iterable]
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_sync_task.py:442:16
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:270:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:273:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:271:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:274:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:340:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:343:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:341:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:344:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:460:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:463:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:461:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:464:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:525:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:528:20
 ERROR Object of class `NoneType` has no attribute `error` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:526:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:529:20
 ERROR `in` is not supported between `Literal['batch upload']` and `object` [not-iterable]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:527:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:530:20
 ERROR Object of class `NoneType` has no attribute `stopped_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:528:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:531:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:568:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:571:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:569:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:572:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:720:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:723:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:721:20
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_task.py:724:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:129:16
-ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
    --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:130:16
+ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:131:16
 ERROR `>` is not supported between `None` and `Literal[0]` [unsupported-operation]
-   --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:177:16
+   --> tests/test_containers_integration_tests/tasks/test_document_indexing_update_task.py:175:16
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-  --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:99:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:102:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:106:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:109:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:238:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:241:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:245:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:248:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:338:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:341:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:339:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:342:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:390:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:393:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:391:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:394:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:459:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:462:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:460:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:463:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:561:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:564:20
 ERROR Object of class `NoneType` has no attribute `error` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:562:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:565:20
 ERROR Object of class `object` has no attribute `lower` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:563:38
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:566:38
 ERROR Object of class `NoneType` has no attribute `stopped_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:564:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:567:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:604:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:607:20
 ERROR Object of class `NoneType` has no attribute `error` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:605:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:608:20
 ERROR Object of class `object` has no attribute `lower` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:606:31
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:609:31
 ERROR Object of class `NoneType` has no attribute `stopped_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:607:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:610:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:669:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:672:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:712:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:715:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:756:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:759:20
 ERROR Object of class `NoneType` has no attribute `is_paused` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:873:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:876:20
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:874:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:877:20
 ERROR Object of class `NoneType` has no attribute `display_status` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:875:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:878:20
 ERROR Object of class `NoneType` has no attribute `processing_started_at` [missing-attribute]
-   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:876:20
+   --> tests/test_containers_integration_tests/tasks/test_duplicate_document_indexing_task.py:879:20
 ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
   --> tests/test_containers_integration_tests/tasks/test_enable_segments_to_index_task.py:55:20
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1888,26 +1892,16 @@
    --> tests/unit_tests/controllers/console/app/workflow_draft_variables_test.py:136:47
 ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
   --> tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline.py:83:9
-ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
-   --> tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow.py:111:9
-ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
-   --> tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow.py:112:9
-ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
-   --> tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow.py:113:9
-ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
-  --> tests/unit_tests/controllers/console/datasets/test_data_source.py:38:9
-ERROR Argument `scoped_session[flask_sqlalchemy.session.Session]` is not assignable to parameter `session` with type `sqlalchemy.orm.session.Session` in function `_add_binding` [bad-argument-type]
-  --> tests/unit_tests/controllers/console/datasets/test_data_source.py:85:28
-ERROR Missing argument `name` in function `controllers.console.datasets.datasets.DatasetCreatePayload.__init__` [missing-argument]
-   --> tests/unit_tests/controllers/console/datasets/test_datasets.py:615:49
-ERROR Argument `Literal['custom']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:294:18
-ERROR Argument `Literal['custom']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
-   --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:329:67
-ERROR Argument `Literal['custom']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:1665:67
-ERROR Argument `Literal['opendal']` is not assignable to parameter `storage_type` with type `StorageType` in function `tests.unit_tests.model_factories.make_upload_file` [bad-argument-type]
-   --> tests/unit_tests/controllers/console/datasets/test_datasets_segments.py:132:22
+ERROR Argument `Literal['local']` is not assignable to parameter `storage_type` with type `StorageType` in function `models.model.UploadFile.__init__` [bad-argument-type]
+  --> tests/unit_tests/controllers/console/datasets/test_datasets_document_download.py:56:26
+ERROR Argument `Literal['account']` is not assignable to parameter `created_by_role` with type `CreatorUserRole` in function `models.model.UploadFile.__init__` [bad-argument-type]
+  --> tests/unit_tests/controllers/console/datasets/test_datasets_document_download.py:62:29
+ERROR Argument `RequestContext` is not assignable to parameter `object` with type `ExternalKnowledgeApiPayload` in function `list.append` [bad-argument-type]
+  --> tests/unit_tests/controllers/console/datasets/test_external.py:86:17
+ERROR Argument `UUID` is not assignable to parameter `object` with type `ExternalKnowledgeApiPayload` in function `list.append` [bad-argument-type]
+  --> tests/unit_tests/controllers/console/datasets/test_external.py:88:21
+ERROR Argument `UUID` is not assignable to parameter `object` with type `RequestContext` in function `list.append` [bad-argument-type]
+  --> tests/unit_tests/controllers/console/datasets/test_external.py:88:21
 ERROR Unexpected SQLAlchemy update field `app_model_config_id` [unexpected-keyword]
    --> tests/unit_tests/controllers/console/explore/test_message.py:278:83
 ERROR Generator function should return `Generator` [bad-return]
@@ -2118,13 +2112,21 @@
   --> tests/unit_tests/controllers/service_api/conftest.py:39:16
 ERROR Argument `Literal['completed']` is not assignable to parameter `status` with type `SQLCoreOperations[SegmentStatus] | SegmentStatus` in function `models.dataset.DocumentSegment.__init__` [bad-argument-type]
    --> tests/unit_tests/controllers/service_api/conftest.py:197:16
+ERROR Missing argument `mutations` in function `services.knowledge.dataset_service.SegmentService.multi_create_segment` [missing-argument]
+   --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:449:53
+ERROR Missing argument `mutations` in function `services.knowledge.dataset_service.SegmentService.delete_segment` [missing-argument]
+   --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:516:38
+ERROR Missing argument `mutations` in function `services.knowledge.dataset_service.SegmentService.create_child_chunk` [missing-argument]
+   --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:562:51
+ERROR Missing argument `mutations` in function `services.knowledge.dataset_service.SegmentService.update_child_chunk` [missing-argument]
+   --> tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py:625:51
 ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]
    --> tests/unit_tests/controllers/service_api/dataset/test_document.py:142:17
 ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]
    --> tests/unit_tests/controllers/service_api/dataset/test_document.py:186:17
 ERROR Object of class `Document` has no attribute `summary_index_status` [missing-attribute]
    --> tests/unit_tests/controllers/service_api/dataset/test_document.py:216:33
-ERROR Missing argument `session` in function `services.dataset_service.DocumentService.get_document` [missing-argument]
+ERROR Missing argument `session` in function `services.knowledge.dataset_service.DocumentService.get_document` [missing-argument]
    --> tests/unit_tests/controllers/service_api/dataset/test_document.py:428:46
 ERROR Argument `None` is not assignable to parameter `value` with type `SQLCoreOperations[datetime] | datetime` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
   --> tests/unit_tests/controllers/service_api/dataset/test_rag_pipeline_file_upload_serialization.py:34:30
@@ -2141,37 +2143,39 @@
 ERROR Cannot index into `object` [bad-index]
    --> tests/unit_tests/controllers/test_swagger.py:151:20
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:346:16
+   --> tests/unit_tests/controllers/test_swagger.py:294:12
+ERROR Cannot index into `object` [bad-index]
+   --> tests/unit_tests/controllers/test_swagger.py:378:16
 ERROR `in` is not supported between `Literal['user']` and `object` [not-iterable]
-   --> tests/unit_tests/controllers/test_swagger.py:347:16
+   --> tests/unit_tests/controllers/test_swagger.py:379:16
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:362:37
+   --> tests/unit_tests/controllers/test_swagger.py:394:37
 ERROR `in` is not supported between `Literal['user']` and `object` [not-iterable]
-   --> tests/unit_tests/controllers/test_swagger.py:363:16
+   --> tests/unit_tests/controllers/test_swagger.py:395:16
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:374:16
+   --> tests/unit_tests/controllers/test_swagger.py:406:16
 ERROR `not in` is not supported between `Literal['user']` and `object` [not-iterable]
-   --> tests/unit_tests/controllers/test_swagger.py:375:16
+   --> tests/unit_tests/controllers/test_swagger.py:407:16
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:395:20
+   --> tests/unit_tests/controllers/test_swagger.py:427:20
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:404:20
+   --> tests/unit_tests/controllers/test_swagger.py:436:20
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:405:16
+   --> tests/unit_tests/controllers/test_swagger.py:437:16
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:409:12
+   --> tests/unit_tests/controllers/test_swagger.py:441:12
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:480:12
+   --> tests/unit_tests/controllers/test_swagger.py:512:12
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:483:12
+   --> tests/unit_tests/controllers/test_swagger.py:515:12
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:486:12
+   --> tests/unit_tests/controllers/test_swagger.py:518:12
 ERROR Type `object` is not iterable [not-iterable]
-   --> tests/unit_tests/controllers/test_swagger.py:496:5
+   --> tests/unit_tests/controllers/test_swagger.py:528:5
 ERROR Type `object` is not iterable [not-iterable]
-   --> tests/unit_tests/controllers/test_swagger.py:502:19
+   --> tests/unit_tests/controllers/test_swagger.py:534:19
 ERROR Cannot index into `object` [bad-index]
-   --> tests/unit_tests/controllers/test_swagger.py:640:12
+   --> tests/unit_tests/controllers/test_swagger.py:672:12
 ERROR `object` is not assignable to attribute `request` with type `Request` [bad-assignment]
   --> tests/unit_tests/controllers/trigger/test_trigger.py:12:22
 ERROR `_RequestStub` is not assignable to attribute `request` with type `Request` [bad-assignment]
@@ -3093,17 +3097,17 @@
 ERROR Cannot index into `str` [bad-index]
    --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_generate_response_converter.py:111:12
 ERROR Class `PipelineRunner` has no class attribute `call_args` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py:429:12
+   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py:437:12
 ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `RagPipelineGenerateEntity` in function `core.app.apps.pipeline.pipeline_runner.PipelineRunner.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:129:37
+   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:130:37
 ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `RagPipelineGenerateEntity` in function `core.app.apps.pipeline.pipeline_runner.PipelineRunner.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:224:37
+   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:237:37
 ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `RagPipelineGenerateEntity` in function `core.app.apps.pipeline.pipeline_runner.PipelineRunner.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:312:37
+   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:326:37
 ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `RagPipelineGenerateEntity` in function `core.app.apps.pipeline.pipeline_runner.PipelineRunner.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:333:37
+   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:346:37
 ERROR Argument `SimpleNamespace` is not assignable to parameter `application_generate_entity` with type `RagPipelineGenerateEntity` in function `core.app.apps.pipeline.pipeline_runner.PipelineRunner.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:384:37
+   --> tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py:403:37
 ERROR Object of class `Account` has no attribute `tenant_id` [missing-attribute]
    --> tests/unit_tests/core/app/apps/test_base_app_generator.py:599:9
 ERROR Argument `object` is not assignable to parameter `task_id` with type `str` in function `core.app.apps.base_app_queue_manager.AppQueueManager.__init__` [bad-argument-type]
@@ -3717,31 +3721,37 @@
 ERROR Argument `SimpleNamespace` is not assignable to parameter `datasource_type` with type `DatasourceProviderType` in function `core.datasource.datasource_manager.DatasourceManager.get_datasource_plugin_provider` [bad-argument-type]
    --> tests/unit_tests/core/datasource/test_datasource_manager.py:207:29
 ERROR Argument `SimpleNamespace` is not assignable to parameter `datasource_param` with type `DatasourceParameter | None` in function `core.datasource.datasource_manager.DatasourceManager.stream_online_results` [bad-argument-type]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:253:26
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:246:26
 ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `text` [missing-attribute]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:258:12
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:252:12
 ERROR Argument `SimpleNamespace` is not assignable to parameter `datasource_param` with type `DatasourceParameter | None` in function `core.datasource.datasource_manager.DatasourceManager.stream_online_results` [bad-argument-type]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:285:26
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:272:26
 ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `text` [missing-attribute]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:291:13
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:279:13
 ERROR Argument `SimpleNamespace` is not assignable to parameter `online_drive_request` with type `OnlineDriveDownloadFileParam | None` in function `core.datasource.datasource_manager.DatasourceManager.stream_online_results` [bad-argument-type]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:370:30
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:343:30
 ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `text` [missing-attribute]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:375:13
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:349:13
 ERROR Argument `SimpleNamespace` is not assignable to parameter `datasource_param` with type `DatasourceParameter | None` in function `core.datasource.datasource_manager.DatasourceManager.stream_node_events` [bad-argument-type]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:425:30
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:390:30
 ERROR Argument `SimpleNamespace` is not assignable to parameter `datasource_param` with type `DatasourceParameter | None` in function `core.datasource.datasource_manager.DatasourceManager.stream_node_events` [bad-argument-type]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:512:30
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:475:30
 ERROR Argument `SimpleNamespace` is not assignable to parameter `datasource_param` with type `DatasourceParameter | None` in function `core.datasource.datasource_manager.DatasourceManager.stream_node_events` [bad-argument-type]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:563:34
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:524:34
 ERROR Argument `SimpleNamespace` is not assignable to parameter `online_drive_request` with type `OnlineDriveDownloadFileParam | None` in function `core.datasource.datasource_manager.DatasourceManager.stream_node_events` [bad-argument-type]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:609:34
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:568:34
 ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]
-   --> tests/unit_tests/core/datasource/test_datasource_manager.py:669:12
+   --> tests/unit_tests/core/datasource/test_datasource_manager.py:627:12
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
-  --> tests/unit_tests/core/datasource/test_notion_provider.py:51:56
+  --> tests/unit_tests/core/datasource/test_notion_provider.py:53:56
+ERROR Argument `Document` is not assignable to parameter `document_model` with type `StoredDocumentExtractionInput | None` in function `core.rag.extractor.notion_extractor.NotionExtractor.update_last_edited_time` [bad-argument-type]
+   --> tests/unit_tests/core/datasource/test_notion_provider.py:844:48
+ERROR Argument `Document` is not assignable to parameter `document_model` with type `StoredDocumentExtractionInput | None` in function `core.rag.extractor.notion_extractor.NotionExtractor.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/datasource/test_notion_provider.py:886:28
+ERROR Argument `Document` is not assignable to parameter `document_model` with type `StoredDocumentExtractionInput | None` in function `core.rag.extractor.notion_extractor.NotionExtractor.__init__` [bad-argument-type]
+   --> tests/unit_tests/core/datasource/test_notion_provider.py:958:28
 ERROR `in` is not supported between `Literal['Single Page']` and `None` [not-iterable]
-   --> tests/unit_tests/core/datasource/test_website_crawl.py:992:16
+    --> tests/unit_tests/core/datasource/test_website_crawl.py:1010:16
 ERROR Argument `Iterator[DatasourceMessage]` is not assignable to parameter `messages` with type `Generator[DatasourceMessage]` in function `core.datasource.utils.message_transformer.DatasourceFileMessageTransformer.transform_datasource_invoke_messages` [bad-argument-type]
   --> tests/unit_tests/core/datasource/utils/test_message_transformer.py:27:26
 ERROR Object of type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` has no attribute `text` [missing-attribute]
@@ -4196,58 +4206,6 @@
   --> tests/unit_tests/core/rag/data_post_processor/test_data_post_processor.py:29:29
 ERROR Argument `dict[str, str]` is not assignable to parameter `reranking_model` with type `RerankingModelDict | None` in function `core.rag.data_post_processor.data_post_processor.DataPostProcessor._get_rerank_model_instance` [bad-argument-type]
    --> tests/unit_tests/core/rag/data_post_processor/test_data_post_processor.py:192:33
-ERROR Argument `Literal['completed']` is not assignable to parameter `status` with type `SQLCoreOperations[SegmentStatus] | SegmentStatus` in function `models.dataset.DocumentSegment.__init__` [bad-argument-type]
-  --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:70:16
-ERROR Argument `list[Document | SimpleNamespace]` is not assignable to parameter `texts` with type `list[Document]` in function `core.rag.datasource.keyword.jieba.jieba.Jieba.create` [bad-argument-type]
-  --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:88:9
-ERROR Object of class `FunctionType` has no attribute `assert_called_once` [missing-attribute]
-  --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:96:5
-ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
-  --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:97:17
-ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:102:19
-ERROR Object of class `FunctionType` has no attribute `call_count` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:124:12
-ERROR Object of class `FunctionType` has no attribute `call_args_list` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:125:18
-ERROR Object of class `FunctionType` has no attribute `call_args_list` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:126:19
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:131:5
-ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:149:16
-ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:150:12
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:185:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:186:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:187:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:198:5
-ERROR Object of class `FunctionType` has no attribute `assert_not_called` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:199:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:200:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:354:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:355:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:356:5
-ERROR Object of class `FunctionType` has no attribute `reset_mock` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:358:5
-ERROR Object of class `FunctionType` has no attribute `reset_mock` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:359:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:361:5
-ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:362:5
-ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:392:19
-ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
-   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py:395:12
 ERROR Object of class `ModuleType` has no attribute `analyse` [missing-attribute]
   --> tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py:32:5
 ERROR Object of class `ModuleType` has no attribute `default_tfidf` [missing-attribute]
@@ -4292,46 +4250,14 @@
    --> tests/unit_tests/core/rag/embedding/test_embedding_base.py:222:23
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
   --> tests/unit_tests/core/rag/extractor/test_excel_extractor.py:17:56
-ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:223:41
 ERROR Argument `object | None` is not assignable to parameter `session` with type `Session | None` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:223:85
-ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:302:38
-ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:319:41
-ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:347:41
-ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:363:38
-ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:367:38
-ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:371:38
-ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
-   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:375:38
+   --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:222:85
 ERROR Object of class `NoneType` has no attribute `strip` [missing-attribute]
   --> tests/unit_tests/core/rag/extractor/test_markdown_extractor.py:30:16
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
   --> tests/unit_tests/core/rag/extractor/test_notion_extractor.py:29:56
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
    --> tests/unit_tests/core/rag/indexing/test_index_processor.py:184:16
-ERROR Argument `Literal['automatic']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/rag/indexing/test_indexing_runner.py:910:22
-ERROR Argument `Literal['waiting']` is not assignable to parameter `status` with type `SQLCoreOperations[SegmentStatus] | SegmentStatus` in function `models.dataset.DocumentSegment.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/rag/indexing/test_indexing_runner.py:956:20
-ERROR Argument `None` is not assignable to parameter `state` with type `InstanceState[Any]` in function `sqlalchemy.orm.exc.ObjectDeletedError.__init__` [bad-argument-type]
-    --> tests/unit_tests/core/rag/indexing/test_indexing_runner.py:1252:84
-ERROR Argument `Literal['completed']` is not assignable to parameter `after_indexing_status` with type `IndexingStatus` in function `core.indexing_runner.IndexingRunner._update_document_index_status` [bad-argument-type]
-    --> tests/unit_tests/core/rag/indexing/test_indexing_runner.py:1360:13
-ERROR Argument `Literal['completed']` is not assignable to parameter `after_indexing_status` with type `IndexingStatus` in function `core.indexing_runner.IndexingRunner._update_document_index_status` [bad-argument-type]
-    --> tests/unit_tests/core/rag/indexing/test_indexing_runner.py:1390:71
-ERROR Argument `Literal['completed']` is not assignable to parameter `after_indexing_status` with type `IndexingStatus` in function `core.indexing_runner.IndexingRunner._update_document_index_status` [bad-argument-type]
-    --> tests/unit_tests/core/rag/indexing/test_indexing_runner.py:1398:71
-ERROR Argument `Literal['automatic']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
-    --> tests/unit_tests/core/rag/indexing/test_indexing_runner.py:1416:18
-ERROR Argument `Literal['custom']` is not assignable to parameter `mode` with type `ProcessRuleMode | SQLCoreOperations[ProcessRuleMode]` in function `models.dataset.DatasetProcessRule.__init__` [bad-argument-type]
-    --> tests/unit_tests/core/rag/indexing/test_indexing_runner.py:1427:18
 ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
     --> tests/unit_tests/core/rag/rerank/test_reranker.py:1198:9
 ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
@@ -4395,7 +4321,7 @@
 ERROR Argument `SimpleNamespace` is not assignable to parameter `orig` with type `BaseException` in function `sqlalchemy.exc.DBAPIError.__init__` [bad-argument-type]
     --> tests/unit_tests/core/rag/retrieval/test_dataset_retrieval.py:5594:13
 ERROR Argument `str` is not assignable to parameter `metadata_filtering_mode` with type `Literal['automatic', 'disabled', 'manual']` in function `core.workflow.nodes.knowledge_retrieval.retrieval.KnowledgeRetrievalRequest.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/rag/retrieval/test_dataset_retrieval_methods.py:143:33
+   --> tests/unit_tests/core/rag/retrieval/test_dataset_retrieval_methods.py:145:33
 ERROR Argument `Iterator[SimpleNamespace]` is not assignable to parameter `invoke_result` with type `Generator[Unknown]` in function `core.rag.retrieval.router.multi_dataset_react_route.ReactMultiDatasetRouter._handle_invoke_result` [bad-argument-type]
    --> tests/unit_tests/core/rag/retrieval/test_multi_dataset_react_route.py:194:52
 ERROR Argument `None` is not assignable to parameter `text` with type `str` in function `core.rag.splitter.text_splitter.RecursiveCharacterTextSplitter.split_text` [bad-argument-type]
@@ -4915,9 +4841,9 @@
 ERROR Class member `_TestHitCallback.return_retriever_resource_info` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
    --> tests/unit_tests/core/tools/utils/test_misc_utils_extra.py:134:9
 ERROR Argument `_FakeFlaskApp` is not assignable to parameter `flask_app` with type `Flask` in function `core.tools.utils.dataset_retriever.dataset_multi_retriever_tool.DatasetMultiRetrieverTool._retriever` [bad-argument-type]
-   --> tests/unit_tests/core/tools/utils/test_misc_utils_extra.py:413:31
+   --> tests/unit_tests/core/tools/utils/test_misc_utils_extra.py:417:31
 ERROR Argument `_FakeFlaskApp` is not assignable to parameter `flask_app` with type `Flask` in function `core.tools.utils.dataset_retriever.dataset_multi_retriever_tool.DatasetMultiRetrieverTool._retriever` [bad-argument-type]
-   --> tests/unit_tests/core/tools/utils/test_misc_utils_extra.py:464:31
+   --> tests/unit_tests/core/tools/utils/test_misc_utils_extra.py:468:31
 ERROR `None` is not subscriptable [unsupported-operation]
    --> tests/unit_tests/core/tools/utils/test_parser.py:115:12
 ERROR Argument `list[ToolParameter] | None` is not assignable to parameter `obj` with type `Sized` in function `len` [bad-argument-type]
@@ -6095,15 +6021,7 @@
 ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]
    --> tests/unit_tests/factories/test_build_from_mapping.py:185:12
 ERROR Object of class `Dataset` has no attribute `embedding_available` [missing-attribute]
-   --> tests/unit_tests/fields/test_data\n\n... (truncated) ...

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 67.66% 68.92% +1.26%
Strict coverage 67.29% 68.56% +1.28%
Typed symbols 52,042 54,190 +2,148
Untyped symbols 25,012 24,565 -447
Modules 3582 3673 +91

@autofix-ci
autofix-ci Bot requested a review from crazywoola as a code owner September 3, 2026 08:16
@github-actions github-actions Bot added the web This relates to changes on the web. label Sep 3, 2026
@41tair
41tair marked this pull request as draft September 5, 2026 05:41
@github-actions github-actions Bot added e2e End-to-end tests and E2E test infrastructure. and removed e2e End-to-end tests and E2E test infrastructure. labels Sep 8, 2026
@41tair
41tair marked this pull request as ready for review September 17, 2026 10:55
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.50563% with 233 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.50%. Comparing base (be87442) to head (eb454e3).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
api/repositories/knowledge/segment_repository.py 84.02% 24 Missing and 22 partials ⚠️
.../repositories/knowledge/dataset_read_repository.py 87.39% 16 Missing and 13 partials ⚠️
.../controllers/console/datasets/datasets_segments.py 75.23% 25 Missing and 1 partial ⚠️
api/controllers/console/datasets/datasets.py 85.27% 19 Missing and 5 partials ⚠️
api/controllers/console/datasets/data_source.py 80.39% 19 Missing and 1 partial ⚠️
api/repositories/knowledge/document_repository.py 88.33% 13 Missing and 1 partial ⚠️
.../controllers/console/datasets/datasets_document.py 94.95% 8 Missing and 4 partials ⚠️
api/controllers/service_api/dataset/metadata.py 82.92% 6 Missing and 1 partial ⚠️
api/core/rag/retrieval/dataset_retrieval.py 78.57% 3 Missing and 3 partials ⚠️
api/controllers/common/rbac/locators.py 44.44% 5 Missing ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #41729      +/-   ##
==========================================
+ Coverage   88.34%   88.50%   +0.15%     
==========================================
  Files        5137     5183      +46     
  Lines      324705   325983    +1278     
  Branches    65496    65415      -81     
==========================================
+ Hits       286865   288505    +1640     
+ Misses      32454    32186     -268     
+ Partials     5386     5292      -94     
Flag Coverage Δ
api 88.23% <92.50%> (+0.26%) ⬆️
dify-ui 93.72% <ø> (ø)
web 88.79% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Stream29
Stream29 self-requested a review September 28, 2026 03:57
JohnJyong
JohnJyong previously approved these changes Sep 29, 2026
@JohnJyong
JohnJyong added this pull request to the merge queue Sep 29, 2026
Merged via the queue into langgenius:main with commit a67cd87 Sep 29, 2026
85 checks passed
JessYanCoding added a commit to JessYanCoding/dify that referenced this pull request Sep 29, 2026
…e deleted

Rewritten on top of langgenius#41729, which replaced the inline `index_processor.clean(...)`
block in both document-deletion tasks with `clean_document_indexes(document_ids=...)`.
The new adapter derives its node ids from DocumentSegment / DocumentSegmentSummary /
ChildChunk only, so it cannot see segment attachments, and the previous approach of
appending orphan attachment ids to `index_node_ids` no longer has anywhere to go.

Two defects survived the refactor unchanged:

1. Attachment vectors are never removed. They are written under
   `doc_id == UploadFile.id` by `Vector.create_multimodal`, while the node ids the
   cleanup derives come from segments, summaries and child chunks. They therefore
   outlive the document permanently, keep consuming top-k slots and quietly degrade
   recall, and `RetrievalService.get_segment_attachment_infos` drops them silently
   because no row backs them any more.

2. An attachment another document still references is destroyed.
   `SegmentAttachmentBinding.attachment_id` carries no uniqueness constraint, so the
   same `UploadFile` may be bound to segments of several documents. Both tasks deleted
   the row and its blob for every binding the deleted document held. Both also ordered
   the `UploadFile` delete before the binding delete, so the surviving bindings could
   not have been consulted even in principle.

`clean_document_indexes` grows a keyword-only `extra_node_ids` parameter with a default,
so `clean_notion_document_task` is unaffected. Those ids join the vector deletion only:
`body_node_ids` still drives the Jieba keyword index, which never held attachment
vectors. Deciding which attachments are genuinely orphaned stays with the caller,
because that answer depends on bindings outside the documents being cleaned.

Both tasks now compute the orphan set up front, pass it as `extra_node_ids`, delete
bindings before attachment rows, and only delete attachments nothing else references.
In `batch_clean_document_task` the binding deletion moves out of the per-batch loop in
Step 5 into its own Step 3.5 with its own try/except.

Verification on a4f949f (origin/main with langgenius#41729 merged):

- `pytest api/tests/unit_tests/tasks` - 333 passed (327 on main, so +6)
- `pytest api/tests/unit_tests/services/knowledge/test_document_index_cleanup.py` -
  17 passed (14 on main, so +3)
- `pytest api/tests/unit_tests` - 21957 passed. The 33 failures are missing optional
  VDB plugin packages plus `test_zip64_extensible_data_is_not_part_of_central_directory`;
  a clean checkout of the same commit reproduces exactly the same 33 with 21948 passed.
- reverting only the three production files with the tests kept - 7 failed, 5 passed
- `ruff format --check` / `ruff check` - clean
- `lint-imports` - 59 contracts kept, 0 broken
- `pyrefly check` on the changed production files - 0 diagnostics
- `pyrefly --config=tests/unit_tests/pyrefly.toml` on the changed test files - identical
  diagnostic counts before and after, so no new strict-mode debt
- `check_no_new_getattr.py` and `check_no_new_controller_sqlalchemy.py` - both clean
- `api/uv.lock` unchanged

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@WH-2099 WH-2099 self-assigned this Oct 10, 2026
JessYanCoding added a commit to JessYanCoding/dify that referenced this pull request Oct 10, 2026
…e deleted

Rewritten on top of langgenius#41729, which replaced the inline `index_processor.clean(...)`
block in both document-deletion tasks with `clean_document_indexes(document_ids=...)`.
The new adapter derives its node ids from DocumentSegment / DocumentSegmentSummary /
ChildChunk only, so it cannot see segment attachments, and the previous approach of
appending orphan attachment ids to `index_node_ids` no longer has anywhere to go.

Two defects survived the refactor unchanged:

1. Attachment vectors are never removed. They are written under
   `doc_id == UploadFile.id` by `Vector.create_multimodal`, while the node ids the
   cleanup derives come from segments, summaries and child chunks. They therefore
   outlive the document permanently, keep consuming top-k slots and quietly degrade
   recall, and `RetrievalService.get_segment_attachment_infos` drops them silently
   because no row backs them any more.

2. An attachment another document still references is destroyed.
   `SegmentAttachmentBinding.attachment_id` carries no uniqueness constraint, so the
   same `UploadFile` may be bound to segments of several documents. Both tasks deleted
   the row and its blob for every binding the deleted document held. Both also ordered
   the `UploadFile` delete before the binding delete, so the surviving bindings could
   not have been consulted even in principle.

`clean_document_indexes` grows a keyword-only `extra_node_ids` parameter with a default,
so `clean_notion_document_task` is unaffected. Those ids join the vector deletion only:
`body_node_ids` still drives the Jieba keyword index, which never held attachment
vectors. Deciding which attachments are genuinely orphaned stays with the caller,
because that answer depends on bindings outside the documents being cleaned.

Both tasks now compute the orphan set up front, pass it as `extra_node_ids`, delete
bindings before attachment rows, and only delete attachments nothing else references.
In `batch_clean_document_task` the binding deletion moves out of the per-batch loop in
Step 5 into its own Step 3.5 with its own try/except.

Verification on a4f949f (origin/main with langgenius#41729 merged):

- `pytest api/tests/unit_tests/tasks` - 333 passed (327 on main, so +6)
- `pytest api/tests/unit_tests/services/knowledge/test_document_index_cleanup.py` -
  17 passed (14 on main, so +3)
- `pytest api/tests/unit_tests` - 21957 passed. The 33 failures are missing optional
  VDB plugin packages plus `test_zip64_extensible_data_is_not_part_of_central_directory`;
  a clean checkout of the same commit reproduces exactly the same 33 with 21948 passed.
- reverting only the three production files with the tests kept - 7 failed, 5 passed
- `ruff format --check` / `ruff check` - clean
- `lint-imports` - 59 contracts kept, 0 broken
- `pyrefly check` on the changed production files - 0 diagnostics
- `pyrefly --config=tests/unit_tests/pyrefly.toml` on the changed test files - identical
  diagnostic counts before and after, so no new strict-mode debt
- `check_no_new_getattr.py` and `check_no_new_controller_sqlalchemy.py` - both clean
- `api/uv.lock` unchanged

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
JessYanCoding added a commit to JessYanCoding/dify that referenced this pull request Oct 10, 2026
…tryably

Addresses review on langgenius#42642. Both document-deletion tasks now call one new
function, `release_document_attachments` in
services/knowledge/indexing/adapters/cleanup.py, instead of handling
attachments inline:

- Attachments are discovered through their bindings (`document_id IN ...`)
  rather than through segments, so a release that failed is picked up by a
  later run even after the segments have been deleted.
- Two scopes are decided separately. The vector lives in this dataset's
  collection and is deleted once no other binding in this dataset remains;
  the UploadFile row and blob are shared and go only once no binding
  anywhere remains.
- Each attachment is locked (acquired in sorted id order) while its
  remaining references are counted and released, and the binding deletion
  commits before the lock is released, so concurrent deletions of documents
  sharing an attachment cannot each see the other's binding and both keep it.
- Vectors are deleted before bindings, so a failed vector deletion leaves the
  bindings in place for the next attempt.

A Redis lock is used rather than SELECT ... FOR UPDATE because the vector
deletion in between is external I/O, which langgenius#41729 keeps outside database
transactions. The `extra_node_ids` parameter the previous revision added to
`clean_document_indexes` is reverted, since the orphan decision now has to be
made under the lock. All code comments are in English.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
xhdnoah added a commit to xhdnoah/dify that referenced this pull request Oct 28, 2026
Remove the include_own_datasets parameter and the conditional gate so
that maintainers always retain visibility of their own datasets when
RBAC is enabled, matching the main branch behavior.

The LTS branch predates the dataset application boundary refactor
(langgenius#41729, 2026-09-29) that introduced api/services/knowledge/datasets/.
The same logic is applied to the pre-refactor files instead.

Source commits on main:
- 4c830e8 (fix: fix list dataset not include own)
- e1278ec (chore: remove include_own_datasets param)
xhdnoah added a commit to xhdnoah/dify that referenced this pull request Oct 28, 2026
Remove the include_own_datasets parameter and the conditional gate so
that maintainers always retain visibility of their own datasets when
RBAC is enabled, matching the main branch behavior.

The LTS branch predates the dataset application boundary refactor
(langgenius#41729, 2026-09-29) that introduced api/services/knowledge/datasets/.
The same logic is applied to the pre-refactor files instead.

(cherry picked from commit a394d04)
xhdnoah added a commit to xhdnoah/dify that referenced this pull request Oct 28, 2026
Remove the include_own_datasets parameter and the conditional gate so
that maintainers always retain visibility of their own datasets when
RBAC is enabled, matching the main branch behavior.

The LTS branch predates the dataset application boundary refactor
(langgenius#41729, 2026-09-29) that introduced api/services/knowledge/datasets/.
The same logic is applied to the pre-refactor files instead.

Add two tests verifying that a maintainer can see their own dataset
even when accessible_dataset_ids is empty, mirroring the maintainer
visibility test added in the main branch PR.

(cherry picked from commit a394d04)
xhdnoah added a commit to xhdnoah/dify that referenced this pull request Oct 28, 2026
Remove the include_own_datasets parameter and the conditional gate so
that maintainers always retain visibility of their own datasets when
RBAC is enabled, matching the main branch behavior.

The LTS branch predates the dataset application boundary refactor
(langgenius#41729, 2026-09-29) that introduced api/services/knowledge/datasets/.
The same logic is applied to the pre-refactor files instead.

(cherry picked from commit a394d04)
xhdnoah added a commit to xhdnoah/dify that referenced this pull request Oct 28, 2026
Remove the include_own_datasets parameter and the conditional gate so
that maintainers always retain visibility of their own datasets when
RBAC is enabled, matching the main branch behavior.

The LTS branch predates the dataset application boundary refactor
(langgenius#41729, 2026-09-29) that introduced api/services/knowledge/datasets/.
The same logic is applied to the pre-refactor files instead.

The main branch PR added a maintainer-visibility test with an empty
accessible_dataset_ids list (test_list_visibility_restricts_even_requested_ids
in test_adapters.py, introduced by langgenius#44605 on 2026-10-23). LTS forked
on 2026-09-10 and never received that test. Add two equivalent tests
to test_dataset_service_dataset.py covering the boundary scenario
where accessible_dataset_ids is empty but the maintainer should still
see their own dataset — this is the exact regression that langgenius#44795
fixes and the LTS existing tests only cover the non-empty case.

(cherry picked from commit a394d04)
xhdnoah added a commit that referenced this pull request Oct 28, 2026
Remove the include_own_datasets parameter and the conditional gate so
that maintainers always retain visibility of their own datasets when
RBAC is enabled, matching the main branch behavior.

The LTS branch predates the dataset application boundary refactor
(#41729, 2026-09-29) that introduced api/services/knowledge/datasets/.
The same logic is applied to the pre-refactor files instead.

The main branch PR added a maintainer-visibility test with an empty
accessible_dataset_ids list (test_list_visibility_restricts_even_requested_ids
in test_adapters.py, introduced by #44605 on 2026-10-23). LTS forked
on 2026-09-10 and never received that test. Add two equivalent tests
to test_dataset_service_dataset.py covering the boundary scenario
where accessible_dataset_ids is empty but the maintainer should still
see their own dataset — this is the exact regression that #44795
fixes and the LTS existing tests only cover the non-empty case.

(cherry picked from commit a394d04)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants