Skip to content

fix: restore download button when file type is selected in agent message - #17184

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:fix/agent-download-button-file-type
Jul 22, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:fix/agent-download-button-file-type

Conversation

@euvre

@euvre euvre commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

When an agent Message component has file type checkboxes enabled (e.g., Markdown), the backend emits attachment and download information via message_end events. However, the SSE relay in agent chat sessions filters workflow_finished outputs (keeping only usage), and the frontend previously read attachments solely from workflow_finished, causing the download button to disappear even when file types were correctly configured.

Changes

  • Frontend (use-send-message.ts): Extend IMessageEndData interface to support attachment and downloads fields
  • Frontend (use-send-agent-message.ts): Fall back to reading attachment / downloads from the last message_end event when workflow_finished.outputs is unavailable
  • Backend (canvas.py): Include downloads in _build_message_end so they survive the SSE relay that strips outputs from workflow_finished
  • Frontend (next-message-item/index.tsx): Remove stale commented-out attachment download code

When an agent Message component has file type checkboxes enabled,
the backend emits attachment/download info via message_end events,
but the SSE relay filters workflow_finished outputs (keeping only
usage). The frontend previously read attachments solely from
workflow_finished, causing the download button to disappear.

Changes:
- Extend IMessageEndData interface to support attachment and downloads
- Fall back to reading attachment/downloads from the last message_end
  event when workflow_finished.outputs is unavailable
- Include downloads in _build_message_end on the Python backend side
- Remove stale commented-out attachment download code from
  next-message-item
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 21, 2026
@euvre euvre added the ci Continue Integration label Jul 21, 2026
@dosubot dosubot Bot added the 🐞 bug Something isn't working, pull request that fix bug. label Jul 21, 2026
@euvre
euvre requested a review from wangq8 July 21, 2026 10:02
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Message-end payloads now include non-empty downloads. Frontend message-end data makes related fields optional, and agent message reconstruction falls back to the latest message-end event when workflow outputs lack attachment or download data. Obsolete commented download UI code was removed.

Changes

Message download propagation

Layer / File(s) Summary
Emit download metadata
agent/canvas.py, web/src/hooks/use-send-message.ts
Message-end construction emits non-empty downloads, while IMessageEndData accepts optional reference, attachment, and download fields.
Recover message attachments and downloads
web/src/pages/agent/chat/use-send-agent-message.ts, web/src/components/next-message-item/index.tsx
Agent message reconstruction falls back from workflow outputs to the latest MessageEnd data, and obsolete commented download-button JSX is removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: qinling0210

Poem

I’m a rabbit with downloads to share,
Carrying message crumbs through the air.
Workflow or event, the data arrives,
Optional fields keep the flow alive.
Hop, hop—old comments take flight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: restoring the download button for agent messages when file types are selected.
Description check ✅ Passed The description includes the required Summary and gives enough context plus implementation details for the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
web/src/pages/agent/chat/use-send-agent-message.ts (1)

86-88: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Use findLast to avoid unnecessary array cloning and reversing.

Cloning and reversing the eventList array incurs unnecessary memory allocation and time complexity. Please consider using Lodash's findLast (or native Array.prototype.findLast if the compilation target supports it). As per coding guidelines, use Lodash for general utility operations when appropriate.

♻️ Proposed refactor using Lodash

First, add the import at the top of the file:

import findLast from 'lodash/findLast';

Then apply the fix:

-  const messageEndEvent = [...eventList]
-    .reverse()
-    .find((x) => x.event === MessageEventType.MessageEnd) as IMessageEndEvent;
+  const messageEndEvent = findLast(
+    eventList,
+    (x) => x.event === MessageEventType.MessageEnd
+  ) as IMessageEndEvent;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/pages/agent/chat/use-send-agent-message.ts` around lines 86 - 88,
Update the messageEndEvent lookup in the send-agent message flow to use Lodash’s
findLast (adding its import) instead of cloning eventList with spread and
reverse. Preserve the existing MessageEventType.MessageEnd predicate and
IMessageEndEvent cast.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@web/src/pages/agent/chat/use-send-agent-message.ts`:
- Around line 86-88: Update the messageEndEvent lookup in the send-agent message
flow to use Lodash’s findLast (adding its import) instead of cloning eventList
with spread and reverse. Preserve the existing MessageEventType.MessageEnd
predicate and IMessageEndEvent cast.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b7d3b99c-4fee-4ef9-bcca-05cc847bf525

📥 Commits

Reviewing files that changed from the base of the PR and between edeb47c and 09705ac.

📒 Files selected for processing (4)
  • agent/canvas.py
  • web/src/components/next-message-item/index.tsx
  • web/src/hooks/use-send-message.ts
  • web/src/pages/agent/chat/use-send-agent-message.ts
💤 Files with no reviewable changes (1)
  • web/src/components/next-message-item/index.tsx

@codecov

codecov Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (6a85d1c) to head (39668fa).
⚠️ Report is 56 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17184      +/-   ##
==========================================
- Coverage   94.56%   90.65%   -3.91%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      650      -28     
- Misses         25       39      +14     
- Partials       14       28      +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Multi-layer fix is well-coordinated: backend adds downloads to message_end, frontend falls back to reading attachment/downloads from the last message_end event when workflow_finished outputs are unavailable, and stale commented-out code is cleaned up. The fallback chain in findMessageFromList is correctly ordered.

@wangq8
wangq8 requested a review from dcc123456 July 21, 2026 11:10
@wangq8
wangq8 merged commit 2f7dc60 into infiniflow:main Jul 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants