Repository navigation
fix(agent): persist plugin blob outputs and render attachments in chat and logs - #46219
BeautyyuYanli wants to merge 9 commits into
Conversation
Pyrefly Type Coverage
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-13 04:35:47.905072825 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-13 04:35:34.837083398 +0000
@@ -3189,25 +3189,25 @@
ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
--> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:782:20
ERROR Class `FakeAgentBackendScenario` has no class attribute `PAUSED` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:199:35
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:203:35
ERROR Argument `tuple[AgentAppSessionScope, str, SessionSnapshot | None]` is not assignable to parameter `object` with type `tuple[AgentAppSessionScope, str, SessionSnapshot | None, str | None, str | None]` in function `list.append` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:569:27
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:573:27
ERROR Argument `Literal[0]` is not assignable to parameter `message_unit_price` with type `Decimal | SQLCoreOperations[Decimal]` in function `models.model.Message.__init__` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:689:28
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:693:28
ERROR Argument `Literal[0]` is not assignable to parameter `message_price_unit` with type `Decimal | SQLCoreOperations[Decimal]` in function `models.model.Message.__init__` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:690:28
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:694:28
ERROR Argument `Literal[0]` is not assignable to parameter `answer_unit_price` with type `Decimal | SQLCoreOperations[Decimal]` in function `models.model.Message.__init__` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:693:27
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:697:27
ERROR Argument `Literal[0]` is not assignable to parameter `answer_price_unit` with type `Decimal | SQLCoreOperations[Decimal]` in function `models.model.Message.__init__` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:694:27
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:698:27
ERROR Argument `Literal[0]` is not assignable to parameter `total_price` with type `Decimal | SQLCoreOperations[Decimal | None] | None` in function `models.model.Message.__init__` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:696:21
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:700:21
ERROR Argument `Literal[core.app.entities.app_invoke_entities.InvokeFrom.WEB_APP]` is not assignable to parameter `invoke_from` with type `models.enums.InvokeFrom | SQLCoreOperations[models.enums.InvokeFrom | None] | None` in function `models.model.Message.__init__` [bad-argument-type]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:698:21
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:702:21
ERROR Cannot unpack tuple[AgentAppSessionScope, str, SessionSnapshot | None, str | None, str | None] (of size 5) into 3 values [bad-unpacking]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:746:5
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:750:5
ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
- --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:1061:12
+ --> tests/unit_tests/core/app/apps/agent_app/test_app_runner.py:1067:12
ERROR Object of class `list` has no attribute `startswith` [missing-attribute]
--> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:611:16
ERROR Object of class `NoneType` has no attribute `kind` [missing-attribute]
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46219 +/- ##
==========================================
+ Coverage 90.31% 90.33% +0.01%
==========================================
Files 6496 6458 -38
Lines 408541 408103 -438
Branches 81968 81836 -132
==========================================
- Hits 368979 368649 -330
+ Misses 33158 33053 -105
+ Partials 6404 6401 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…utputs # Conflicts: # api/repositories/agent_observability_repository.py
…utputs # Conflicts: # dify-agent/docs/dify-agent/user-manual/plugin-tool-layer/index.md # dify-agent/src/dify_agent/agent_stub/protocol/agent_stub.py # dify-agent/src/dify_agent/layers/dify_plugin/tools_layer.py
…utputs # Conflicts: # web/features/agent-v2/agent-editor/preview/__tests__/chat-history-fixtures.ts # web/features/agent-v2/agent-editor/preview/__tests__/chat-history.browser.spec.tsx
Vinext bundle analysisJS gzip: 🟠 +9.36 KiB (+0.09%) · CSS gzip: 🟠 +293 B (+0.08%)
Entry changes: 🟠 205 increased · 🟢 16 decreased (gzip). Largest entry changesTop 5 by absolute gzip delta. Static dependencies overlap; do not sum entries.
Top 20 of 221 changed entries (full paths and raw sizes)
📦 11 package attribution changes (uncompressed modules)Showing 11 of 11, ordered by absolute module-size delta.
Measurement details and build revisionsBase: Raw JS change: 🟠 +20.95 KiB (+0.06%) · Raw CSS change: 🟠 +2.15 KiB (+0.12%) 🟠 Increase · 🟢 Decrease · ⚪ Unchanged. Colors indicate direction, not a performance budget verdict. Percentages use the base size. Entries follow only static edges in the official Rolldown chunk graph, deduplicating shared files. Dynamic entries are measured when loaded; they are not page first-load metrics. Entry totals overlap and must not be summed. Download base/merge snapshots and official Rolldown analysis reports. Comparison: event base SHA vs the tested merge commit at GITHUB_SHA (PR or merge queue). |
This PR is made with gpt-6.2-sol (Codex), gpt-6.1-sol (Codex), gemini-4-neon (Google Antigravity) and gemini-4-carbon (Google Antigravity), while I'm responsible for all the changes.
Fixes #42114
Supersedes #43099
Summary
When a plugin tool invoked by
dify-agentemits binaryBLOBorBLOB_CHUNKstream messages (such as PNG charts, PDFs, DOCX files, or audio), generated files were previously omitted from both chat attachments and Console Agent Logs (and chunkedBLOB_CHUNKmetadata could be dropped when the closing frame omittedmeta).This PR completes the binary plugin
BLOBattachment delivery pipeline acrossdify-agent,api,packages/contracts, andwebon top of the sharedread_media/agent_filesplane while keeping non-BLOBplugin media scope boundaries intact (tracked separately in #40455):dify-agent(protocol/agent_stub.py,layers/agent_files.py,tool_client.py,tools_layer.py):BLOB_CHUNKmetadata (filename,mime_type, etc.) across frames when merging into a terminalBLOBmessage even when the closingend=Truechunk omitsmeta.is_safe_dify_file_uriandfile_reference_record_idin client-safedify_agent.agent_stub.protocol.agent_stub(re-exported inagent_stub_files.py) so core-onlydify-agentconsumers such asapinever pull[server]optional dependencies (jwcrypto,fastapi), and enforceis_safe_dify_file_urionupload_uriinupload_agent_tool_file.MessageType.BLOBfilename/MIME metadata before uploading viaupload_agent_tool_file, preserveformat_media_observation(read_media) andTool media unavailableobservation contracts, and returnToolReturn.metadata["dify_plugin_blob_files"]carrying persistedToolFileIDs decoded from canonicaldify-file-ref:references forBLOB/ mergedBLOB_CHUNKoutputs.api&packages/contracts(app_runner.py,agent_fields.py,agent_observability_repository.py, OpenAPI & generated contracts):ToolFileUUIDs and run ownership (tenant_id,user_id,conversation_id) inAgentAppRunner, deriving file extension and/files/tools/<id><ext>URLs exclusively from verifiedToolFilerows, committing deduplicated assistantMessageFilerecords andMessageAgentThought.message_filesatomically before publishing liveQueueAgentThoughtEventandQueueMessageFileEventSSE items.message_filesonAgentLogMessageItemResponse(GET /console/api/agent/<agent_id>/logs/<conversation_id>/messages) via read-only batchUploadFile/ToolFileresolution inAgentObservabilityQueriesundersession.no_autoflush(without ORM mutations, flushes, or commits), and synchronize Console OpenAPI markdown and TypeScript/Zod contracts.web(useChatSSE boundary,AgentLogDetailPanel, & chat history/refresh normalization):agent_thought.message_filesstring IDs intothought.fileswhile keepingthought.message_filesstrictlyFileEntity[], routing live and resumedmessage_fileevents to their owning tool thoughts (including parallel tool calls and Agent v2agent_response_parts).message_filesinAgentLogDetailPanel, and share typedMessageFile->FileEntity[]normalization (related_id: file.id) across Agent v2 preview chat history, post-stream completion refresh, WebApp chat-with-history, and embedded chatbot while skipping missing/deleted file IDs inaddFileInfos.Screenshots
BLOB/BLOB_CHUNKoutputs were omitted or misrouted in live/reloaded chat thoughts and missing from Console Agent Logs.BLOB/BLOB_CHUNKoutputs are persisted asToolFile/MessageFileattachments, streamed to the owning tool thought viamessage_file, preserved on reload, compatible withread_media, and rendered in Console Agent Logs.Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods