Dataset segment cleanup misses inline images with signed preview URLs
Summary
Inline image IDs are not found when a Markdown preview URL contains signed query parameters. Dataset and document cleanup then omit those image IDs from upload-file deletion.
Source-based reproduction
api/core/tools/utils/web_reader_tool.py:get_image_upload_file_ids() matches ). The closing ) must follow file-preview or image-preview immediately. For example:

The function returns [], rather than ["abc123"], because the query string sits before ).
This is a reachable URL shape: signed /files/<id>/file-preview?... values occur in the codebase, including the image Markdown fixture in api/tests/unit_tests/core/agent/test_fc_agent_runner.py. The function feeds api/tasks/clean_dataset_task.py:_delete_segments(), clean_document_task.py, and batch_clean_document_task.py; the dataset task passes only extracted IDs to _delete_upload_files() before deleting the segment.
Expected
Recognize the file ID when a valid preview URL has a query string or fragment, while continuing to reject unrelated URLs and malformed schemes. Add a focused regression for both preview routes and signed query parameters.
I searched current issues and open PRs for this cleanup/query-string case and found no matching active fix. This is a source-level finding; I have not run the backend unit suite in this checkout.
There is an existing regression-test location: api/tests/unit_tests/core/tools/utils/test_web_reader_tool.py::test_get_image_upload_file_ids. It currently covers unsigned URLs for both preview routes, an invalid htt:// scheme, and multiple images, but no query strings or fragments. Extending it with signed-query, fragment-only, and query-plus-fragment cases for both routes would target this gap. [1]
For a cleanup-level regression, use an upload referenced only by the inline image, without a source-file reference or attachment binding. The existing inline-image cleanup test shares the same upload across all three roles, so later source-file or attachment cleanup could hide a failed image-ID extraction. Assert that the upload row and blob are deleted along with the segment, using the real extractor. [2] [3]
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
Hi @wzxsdf, thanks for opening this issue.
Why this is being closed
The signed-preview example and cleanup analysis are helpful, but the report does not identify the Dify version or commit, deployment type, or whether the behavior was reproduced in a running deployment. Those fields are needed to verify which environment is affected. The bug report template asks for version, deployment and reproduction details. We are closing this while that context is gathered; this is not a judgment that the underlying observation is incorrect.
Next steps
Please update the report with the missing details, the precise steps and observed versus expected results, and any relevant sanitized logs or test output. If this is a source-only reproduction, please say so explicitly and include the exact commit and how to run it. Then request reopening so the report and linked work can be reviewed.
补充复现信息(仅源码复现;没有运行中的部署,也没有部署日志):
- 受影响源码基线:
langgenius/dify@6b8e067e6690860e76a3622de1021fc3202dc54f。部署类型:无;报告来自该 commit 的源码行为。 - 在该 commit 的仓库根目录、具备 API 开发依赖的 Python 3.13 环境中运行:
PYTHONPATH=api uv run --project api python - <<'PY'
from core.tools.utils.web_reader_tool import get_image_upload_file_ids
content = ""
print(get_image_upload_file_ids(content))
PY
- 基线正则要求
file-preview后直接闭合 Markdown 链接,因此会得到[];预期为['abc123']。这是源码推导的结果,未声称在部署环境执行了命令。 - #46793 包含提取器与清理任务的回归测试;最新提交
0401a3dcb34cc033bbfa54ff13bb7927de3c3391的主 CI、autofix 与 Codecov 均通过。该 PR 后来因缺少本条信息被关闭。
请重新评估此 Issue 与 #46793 是否可重新开放。