App deletion can commit even when cleanup delivery fails
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
main @ 682819150e13
Cloud or Self Hosted
Self Hosted (Source)
Steps to reproduce
On current main (682819150e13), with a Roster Agent and its backing App in a test workspace:
- Send
DELETE /console/api/agent/{agent_id}. - Make
remove_app_and_related_data_task.delayraise a broker connection error. - Observe HTTP 500. Query the database: the App row is gone and the Agent is archived. Retry the same DELETE request; it returns 404.
I reproduced this with the existing controller test harness and a publisher that raises RuntimeError("broker unavailable"). The path is AppLifecycleGateway.delete_agent (transaction commit), followed by AgentAppDeletionService.delete -> AppLifecycleGateway.deleted -> AppService.notify_deleted_app.
✔️ Expected Behavior
Once deletion commits, the cleanup request should remain durably recorded and be delivered/retried after a transient broker outage. A failed publication should not leave a deleted App with no recoverable cleanup request and a client-facing 500 that cannot be retried.
❌ Actual Behavior
The App deletion transaction commits before Celery publication. When .delay raises, the API returns 500 although the App is already deleted. Retrying returns 404, and the remaining cleanup steps after remove_app_and_related_data_task.delay are skipped. The cleanup task's retry policy cannot help because no task was accepted by the broker. The Agent ownership lifecycle PR #40888 explicitly scoped out an outbox; this report covers the resulting unrecoverable producer-side publish failure.
This also appears to affect ordinary App deletion, not just Roster Agents: ConsoleAppService.delete() uses the same commit-then-notify sequence, and AppLifecycleGateway.delete() exits its transaction before notify_deleted_app() runs. A regression test should cover both entry points. [1] [2] [3]
The recovery scope is broader than the first Celery task. When that publication raises, it also prevents workflow-only Agent retirement, Agent resource collection/purge, and the subsequent web-app-auth cleanup from running. The collector call carries workspace, binding, home-snapshot and backing-Agent IDs from the deletion result. [4]
That suggests a durable recovery mechanism needs to preserve the complete deletion cleanup intent, not just retry remove_app_and_related_data_task. A useful acceptance test would restore broker availability after the injected failure and verify that all downstream cleanup is eventually dispatched without requiring the deleted App to resolve through DELETE again. [4]
To reply, just mention @dosu.
Docs are dead. Just use Dosu.