Skip to content

fix(agent): complete Agent deletion lifecycle - #40888

Open
BeautyyuYanli wants to merge 2 commits into
mainfrom
lody/45ef1a2a-634
Open

fix(agent): complete Agent deletion lifecycle#40888
BeautyyuYanli wants to merge 2 commits into
mainfrom
lody/45ef1a2a-634

Conversation

@BeautyyuYanli

Copy link
Copy Markdown
Contributor

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

  • Complete Agent deletion as a two-phase lifecycle: retire working resources first, then hard-delete the Agent aggregate only after every explicit external resource is collected successfully.
  • Reject direct deletion with HTTP 409 while a normal App's current draft or published Workflow still effectively references the Agent.
  • Treat RETIRED as the sole Home Snapshot deletion condition; Draft and Config Snapshot pointers are historical references and no longer defer physical collection.
  • Attempt every Workspace, Binding, and Home Snapshot in a collection batch, aggregate failures in input order, fail the Celery task, and skip aggregate purge when any resource fails.
  • Propagate Celery publication, workflow-only retirement, Workspace lifecycle invariant, external collection, and aggregate purge failures instead of logging them as success.
  • Hard-delete Agent-owned Drafts, Config Snapshots, Config Revisions, debug-conversation mappings, resource ledgers, stale Workflow Agent bindings, and the archived Agent in one database transaction.
  • Preserve ownership boundaries for Workspaces, Apps, Workflows, Conversations, Datasets, Credentials, and Files, and document the lifecycle and current lack of automatic retry or reconciliation.

Issue: N/A — scoped completion of retired Agent resource collection and aggregate deletion.

Root cause

Product deletion archived an Agent and retired external working resources, but it never deleted the Agent, its Drafts, Config Snapshots, Config Revisions, or aggregate ledgers. Home collection also treated Draft and Config Snapshot home_snapshot_id pointers as liveness references, so a logically deleted Home could remain deferred indefinitely.

The cleanup path had several false-success boundaries: the Celery task stopped at the first collector failure, publication failures were only logged, a retired Workspace without a retired Binding returned successfully, and workflow-only retirement failures were converted into empty results. These behaviors made incomplete deletion difficult to observe and prevented one request from reaching a deterministic terminal result.

Impact

Deletion now locks and archives the Agent, retires the resources owned by the deleting product path, and enqueues one explicit collection batch. Independent resources all receive one collection attempt. Any failure is logged with tenant and resource context, summarized into a raised error, and leaves the Agent aggregate available for retry or later GC.

After all external collection succeeds, Dify API locks the archived Agent again, rechecks active resource and effective Workflow ownership invariants, and deletes the complete Agent-owned aggregate atomically. Missing resources or Agents remain idempotent no-ops. Shared business objects and Workflow-owned records outside stale Agent bindings are not cascaded.

A RETIRED Home Snapshot is physically collectable even while historical configuration rows still point to it. Those configuration rows are removed with the Agent aggregate after external collection finishes.

This PR does not add Celery autoretry, periodic GC, reconciliation, a new cleanup-state model, or a database migration.

Validation

  • Rebased onto current origin/main (bec38906) without conflicts.
  • Final post-rebase affected API suite: 643 passed, 2 existing dependency deprecation warnings.
  • Focused Ruff F checks and compile checks passed during implementation.
  • Changed production-file Pyrefly checks completed with 0 diagnostics.
  • Dify Agent documentation build passed.
  • git diff --check passed.
  • All five staged implementation reviews passed after scoped rework.

The full backend suite and CI-only integration suite were not run locally. The repository's default Ruff configuration includes RUF101, which the installed Ruff version does not recognize, so focused Ruff F checks were used instead.

Screenshots

Before After
N/A — backend lifecycle, task behavior, tests, and documentation only. N/A — backend lifecycle, task behavior, tests, and documentation only.

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

This PR is made with gpt-5.6-sol (codex), while I'm responsible for all the changes.

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Aug 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 59.25% 59.30% +0.06%
Strict coverage 58.83% 58.88% +0.06%
Typed symbols 39,551 39,643 +92
Untyped symbols 27,398 27,398 0
Modules 3172 3174 +2

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-08-17 12:01:28.263415526 +0000
+++ /tmp/pyrefly_pr.txt	2026-08-17 12:01:19.096357264 +0000
@@ -1825,27 +1825,27 @@
 ERROR No attribute `MethodView` in module `builtins` [missing-attribute]
  --> tests/unit_tests/controllers/common/test_fields.py:8:5
 ERROR `in` is not supported between `Literal['Incorrect API key provided']` and `None` [not-iterable]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1644:12
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1682:12
 ERROR Argument `test_drain_streaming_generate_response_returns_on_message_end.ClosableResponse` is not assignable to parameter `response` with type `Generator[str] | RateLimitGenerator` in function `controllers.console.app.completion._drain_streaming_generate_response` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1767:69
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1805:69
 ERROR Argument `Iterator[Any]` is not assignable to parameter `response` with type `Generator[str] | RateLimitGenerator` in function `controllers.console.app.completion._drain_streaming_generate_response` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1774:66
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1812:66
 ERROR Argument `Iterator[Any]` is not assignable to parameter `response` with type `Generator[str] | RateLimitGenerator` in function `controllers.console.app.completion._drain_streaming_generate_response` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1780:66
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1818:66
 ERROR Object of class `object` has no attribute `data` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2192:50
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2230:50
 ERROR Object of class `object` has no attribute `limit` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2193:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2231:30
 ERROR Object of class `object` has no attribute `has_more` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2194:33
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2232:33
 ERROR Object of class `object` has no attribute `data` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2231:50
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2269:50
 ERROR Object of class `object` has no attribute `limit` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2232:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2270:30
 ERROR Object of class `object` has no attribute `has_more` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2233:33
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2271:33
 ERROR Argument `Literal['00000000-0000-0000-0000-000000000002']` is not assignable to parameter `message_id` with type `UUID` in function `controllers.console.app.message._get_message_suggested_questions` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2330:24
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2368:24
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.agent_config_inspector._resolve_agent_id` [bad-argument-type]
   --> tests/unit_tests/controllers/console/app/test_agent_config_inspector.py:54:51
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.agent_drive_inspector._resolve_agent_id` [bad-argument-type]
@@ -6957,63 +6957,67 @@
 ERROR Argument `list[SimpleNamespace]` is not assignable to parameter `feedbacks` with type `Sequence[MessageFeedback]` in function `services.agent.observability_service.AgentObservabilityService.serialize_log_message` [bad-argument-type]
    --> tests/unit_tests/services/agent/test_agent_observability_service.py:632:9
 ERROR Argument `SimpleNamespace` is not assignable to parameter `binding` with type `WorkflowAgentNodeBinding` in function `services.agent.composer_service.AgentComposerService._workflow_inline_debug_conversation_id` [bad-argument-type]
-   --> tests/unit_tests/services/agent/test_agent_services.py:402:17
+   --> tests/unit_tests/services/agent/test_agent_services.py:404:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `agent` with type `Agent | None` in function `services.agent.composer_service.AgentComposerService._workflow_inline_debug_conversation_id` [bad-argument-type]
-   --> tests/unit_tests/services/agent/test_agent_services.py:403:15
+   --> tests/unit_tests/services/agent/test_agent_services.py:405:15
 ERROR Argument `SimpleNamespace` is not assignable to parameter `binding` with type `WorkflowAgentNodeBinding` in function `services.agent.composer_service.AgentComposerService._workflow_inline_debug_conversation_id` [bad-argument-type]
-   --> tests/unit_tests/services/agent/test_agent_services.py:429:21
+   --> tests/unit_tests/services/agent/test_agent_services.py:431:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `agent` with type `Agent | None` in function `services.agent.composer_service.AgentComposerService._workflow_inline_debug_conversation_id` [bad-argument-type]
-   --> tests/unit_tests/services/agent/test_agent_services.py:430:19
+   --> tests/unit_tests/services/agent/test_agent_services.py:432:19
 ERROR Argument `SimpleNamespace` is not assignable to parameter `binding` with type `WorkflowAgentNodeBinding` in function `services.agent.composer_service.AgentComposerService._workflow_inline_debug_conversation_id` [bad-argument-type]
-   --> tests/unit_tests/services/agent/test_agent_services.py:439:21
+   --> tests/unit_tests/services/agent/test_agent_services.py:441:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `agent` with type `Agent | None` in function `services.agent.composer_service.AgentComposerService._workflow_inline_debug_conversation_id` [bad-argument-type]
-   --> tests/unit_tests/services/agent/test_agent_services.py:440:19
+   --> tests/unit_tests/services/agent/test_agent_services.py:442:19
 ERROR Object of class `NoneType` has no attribute `agent_workspace_binding_id` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:1310:12
+    --> tests/unit_tests/services/agent/test_agent_services.py:1315:12
 ERROR Object of class `object` has no attribute `prompt` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2760:12
+    --> tests/unit_tests/services/agent/test_agent_services.py:2765:12
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2950:12
+    --> tests/unit_tests/services/agent/test_agent_services.py:2955:12
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2951:12
+    --> tests/unit_tests/services/agent/test_agent_services.py:2956:12
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2952:12
+    --> tests/unit_tests/services/agent/test_agent_services.py:2957:12
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2954:12
+    --> tests/unit_tests/services/agent/test_agent_services.py:2959:12
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/services/agent/test_agent_services.py:2955:12
+    --> tests/unit_tests/services/agent/test_agent_services.py:2960:12
 ERROR Argument `list[str | None]` is not assignable to parameter `version_ids` with type `list[str]` in function `services.agent.roster_service.AgentRosterService._load_versions_by_id` [bad-argument-type]
-    --> tests/unit_tests/services/agent/test_agent_services.py:4284:52
+    --> tests/unit_tests/services/agent/test_agent_services.py:4364:52
 ERROR Object of class `NoneType` has no attribute `conversation_id` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5177:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5257:16
 ERROR Object of class `object` has no attribute `name` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5394:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5474:16
 ERROR Object of class `object` has no attribute `mode` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5395:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5475:16
 ERROR Object of class `object` has no attribute `agent_role` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5396:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5476:16
 ERROR Object of class `object` has no attribute `config_snapshot` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5406:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5486:16
 ERROR Object of class `object` has no attribute `home_snapshot_id` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5408:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5488:16
 ERROR Object of class `object` has no attribute `summary` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5409:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5489:16
 ERROR Object of class `object` has no attribute `version_note` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5410:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5490:16
 ERROR Object of class `object` has no attribute `active_config_has_model` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5411:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5491:16
 ERROR Object of class `object` has no attribute `active_config_is_published` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5412:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5492:16
 ERROR Object of class `object` has no attribute `updated_by` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5413:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5493:16
 ERROR Object of class `object` has no attribute `id` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5414:35
+    --> tests/unit_tests/services/agent/test_agent_services.py:5494:35
 ERROR Object of class `object` has no attribute `agent_role` [missing-attribute]
-    --> tests/unit_tests/services/agent/test_agent_services.py:5479:16
+    --> tests/unit_tests/services/agent/test_agent_services.py:5559:16
 ERROR Cannot set item in `dict[str, str]` [unsupported-operation]
-    --> tests/unit_tests/services/agent/test_agent_services.py:7256:31
+    --> tests/unit_tests/services/agent/test_agent_services.py:7336:31
 ERROR Object of class `NoneType` has no attribute `workflow_prompt` [missing-attribute]
    --> tests/unit_tests/services/agent/test_composer_mention_validation.py:113:5
+ERROR Object of class `Join` has no attribute `name` [missing-attribute]
+   --> tests/unit_tests/services/agent/test_deletion_service.py:230:35
+ERROR Object of class `FromClause` has no attribute `name` [missing-attribute]
+   --> tests/unit_tests/services/agent/test_deletion_service.py:242:9
 ERROR Argument `object` is not assignable to parameter `pwd` with type `bytes | None` in function `zipfile.ZipFile.read` [bad-argument-type]
    --> tests/unit_tests/services/agent/test_skill_package_service.py:258:44
 ERROR Class member `ConcreteApiKeyAuth.validate_credentials` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
