Skip to content

Scheduled workflow: Agent node file output fails with "ToolFile not found" because runner marks the Account as end-user #44792

Closed

Description

@CodeWarriors0

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

1.16.1 (same code path still present in 1.17.1, 1.18.0 and main)

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Environment

This was hit in our self-hosted production environment (Dify deployed on Kubernetes on a cloud provider, with separate API / Worker / dify-agent deployments), on a Workflow app with a Schedule Trigger that runs every hour. Every scheduled run failed, while the same app worked when run manually in Studio.

Setup

  1. Create a Workflow app:
    Schedule Trigger → Agent node (new Agent / agent_v2) → any node that consumes Agent.files (e.g. a tool that sends the file somewhere, or simply an End node outputting files).
  2. Instruct the Agent to generate a small file (e.g. "write an HTML report and return it as a file"), so it uploads the file and then requests its download URL through the Agent Stub.
  3. Run it once from Studio (debugger). → Works: Agent outputs text and files.
  4. Publish and let the Schedule Trigger fire. → Fails.

Logs from the scheduled run

Upload succeeds, download request fails 40 ms later:

POST /files/upload/for-plugin          -> 201
POST /inner/api/.../download request   -> 400
ValueError: ToolFile <tool_file_id> not found
  FileRequestService.request_download(...)
  factories/file_factory/builders.py  _build_from_tool_file

Agent node succeeds with text=ready, files=not_produced; the downstream node then fails with:

Variable ['<agent_node_id>', 'files'] does not exist

Agent execution context of the two runs (same app, same Agent config):

Run user_id user_from invoke_from Result
Studio debug <account_id> account debugger files OK
Schedule Trigger <account_id> (same Account) end-user service-api ToolFile not found

Root cause (traced on main)

  1. tasks/workflow_schedule_tasks.py → AsyncWorkflowService.trigger_workflow_async(user=<Account>); tasks/async_workflow_tasks.py runs WorkflowAppGenerator.generate(user=<Account>, invoke_from=InvokeFrom.SERVICE_API).
  2. BaseAppGenerator._bind_file_access_scope correctly derives user_from=ACCOUNT from the real Account object, but WorkflowBasedAppRunner._resolve_user_from(invoke_from) re-derives it from invoke_from only (InvokeFrom.runs_as_account() is true only for DEBUGGER/EXPLORE), so the graph / Agent execution_context becomes user_id=<Account.id>, user_from=end-user.
  3. Upload (controllers/inner_api/agent/files.py /agent/files/upload-request): because user_from == "end-user", the owner is get_user(tenant_id, <Account.id>).id, i.e. a newly mapped EndUser id. The ToolFile is stored with user_id=<EndUser.id>.
  4. Download (/agent/files/download-request → FileRequestService.request_download): uses the raw <Account.id> with user_from=end-user, so DatabaseFileAccessController.apply_tool_file_filters adds ToolFile.user_id == <Account.id> → no row → ToolFile ... not found.

In short, the same run carries two different identity decisions (real object type vs. invoke_from inference), and the Account id is labelled as an EndUser, so upload and download resolve to different owner ids.

Related

This report is about the Schedule Trigger + Agent node file output path, which is not covered by those fixes.

✔️ Expected Behavior

A Schedule-Triggered run should behave like the Studio run: the file uploaded by the Agent node can be read back (download URL issued) and files is available to downstream nodes.

The run identity should be consistent end to end: user_from should follow the actual user object (Account → account, EndUser → end-user) rather than being inferred from invoke_from, while keeping the existing EndUser ownership checks and tenant isolation unchanged.

❌ Actual Behavior

  • In our self-hosted production deployment (Kubernetes), every scheduled run of the app fails (observed on consecutive hourly runs), while the same workflow works in Studio. Scheduled reports are not delivered.
  • The Agent node is marked succeeded but produces no files (files=not_produced); the uploaded ToolFile exists but is owned by a mapped EndUser id that the download request never matches.
  • The downstream node fails with Variable ['<agent_node_id>', 'files'] does not exist, so the whole run fails (including text-only branches that don't need the file).
  • Increasing timeouts or file size limits does not help; this is an identity mismatch, not a transport error.

Activity

  1. added
    🐞 bug
    on Oct 26, 2026
  2. dosubot commented on Oct 26, 2026

    @dosubot

    The checked-out code supports your diagnosis: the generator derives user_from from the actual Account/EndUser object, while the workflow runner independently derives it from invoke_from. The Agent upload endpoint can then map the ID through get_user(), but download forwards the original ID unchanged. [1] [2] [3] [4]

    One additional regression case for the eventual fix is resumed execution: WorkflowAppRunner.prepare() recomputes user_from before branching into the resume path and passes that value into the restored graph. Fixing only initial graph construction would leave that path exposed to the same identity inference. [5]

    A useful regression test would cover Account + SERVICE_API upload/download, then repeat after resume, alongside a genuine EndUser run. It should also assert that another EndUser and another tenant cannot retrieve the file, preserving the existing ownership and tenant filters rather than bypassing them. [6]

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about dify

  3. shi-felix commented on Oct 26, 2026

    @shi-felix
    Contributor

    Two independent fixes are now open for this issue:

    Maintainers: please pick whichever fits better (or merge the pause-snapshot persistence from #44796 into the broader boundary capture in #44799).

    From Kimi Code

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

    🐞 bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions