Skip to content

fix: persist agent app uploads as message files - #40889

Open
Elliott-byte wants to merge 2 commits into
langgenius:mainfrom
Elliott-byte:fix/agent-app-persist-message-files
Open

fix: persist agent app uploads as message files#40889
Elliott-byte wants to merge 2 commits into
langgenius:mainfrom
Elliott-byte:fix/agent-app-persist-message-files

Conversation

@Elliott-byte

Copy link
Copy Markdown
Contributor

Fixes #40874

Summary

Agent apps (New Agent Beta) built the generate entity with files=[]: user uploads were forwarded to the agent backend through the prompt locators (prompt_file_mappings), but never parsed into File entities, so _init_generate_records never persisted MessageFile rows for them. As a result, uploaded files vanished from the conversation history UI as soon as the chat was reloaded — in both the build preview and the published app. This is the remaining UI symptom in #40874 (the request-side attachment drop from the same report was already fixed by #40179).

This change parses the request file mappings into File entities inside the file-access scope — the same pattern agent_chat uses — and passes them to AgentAppGenerateEntity, so the chat pipeline persists MessageFile records and history APIs return the uploads again. The agent backend keeps consuming only the prompt locators; the agent app runner and task pipeline never read entity.files, so the change is purely additive on the persistence side. The HITL resume path still passes files=[], since a resume carries no new uploads.

One deliberate behavior change: an invalid upload_file_id now fails the request (consistent with chat / agent_chat) instead of being silently dropped.

Verified with the updated unit test in tests/unit_tests/core/app/apps/agent_app/test_app_generator.py (uploads must reach the entity as File objects), plus the full tests/unit_tests/core/app/apps/ suite (578 passed).

Screenshots

Before After
Uploaded files disappear from the chat history after reload message_files persisted and rendered in history

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 make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

From Claude Code and me

Agent apps built the generate entity with files=[], so user uploads were
never persisted as MessageFile records and disappeared from the
conversation history UI after a reload, in both the build preview and the
published app. Parse the request file mappings into File entities (same
pattern as agent-chat) so the chat pipeline persists them; the agent
backend keeps consuming only the prompt locators.

Fixes langgenius#40874
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 59.25% 59.25% 0.00%
Strict coverage 58.83% 58.83% 0.00%
Typed symbols 39,551 39,551 0
Untyped symbols 27,398 27,398 0
Modules 3172 3172 0

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-08-17 12:10:59.090912731 +0000
+++ /tmp/pyrefly_pr.txt	2026-08-17 12:10:51.442851273 +0000
@@ -3187,13 +3187,13 @@
 ERROR Argument `DummyAccount` is not assignable to parameter `user` with type `Account | EndUser` in function `core.app.apps.agent_app.app_generator.AgentAppGenerator.generate` [bad-argument-type]
   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:73:22
 ERROR Argument `DummyAccount` is not assignable to parameter `user` with type `Account | EndUser` in function `core.app.apps.agent_app.app_generator.AgentAppGenerator.generate` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:183:18
+   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:189:18
 ERROR Argument `DummyAccount` is not assignable to parameter `user` with type `Account | EndUser` in function `core.app.apps.agent_app.app_generator.AgentAppGenerator.generate` [bad-argument-type]
-   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:229:18
+   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:235:18
 ERROR Object of class `FunctionType` has no attribute `call_args` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:321:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:327:16
 ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:389:25
+   --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:395:25
 ERROR Object of class `NoneType` has no attribute `message` [missing-attribute]
   --> tests/unit_tests/core/app/apps/agent_app/test_input_guards.py:67:12
 ERROR Object of class `NoneType` has no attribute `prompt_messages` [missing-attribute]

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v1.16 Agent mode: uploaded files not displayed in UI and file variables invalid in build

1 participant