@@ -7035,31 +7039,31 @@
 ERROR Object of class `Flask` has no attribute `login_manager` [missing-attribute]
    --> tests/unit_tests/services/controller_api.py:829:9
 ERROR Class member `StubResolver.resolve` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:252:13
+   --> tests/unit_tests/services/data_migration/test_import_service.py:255:13
 ERROR Class member `CapturingImportService._import_workflows` overrides parent class `MigrationImportService` in an inconsistent manner [bad-override]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:261:13
+   --> tests/unit_tests/services/data_migration/test_import_service.py:264:13
 ERROR Class member `CapturingImportService._import_workflows` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:261:13
+   --> tests/unit_tests/services/data_migration/test_import_service.py:264:13
 ERROR Argument `object` is not assignable to parameter `account` with type `Account` in function `services.data_migration.import_service.MigrationImportService._import_workflow_app` [bad-argument-type]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:356:21
+   --> tests/unit_tests/services/data_migration/test_import_service.py:359:21
 ERROR Class member `PublishingImportService._ensure_workflow_app_is_published` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:462:13
+   --> tests/unit_tests/services/data_migration/test_import_service.py:465:13
 ERROR Class member `StrategyImportService._ensure_workflow_app_is_published` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:507:13
+   --> tests/unit_tests/services/data_migration/test_import_service.py:547:13
 ERROR Class member `SkipImportService._ensure_workflow_app_is_published` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:557:13
+   --> tests/unit_tests/services/data_migration/test_import_service.py:597:13
 ERROR Class member `StubResolver.resolve` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:952:13
+   --> tests/unit_tests/services/data_migration/test_import_service.py:992:13
 ERROR Class member `OrderedImportService._import_api_tools` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:961:13
+    --> tests/unit_tests/services/data_migration/test_import_service.py:1001:13
 ERROR Class member `OrderedImportService._import_workflows` overrides parent class `MigrationImportService` in an inconsistent manner [bad-override]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:975:13
+    --> tests/unit_tests/services/data_migration/test_import_service.py:1015:13
 ERROR Class member `OrderedImportService._import_workflows` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/services/data_migration/test_import_service.py:975:13
+    --> tests/unit_tests/services/data_migration/test_import_service.py:1015:13
 ERROR Class member `OrderedImportService._import_workflow_tools` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/services/data_migration/test_import_service.py:1002:13
+    --> tests/unit_tests/services/data_migration/test_import_service.py:1042:13
 ERROR Class member `OrderedImportService._import_mcp_tools` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/services/data_migration/test_import_service.py:1007:13
+    --> tests/unit_tests/services/data_migration/test_import_service.py:1047:13
 ERROR Argument `Literal['opendal']` is not assignable to parameter `storage_type` with type `StorageType` in function `models.model.UploadFile.__init__` [bad-argument-type]
    --> tests/unit_tests/services/dataset_service_test_helpers.py:251: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]
@@ -7340,6 +7344,8 @@
   --> tests/unit_tests/services/test_api_token_service.py:29:9
 ERROR Argument `Literal['app']` is not assignable to parameter `value` with type `ApiTokenType | SQLCoreOperations[ApiTokenType]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
   --> tests/unit_tests/services/test_api_token_service.py:44:26
+ERROR Argument `SimpleNamespace` is not assignable to parameter `session` with type `Session` in function `services.app_dsl_service.AppDslService.__init__` [bad-argument-type]
+   --> tests/unit_tests/services/test_app_dsl_service.py:306:37
 ERROR Class member `_TrackingRateLimit.exit` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
    --> tests/unit_tests/services/test_app_generate_service.py:574:17
 ERROR Class member `_TrackingRateLimit.exit` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
@@ -7351,9 +7357,11 @@
 ERROR Argument `_FakeRedisClient` is not assignable to parameter `redis_client` with type `Redis[Unknown] | RedisCluster[Unknown]` in function `libs.broadcast_channel.redis.pubsub_channel.BroadcastChannel.__init__` [bad-argument-type]
    --> tests/unit_tests/services/test_app_generate_service_streaming_integration.py:116:34
 ERROR Argument `str | None` is not assignable to parameter `tenant_id` with type `str` in function `services.app_service.AppService.create_app` [bad-argument-type]
-   --> tests/unit_tests/services/test_app_service.py:118:17
+   --> tests/unit_tests/services/test_app_service.py:131:17
 ERROR Argument `str | None` is not assignable to parameter `tenant_id` with type `str` in function `services.app_service.AppService.create_app` [bad-argument-type]
-   --> tests/unit_tests/services/test_app_service.py:181:17
+   --> tests/unit_tests/services/test_app_service.py:194:17
+ERROR Argument `SimpleNamespace` is not assignable to parameter `app` with type `App` in function `services.app_service.AppService._get_backing_agent_for_update` [bad-argument-type]
+   --> tests/unit_tests/services/test_app_service.py:513:50
 ERROR Argument `TestAsyncWorkflowService.test_should_dispatch_to_matching_celery_task_when_triggering_workflow.DummyAccount` is not assignable to parameter `user` with type `Account | EndUser` in function `services.async_workflow_service.AsyncWorkflowService.trigger_workflow_async` [bad-argument-type]
    --> tests/unit_tests/services/test_async_workflow_service.py:191:46
 ERROR Argument `SimpleNamespace` is not assignable to parameter `user` with type `Account | EndUser` in function `services.async_workflow_service.AsyncWorkflowService.trigger_workflow_async` [bad-argument-type]
@@ -7671,33 +7679,33 @@
 ERROR Argument `SimpleNamespace` is not assignable to parameter `session` with type `Session` in function `services.snippet_dsl_service.SnippetDslService.__init__` [bad-argument-type]
    --> tests/unit_tests/services/test_snippet_dsl_service.py:527:41
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet | None` in function `services.snippet_dsl_service.SnippetDslService._create_or_update_snippet` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:544:17
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:550:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_dsl_service.SnippetDslService._create_or_update_snippet` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:555:17
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:561:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `session` with type `Session` in function `services.snippet_dsl_service.SnippetDslService.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:568:41
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:580:41
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_dsl_service.SnippetDslService._create_or_update_snippet` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:591:17
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:603:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `session` with type `Session` in function `services.snippet_dsl_service.SnippetDslService.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:603:41
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:615:41
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_dsl_service.SnippetDslService.export_snippet_dsl` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:610:36
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:622:36
 ERROR Argument `SimpleNamespace` is not assignable to parameter `session` with type `Session` in function `services.snippet_dsl_service.SnippetDslService.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:614:41
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:626:41
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_dsl_service.SnippetDslService.export_snippet_dsl` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:636:41
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:648:41
 ERROR Argument `SimpleNamespace` is not assignable to parameter `session` with type `Session` in function `services.snippet_dsl_service.SnippetDslService.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:644:41
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:656:41
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_dsl_service.SnippetDslService._append_workflow_export_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:689:17
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:701:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow` with type `Workflow` in function `services.snippet_dsl_service.SnippetDslService._append_workflow_export_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:690:18
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:702:18
 ERROR Argument `SimpleNamespace` is not assignable to parameter `session` with type `Session` in function `services.snippet_dsl_service.SnippetDslService.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:702:41
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:714:41
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_dsl_service.SnippetDslService._append_workflow_export_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:729:17
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:741:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow` with type `Workflow` in function `services.snippet_dsl_service.SnippetDslService._append_workflow_export_data` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_dsl_service.py:730:18
+   --> tests/unit_tests/services/test_snippet_dsl_service.py:742:18
 ERROR Argument `Iterator[Any]` is not assignable to parameter `response` with type `Generator[Mapping[str, Any] | str] | Mapping[str, Any]` in function `services.snippet_generate_service.SnippetGenerateService._filter_virtual_start_events` [bad-argument-type]
   --> tests/unit_tests/services/test_snippet_generate_service.py:50:68
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_generate_service.SnippetGenerateService._ensure_start_node` [bad-argument-type]
@@ -7755,81 +7763,79 @@
 ERROR Argument `Literal['service-api']` is not assignable to parameter `invoke_from` with type `InvokeFrom` in function `services.snippet_generate_service.SnippetGenerateService.run_published` [bad-argument-type]
    --> tests/unit_tests/services/test_snippet_generate_service.py:400:25
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.create_snippet` [bad-argument-type]
-  --> tests/unit_tests/services/test_snippet_service.py:76:17
+  --> tests/unit_tests/services/test_snippet_service.py:83:17
 ERROR Object of class `NoneType` has no attribute `name` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:177:12
