dify icon indicating copy to clipboard operation
dify copied to clipboard

Expired conversation cleanup leaves Agent workspaces active

Open mikamikasuki opened this issue 3 weeks ago • 1 comments

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 at 3d364804fca9db45690e42d8e49b7cb90f4bbedf

Cloud or Self Hosted

Cloud

Steps to reproduce

  1. Create an Agent conversation that owns an active Agent workspace and binding.
  2. Reproduce either retention path:
    • For a free-plan tenant, age the conversation's updated_at beyond the retention period and run ClearFreePlanTenantExpiredLogs.process_tenant(...).
    • Enable WORKFLOW_LOG_CLEANUP_ENABLED, make the associated workflow run older than its retention cutoff, and run clean_workflow_runlogs_precise().
  3. Inspect agent_workspaces and agent_workspace_bindings for the conversation owner.

Focused SQLite service tests reproduce both paths on main at 3d364804: the conversation is deleted while its workspace and binding remain ACTIVE.

✔️ Expected Behavior

Both cleanup paths should retire all conversation-owned workspaces and bindings in the same transaction that removes the conversation, then enqueue resource collection after commit.

❌ Actual Behavior

Both cleanup paths delete the conversation without retiring its Agent workspace or bindings. These resources have no cascading foreign key to the conversation, so they remain ACTIVE and their backend resources are not collected.

mikamikasuki avatar Nov 13 '26 12:11 mikamikasuki

The existing lifecycle helper gives maintainers a reuse point here: AgentWorkspaceRepository.retire_all_for_conversation(...) retires all ACTIVE workspaces scoped to the tenant, app and conversation, including Chatflow node workspaces, and retires each workspace’s ACTIVE bindings in the caller’s transaction. It does not rely solely on conversation.agent_workspace_binding_id. [1]

At the reported commit, the retention loop bypasses that helper and directly bulk-deletes conversations. Normal conversation retirement instead performs workspace retirement within the lifecycle transaction, with resource collection dispatched after commit. [2] [3] [4]

Simply enqueueing the surviving workspace IDs would not repair this: collect_retired_workspace() selects only RETIRED workspaces and returns without action for ACTIVE ones. The retention path needs the state transition as well as post-commit collection. [5]

For a maintainer fix, useful regression coverage would include multiple conversation-owned workspaces, an unrelated conversation left untouched, and rollback leaving both the conversation and resources unchanged with no collection dispatched. This would cover the ownership scope and transaction boundary beyond the single-workspace reproduction.

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about dify with Dosu

dosubot[bot] avatar Nov 13 '26 12:11 dosubot[bot]