Skip to content

fix(api): grant in-run tool files to later workflow nodes - #41300

Merged
crazywoola merged 1 commit into
langgenius:mainfrom
Souravrajvi0:feat/fix-workflow-tool-file-grant-41169-fc6c
Sep 21, 2026
Merged

crazywoola merged 1 commit into
langgenius:mainfrom
Souravrajvi0:feat/fix-workflow-tool-file-grant-41169-fc6c

Conversation

@Souravrajvi0

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #41169

A workflow that downloads an image in a tool node and passes it to a later LLM vision node works in the orchestration test-run, but fails when the same published workflow is invoked as a tool from an Agent.

Orchestration binds an Account file-access scope, so plugin ToolFile rows are readable. Agent chat binds an EndUser scope. Plugin uploads (/files/upload/for-plugin) often store ToolFile.user_id as a different identity than the chatting end user, so later build_from_mapping lookups fail the ownership filter and the LLM prompt has no image (files: []).

This change mirrors the existing upload-file grant: ToolFileMessageTransformer records produced tool_file_ids on the current FileAccessScope. Later nodes in the same execution can attach those files. Ungranted tool files still require matching user_id.

This is the nested-workflow internal file path. It does not change how the Agent App converts tool results to chat text (#40425 / PR #40455).

Screenshots

Not applicable (backend file-access grant).

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran targeted unit tests for the changed files (test_build_from_mapping.py, test_message_transformer.py, FileAccessScope-related tests)

When a workflow is invoked as a tool from an Agent, plugin downloads
often store ToolFile.user_id as a different identity than the chatting
end user. Later LLM nodes then fail the ownership filter and drop the
image, so the vision prompt has no user file.

Mirror the existing upload-file grant: ToolFileMessageTransformer
records produced tool_file_ids on the current FileAccessScope so
build_from_mapping can attach them without weakening ungranted access.

Fixes langgenius#41169
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-08-26 07:49:54.794407111 +0000
+++ /tmp/pyrefly_pr.txt	2026-08-26 07:49:40.927368017 +0000
@@ -6801,11 +6801,11 @@
 ERROR Argument `SimpleNamespace` is not assignable to parameter `controller` with type `ToolProviderController[Unknown, Unknown]` in function `core.tools.utils.encryption.create_tool_provider_encrypter` [bad-argument-type]
    --> tests/unit_tests/core/tools/utils/test_encryption.py:203:75
 ERROR `None` is not subscriptable [unsupported-operation]
-  --> tests/unit_tests/core/tools/utils/test_message_transformer.py:93:12
+  --> tests/unit_tests/core/tools/utils/test_message_transformer.py:95:12
 ERROR `None` is not subscriptable [unsupported-operation]
-  --> tests/unit_tests/core/tools/utils/test_message_transformer.py:94:12
+  --> tests/unit_tests/core/tools/utils/test_message_transformer.py:96:12
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/tools/utils/test_message_transformer.py:137:12
+   --> tests/unit_tests/core/tools/utils/test_message_transformer.py:139:12
 ERROR Class member `_TestHitCallback.on_query` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
    --> tests/unit_tests/core/tools/utils/test_misc_utils_extra.py:128:9
 ERROR Class member `_TestHitCallback.on_tool_end` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
@@ -8067,11 +8067,11 @@
 ERROR Generator function should return `Generator` [bad-return]
   --> tests/unit_tests/extensions/test_workflow_warm_shutdown.py:13:36
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
-  --> tests/unit_tests/factories/test_build_from_mapping.py:69:58
+  --> tests/unit_tests/factories/test_build_from_mapping.py:74:58
 ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]
-   --> tests/unit_tests/factories/test_build_from_mapping.py:148:12
+   --> tests/unit_tests/factories/test_build_from_mapping.py:153:12
 ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]
-   --> tests/unit_tests/factories/test_build_from_mapping.py:180:12
+   --> tests/unit_tests/factories/test_build_from_mapping.py:185:12
 ERROR Object of class `Dataset` has no attribute `embedding_available` [missing-attribute]
    --> tests/unit_tests/fields/test_dataset_fields.py:212:5
 ERROR Object of class `UploadFile` has no attribute `preview_url` [missing-attribute]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 61.21% 61.21% -0.00%
Strict coverage 60.80% 60.80% -0.00%
Typed symbols 42,095 42,096 +1
Untyped symbols 26,855 26,858 +3
Modules 3258 3258 0

@crazywoola
crazywoola added this pull request to the merge queue Sep 21, 2026
Merged via the queue into langgenius:main with commit f9129bc Sep 21, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The file transfer logic in the workflow orchestration page is inconsistent with that of external API calls.

2 participants