+   --> tests/unit_tests/services/test_snippet_service.py:184:12
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.sync_draft_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:217:17
+   --> tests/unit_tests/services/test_snippet_service.py:234:17
 ERROR Argument `str | None` is not assignable to parameter `s` with type `bytearray | bytes | str` in function `json.loads` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:223:23
+   --> tests/unit_tests/services/test_snippet_service.py:240:23
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.sync_draft_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:240:21
+   --> tests/unit_tests/services/test_snippet_service.py:263:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.sync_draft_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:243:21
+   --> tests/unit_tests/services/test_snippet_service.py:266:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.sync_draft_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:268:17
+   --> tests/unit_tests/services/test_snippet_service.py:291:17
 ERROR Argument `str | None` is not assignable to parameter `s` with type `bytearray | bytes | str` in function `json.loads` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:279:23
+   --> tests/unit_tests/services/test_snippet_service.py:302:23
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.update_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:302:17
+   --> tests/unit_tests/services/test_snippet_service.py:325:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.update_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:321:17
+   --> tests/unit_tests/services/test_snippet_service.py:344:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.update_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:323:17
+   --> tests/unit_tests/services/test_snippet_service.py:346:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.restore_published_workflow_to_draft` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:401:17
+   --> tests/unit_tests/services/test_snippet_service.py:434:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.restore_published_workflow_to_draft` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:426:21
+   --> tests/unit_tests/services/test_snippet_service.py:465:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.restore_published_workflow_to_draft` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:428:21
+   --> tests/unit_tests/services/test_snippet_service.py:467:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.restore_published_workflow_to_draft` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:463:17
+   --> tests/unit_tests/services/test_snippet_service.py:502:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_published_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:474:45
+   --> tests/unit_tests/services/test_snippet_service.py:513:45
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_published_workflow_by_id` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:491:21
+   --> tests/unit_tests/services/test_snippet_service.py:530:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.publish_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:502:21
+   --> tests/unit_tests/services/test_snippet_service.py:541:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.publish_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:503:21
+   --> tests/unit_tests/services/test_snippet_service.py:542:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `account` with type `Account` in function `services.snippet_service.SnippetService.publish_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:540:17
+   --> tests/unit_tests/services/test_snippet_service.py:579:17
 ERROR Object of class `NoneType` has no attribute `workflow_id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:550:12
+   --> tests/unit_tests/services/test_snippet_service.py:589:12
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_all_published_workflows` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:559:17
+   --> tests/unit_tests/services/test_snippet_service.py:598:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_all_published_workflows` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:583:17
-ERROR Object of class `NoneType` has no attribute `status` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:646:12
+   --> tests/unit_tests/services/test_snippet_service.py:622:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService._delete_archived_workflow_run_files` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:715:64
+   --> tests/unit_tests/services/test_snippet_service.py:832:64
 ERROR `SimpleNamespace` is not assignable to attribute `_workflow_run_repo` with type `APIWorkflowRunRepository` [bad-assignment]
-   --> tests/unit_tests/services/test_snippet_service.py:731:34
+   --> tests/unit_tests/services/test_snippet_service.py:848:34
 ERROR `SimpleNamespace` is not assignable to attribute `_node_execution_service_repo` with type `DifyAPIWorkflowNodeExecutionRepository` [bad-assignment]
