Skip to content

Retried Agent cleanup can miss workflow-tool workspaces #46657

Open

Description

@mikamikasuki

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

main (ce26dd6)

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. Create a workflow-only Agent backed by App A.
  2. Invoke that Agent as a workflow tool from a workflow in App B. The generated workspace is recorded with the App B workflow run, while the persisted workflow-tool ownership points to App A.
  3. Remove the Agent's final workflow owner so WorkflowAgentRetirementService.retire_unowned retires the Agent and its resources.
  4. If publishing the resource-collection task fails after the database transaction commits, retry retirement and inspect the workspace IDs submitted for collection.

On current main (ce26dd6c9868990df2380ed52751be83f7af2f33), a focused regression test reproduces the retry omission: the second collection request contains the Agent's own workspace but not the retired cross-app workflow-tool workspace.

✔️ Expected Behavior

Retrying retirement should enqueue every retired workspace owned by the orphaned Agent, including workflow-tool workspaces stored under another App. A failed first task publication must not make that workspace undiscoverable on retry.

❌ Actual Behavior

The first retirement discovers the workflow-tool workspace through its persisted root-App ownership and marks it retired. On retry, retire_unowned reloads already-retired workspace IDs using only AgentWorkspace.app_id == backing_app_id. The workflow-tool workspace is stored under App B, so it is omitted from the collection retry and its backend resource may be left without a cleanup task.

Activity

  1. dosubot commented on Nov 18, 2026

    @dosubot

    One additional implication: this appears to affect the first collection payload too, not just retries. retire_all_for_app() discovers cross-app workflow-tool workspaces and returns their retired IDs, but retire_unowned() discards that return value and builds workspace_ids using only AgentWorkspace.app_id == backing_app_id. So even without a publication failure, that cross-app workspace appears absent from this collector request. This is a static-code finding, not a test result. [1] [2]

    The existing retry regression covers a conversation workspace whose app_id matches the hidden App, so it does not exercise this ownership mismatch. A useful extension would assert the cross-app workspace ID in both an ordinary successful publication and a retry after publication failure, while excluding unrelated and other-tenant workspaces. The collector processes explicit workspace IDs rather than rediscovering omitted workspaces. [3] [4]

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about dify

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞 bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions