Repository navigation
Description
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
- 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 outputtingfiles). - 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.
- Run it once from Studio (debugger). → Works: Agent outputs
textandfiles. - 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)
tasks/workflow_schedule_tasks.py→AsyncWorkflowService.trigger_workflow_async(user=<Account>);tasks/async_workflow_tasks.pyrunsWorkflowAppGenerator.generate(user=<Account>, invoke_from=InvokeFrom.SERVICE_API).BaseAppGenerator._bind_file_access_scopecorrectly derivesuser_from=ACCOUNTfrom the realAccountobject, butWorkflowBasedAppRunner._resolve_user_from(invoke_from)re-derives it frominvoke_fromonly (InvokeFrom.runs_as_account()is true only for DEBUGGER/EXPLORE), so the graph / Agentexecution_contextbecomesuser_id=<Account.id>, user_from=end-user.- Upload (
controllers/inner_api/agent/files.py/agent/files/upload-request): becauseuser_from == "end-user", the owner isget_user(tenant_id, <Account.id>).id, i.e. a newly mapped EndUser id. The ToolFile is stored withuser_id=<EndUser.id>. - Download (
/agent/files/download-request→FileRequestService.request_download): uses the raw<Account.id>withuser_from=end-user, soDatabaseFileAccessController.apply_tool_file_filtersaddsToolFile.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
- Webhook file upload fails in async workflow because ToolFile owner differs from Trigger EndUser #42987 / fix(webhook): align ToolFile owner with Trigger EndUser for multipart uploads #42988: same class of bug for Webhook multipart uploads (ToolFile owner Account vs Trigger EndUser).
- fix: reuse tenant-scoped end user in plugin backwards invocation so file inputs pass ownership checks #39141: same
ToolFile not foundmismatch for plugin backwards invocation.
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
dosubot commentedon Oct 26, 2026
The checked-out code supports your diagnosis: the generator derives
user_fromfrom the actualAccount/EndUserobject, while the workflow runner independently derives it frominvoke_from. The Agent upload endpoint can then map the ID throughget_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()recomputesuser_frombefore 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_APIupload/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.
shi-felix commentedon Oct 26, 2026
Two independent fixes are now open for this issue:
AppGenerateEntity.user_fromat the workflow / advanced-chat / RAG-pipeline generator boundaries and lets_resolve_user_fromprefer it, so all three runners and both fresh and resumed runs take the corrected identity; ~same shape as the related Webhook file upload fails in async workflow because ToolFile owner differs from Trigger EndUser #42987/fix(webhook): align ToolFile owner with Trigger EndUser for multipart uploads #42988 fixes.user_frominto pause snapshots and restores it for resumed executions.Maintainers: please pick whichever fits better (or merge the pause-snapshot persistence from #44796 into the broader boundary capture in #44799).
From Kimi Code