-   --> tests/unit_tests/services/test_snippet_service.py:732:44
+   --> tests/unit_tests/services/test_snippet_service.py:849:44
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_snippet_workflow_runs` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:738:54
+   --> tests/unit_tests/services/test_snippet_service.py:855:54
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:739:12
+   --> tests/unit_tests/services/test_snippet_service.py:856:12
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_snippet_workflow_run` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:739:53
+   --> tests/unit_tests/services/test_snippet_service.py:856:53
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_snippet_workflow_run_node_executions` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:740:69
+   --> tests/unit_tests/services/test_snippet_service.py:857:69
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:742:9
+   --> tests/unit_tests/services/test_snippet_service.py:859:9
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_snippet_node_last_run` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:743:21
+   --> tests/unit_tests/services/test_snippet_service.py:860:21
 ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow` with type `Workflow` in function `services.snippet_service.SnippetService.get_snippet_node_last_run` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:744:22
+   --> tests/unit_tests/services/test_snippet_service.py:861:22
 ERROR `SimpleNamespace` is not assignable to attribute `_node_execution_service_repo` with type `DifyAPIWorkflowNodeExecutionRepository` [bad-assignment]
-   --> tests/unit_tests/services/test_snippet_service.py:773:44
+   --> tests/unit_tests/services/test_snippet_service.py:890:44
 ERROR Argument `SimpleNamespace` is not assignable to parameter `snippet` with type `CustomizedSnippet` in function `services.snippet_service.SnippetService.get_snippet_workflow_run_node_executions` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_service.py:777:17
+   --> tests/unit_tests/services/test_snippet_service.py:894:17
 ERROR Object of class `FunctionType` has no attribute `assert_not_called` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:782:5
+   --> tests/unit_tests/services/test_snippet_service.py:899:5
 ERROR Object of class `NoneType` has no attribute `use_count` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:795:12
+   --> tests/unit_tests/services/test_snippet_service.py:912:12
 ERROR Class member `_RaceInsertSession.flush` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/unit_tests/services/test_step_by_step_tour_service.py:58:9
 ERROR Class member `_RaceInsertSession.rollback` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
@@ -7969,11 +7975,11 @@
 ERROR `dict[str, str]` is not assignable to dict value type `list[Unknown] | str` [bad-assignment]
    --> tests/unit_tests/services/test_workflow_service.py:193:30
 ERROR `dict[@_, @_]` is not assignable to TypedDict key `data` with type `BaseNodeData` [bad-assignment]
-    --> tests/unit_tests/services/test_workflow_service.py:3302:54
+    --> tests/unit_tests/services/test_workflow_service.py:3336:54
 ERROR Argument `Literal['invalid']` is not assignable to parameter `value` with type `AppMode | SQLCoreOperations[AppMode]` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
-    --> tests/unit_tests/services/test_workflow_service.py:3348:20
+    --> tests/unit_tests/services/test_workflow_service.py:3382:20
 ERROR Argument `dict[str, str | dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.workflow_service.WorkflowService._build_human_input_node_for_debugging` [bad-argument-type]
-    --> tests/unit_tests/services/test_workflow_service.py:3379:65
+    --> tests/unit_tests/services/test_workflow_service.py:3413:65
 ERROR Object of class `MCPToolProvider` has no attribute `provider_icon` [missing-attribute]
   --> tests/unit_tests/services/tools/test_mcp_tools_transform.py:71:5
 ERROR Object of class `MCPToolProvider` has no attribute `masked_server_url` [missing-attribute]

@github-actions github-actions Bot added the web This relates to changes on the web. label Aug 17, 2026
@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.95028% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.82%. Comparing base (e3ab88f) to head (d4719e4).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
api/services/agent/workflow_publish_service.py 74.28% 5 Missing and 4 partials ⚠️
api/services/agent/workspace_service.py 86.36% 1 Missing and 2 partials ⚠️
api/services/app_service.py 72.72% 3 Missing ⚠️
api/services/snippet_service.py 90.00% 0 Missing and 2 partials ⚠️
api/services/agent/home_snapshot_service.py 66.66% 0 Missing and 1 partial ⚠️
api/services/agent/retirement_service.py 87.50% 0 Missing and 1 partial ⚠️
api/services/agent/roster_service.py 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #40888      +/-   ##
==========================================
+ Coverage   86.76%   86.82%   +0.06%     
==========================================
  Files        5205     5363     +158     
  Lines      292589   296829    +4240     
  Branches    58198    59326    +1128     
==========================================
+ Hits       253859   257720    +3861     
- Misses      33728    34099     +371     
- Partials     5002     5010       +8     
Flag Coverage Δ
api 86.83% <88.95%> (+0.04%) ⬆️
cli 89.33% <ø> (?)
dify-ui 93.45% <ø> (ø)
web 86.67% <ø> (-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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 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.

1 participant