dify icon indicating copy to clipboard operation
dify copied to clipboard

feat(workflow-tool): Add an option to auto-sync "Workflow as Tool" when publishing workflow updates

Open wazgii opened this issue 1 week ago • 3 comments

Self Checks

  • [x] I have read the Contributing Guide and Language Policy.
  • [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] Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

I was using the Workflow as Tool feature to modularize a complex multi-agent stock analysis workflow (where a parent workflow invokes a child workflow tool inside an Iteration node).

When I updated the internal Agent nodes inside the child workflow (without changing any Start/End input or output parameters) and clicked "Publish" -> "Publish Update", the published Workflow as Tool snapshot was not updated. Because I hadn't touched this workflow in a month, I forgot that Dify requires a separate manual action ("Publish" -> "Workflow as Tool" -> "Save") to update the tool snapshot.

It was frustrating because:

  1. Silent Stale Execution & Ghost Errors: When the parent workflow triggered the child workflow tool, it silently executed the old tool snapshot that still referenced a deleted/replaced Agent UUID, throwing Agent <uuid> is not available or has not been published, even though the new Agent was already published and bound on the current canvas.
  2. Confusing Execution Logs: In the child workflow's Log/Tracing panel, the failed runs triggered by the parent workflow displayed outdated node names and bindings from the old tool snapshot, completely contradicting the current published workflow canvas.
  3. High Cognitive Load for Internal Edits: While freezing the tool snapshot makes sense when the Start/End I/O schema changes (to prevent breaking parent workflows), forcing users to manually do a two-step save every single time they tweak an internal prompt, LLM, or Agent node is error-prone and counter-intuitive.

Suggested Solution: Give users the option to auto-sync the Workflow as Tool snapshot when publishing workflow updates:

  1. Add an "Auto-sync Workflow Tool" checkbox/toggle:
    • Once a workflow has been published as a tool, provide a checkbox in the Publish dropdown (or a persistent toggle inside the Workflow as Tool modal): [x] Automatically update "Workflow as Tool" when publishing workflow updates (enabled by default as long as the Start/End I/O schema remains compatible).
  2. Visual "Tool Outdated" Indicator:
    • If manual sync is used and the latest published workflow version is newer than the saved tool snapshot, display a clear warning badge (e.g., Tool update pending) on the Publish menu so users don't forget to save the tool again.

2. Additional context or comments

  • Current Documentation Reference: The latest Dify documentation (Dify Tools -> Workflow) states:

    "Publish the workflow first, then click Publish > Workflow as Tool. The tool keeps running the version it was saved with. After you publish changes to the workflow, save the tool again."

  • Related Issues / PRs:
    • In PR #33637 (fix: sync workflow description and name to MCP server on update), Dify added automatic synchronization when updating a workflow for MCP servers. Having an optional/automatic sync mechanism for Dify's native Workflow as Tool (especially when the I/O schema is unchanged) would align the UX and prevent stale snapshot bugs.
    • Related to #32034 (synchronizing workflow tool updates to referencing workflows).
  • Log Version Clarity: In addition to the auto-sync option, it would be very helpful if the workflow execution log panel displayed a small tag indicating when a run was executed against an older Workflow as Tool snapshot rather than the latest published workflow version.

3. Can you help us with this feature?

  • [ ] I am interested in contributing to this feature.

wazgii avatar Nov 27 '26 05:11 wazgii

I would like to help with this, starting with the publication contract and then implementing an agreed slice.

I checked the relevant paths against current main c2df40d9dc58. The tool has its own saved version: update_workflow_tool advances WorkflowToolProvider.version, whereas ordinary workflow publication creates a new workflow and updates the App's published pointer. The tool-details response already exposes synced, so a version-outdated indicator need not be inferred from input-field counts.

Two boundaries seem important:

  1. New runs versus existing runs. Updating the provider can select a newer workflow for a new invocation. It must not rewrite definitions captured by running or paused invocations. WorkflowToolSourceService reloads an existing snapshot by its exact workflow ID/version, rather than resolving the mutable provider again. I ran the existing source/repository suites: 16 tests passed, including serialized snapshots and a real local workflow engine retaining the old definition across republication. That is baseline coverage, not an implemented auto-sync feature.

  2. Matching I/O does not prove equivalent behavior. An internal prompt or Agent change can deliberately change tool behavior without changing any Start/End fields. I suggest retaining manual publication by default for existing tools, and making auto-sync an explicit author choice. For a conservative first auto-sync rule, require an unchanged effective input/output contract, including requiredness, defaults, select options, file constraints and saved parameter exposure/bindings—not just names or field counts. A changed or unsupported contract should require manual confirmation. This check would not claim to prove semantic compatibility of arbitrary workflows.

A possible implementation sequence:

  • First expose the existing version comparison as “Tool update pending” in the Publish UI, with both version references available. Keep this separate from the existing parameter-outdated indicator.
  • Then add an opt-in policy on an already-published tool. Run policy evaluation and the provider-version update in the same tenant-scoped publication transaction as the new workflow/App pointer; use a lock or expected-version condition so a concurrent manual tool edit cannot be overwritten. Do not call the current save-tool method from a post-commit callback, since it owns a separate transaction.
  • Keep provider identity and saved tool configuration unchanged when advancing only its workflow version. Preserve old captured definitions for running/resumed invocations. Logs should identify the workflow version actually executed, not relabel an old run as current.

For tests I would cover default/manual behavior, an internal-only change, each contract-change category, a concurrent tool edit, publication rollback, permission/tenant boundaries, and new invocation versus paused invocation version selection. I would not modify parent workflow graphs or silently republish their tools.

Would a first PR for the version-outdated indicator be useful, followed by the opt-in transaction/contract work? If someone is already implementing either part, I can take a complementary test slice. No auto-sync implementation or database-concurrency validation is claimed here.

CryoThrust avatar Nov 27 '26 05:11 CryoThrust

Thank you @CryoThrust for the thorough investigation and such a well-thought-out implementation plan!

Your two boundaries make total sense:

  1. Preserving captured definitions for in-flight/paused runs while routing new invocations to the updated provider version is definitely the right behavior.
  2. Making auto-sync an explicit opt-in policy with a strict effective I/O contract check (requiredness, defaults, select options, file constraints, and parameter bindings) strikes the perfect balance between safety and developer convenience.

Would a first PR for the version-outdated indicator be useful, followed by the opt-in transaction/contract work?

Yes, absolutely! Splitting this into two incremental PRs is a great approach:

  • PR 1: Surfacing the existing synced status as a clear "Tool update pending" indicator in the Publish UI (and ideally showing the executed workflow version in the logs) will immediately prevent users from falling into the silent stale-snapshot trap.
  • PR 2: Implementing the transactional opt-in auto-sync policy with the strict contract check will complete the workflow authoring experience.

Really appreciate you taking this on—looking forward to your PRs!

wazgii avatar Nov 27 '26 07:11 wazgii

The first UI slice is in #47385. It uses the existing synced response to show “Tool update pending” even when the inputs have not changed. The existing parameter warning takes precedence, and updating the tool still requires the current editor and confirmation flow.

Five Chromium feature cases pass, including publication/refetch without silent synchronization and an explicit confirmed update clearing the warning. The 167 related unit tests and repository static checks also pass.

This PR deliberately leaves automatic synchronization and executed-version logging out. They need separate backend work; the UI indicator does not establish either behavior. The opt-in transaction/contract work can follow after feedback on this slice.

CryoThrust avatar Nov 27 '26 10:11 CryoThrust