Skip to content

Understanding directory - #4439

Open
ShaoZegangByte wants to merge 10 commits into
mainfrom
understanding_directory
Open

Understanding directory#4439
ShaoZegangByte wants to merge 10 commits into
mainfrom
understanding_directory

Conversation

@ShaoZegangByte

@ShaoZegangByte ShaoZegangByte commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Description

支持普通目录和 HTML 页面目录按文件使用 UnderstandingAPI 解析。复用 ParserRouter,根据 parser_api.extensions 为每个入选文件选择解析后端,并补充并发限制、失败详情、空解析产物清理,以及导入失败后新预占空目标的清理。

覆盖本地目录、内置 ZipParser 展开的目录 ZIP,以及 HTTPAccessor/WebImporter 物化的 HTML 页面目录。关闭 parser_api.enable 或扩展名未命中时,仍走原生解析;不修改网页抓取流程。

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

兼容性说明:新增目录默认上限为 1000 个入选文件、10 层深度,超过时拒绝导入,可通过 parsers.directory 调整。这些限制同样适用于原生解析,因此标记为行为兼容性变更;没有移除或重命名公开 API 参数。

Changes Made

  • 复用 ParserRouter 逐文件路由,保留过滤和目录结构;命中 Understanding 时提前拒绝 no_split
  • 目录默认限制 1000 个文件、10 层深度;同一事件循环内多个目录共享最多 4 个 Understanding 调用。
  • 部分失败时保留成功内容,返回 meta.failed_files,保留真实错误原因和远端 ID。
  • 无成功产物时报错并清理临时目录;失败或取消时,持锁尝试清理被标记为本次新预占且仍为空的目标,不删除本地源目录。
  • 修复 ZIP 中文文件名读取问题,补充回归测试及中英文文档。

Testing

  • I have added tests that prove my fix is effective or that my feature works

  • New and existing unit tests pass locally with my changes

  • I have tested this on the following platforms:

    • Linux
    • macOS
    • Windows
  • 目录过滤、阈值、共享并发、HTML 路由、Understanding 错误处理、原生解析回退、飞书、异步任务及 temp-upload 接口等 21 个测试文件:554 passed,4 个 Pydantic 既有弃用警告

  • 清理相关回归覆盖:空产物不创建合并目标、全失败时清理聚合临时目录、已有目标不标记清理、非空目标不删除,以及 file_id 任务返回错误或抛出异常时按标记清理。补充 6 个组合用例验证错误原因、远端 ID 和清理行为。

  • 当前 PR 相对主干的 22 个 Python 文件执行 ruff check:通过。

  • 同一批 22 个 Python 文件执行 ruff format --check:通过;合并核对还覆盖了双方涉及的全部 27 个 Python 文件。

  • 相对两个合并父版执行 git diff --check:通过;已核对双方改动保留情况。

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

  • 并发上限仅在同一事件循环内的目录任务间共享,不是跨进程或跨实例的全局上限。
  • Understanding 错误处理、ZIP 文件名修复和失败目标清理属于共享组件,也影响其他复用入口;未新增飞书目录专用逻辑。
  • 已知边界:显式目标仍先检查是否存在、再获取树锁;另一请求在间隙创建同一实际目标时,清理归属判断仍有竞争窗口。
  • ZIP 解压前资源预算、原生空 HTML 生成空 Markdown 不在本次修复范围;空产物检查依据可合并文件是否存在,不检查 Markdown 正文是否非空。

@qin-ctx qin-ctx 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.

目录逐文件路由到 Understanding 的方向合理。本次 review 有一个必须在合并前解决的问题:嵌套 ZIP 的子文件失败详情会被外层聚合丢掉;另外提示一下,嵌套 ZIP 也会重置目录文件数和深度限制。

include=kwargs.get("include"),
exclude=kwargs.get("exclude"),
additional_can_process=parser_router.should_use_understanding_api,
max_files=directory_config.max_files,

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.

[Bug] (non-blocking)

嵌套 ZIP 会让一次目录导入绕过 max_filesmax_depth。外层扫描只把每个 .zip 计为一个入选文件;处理 ZIP 时,ZipParser 解压后会重新创建 DirectoryParser,文件数和深度从零开始计算。

例如 max_files=1000,目录里有两个 ZIP,每个 ZIP 各包含 1000 个 PDF。外层以 2 个文件通过,这两个内层扫描也分别以 1000 个文件通过,最终一次导入会提交 2000 个 Understanding 任务。连续嵌套 ZIP 同样会重置深度。嵌套 ZIP 是 ZipParser 明确支持的正常输入,因此这与文档所说的“一次目录在发起 Understanding 请求前完成完整预检”不一致。

请确认这里的限制预期是约束一次逻辑导入,还是每次递归 Parser 调用;是否处理、怎么处理由你决定。

}
meta = detail.get("meta")
if isinstance(meta, dict):
for key in (

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.

[Bug] (blocking)

嵌套 ZIP 中有文件解析失败时,最终结果会把失败信息全部丢掉,只报告这个 ZIP 成功。

例如目录里有 bundle.zip,其中 good.md 成功,bad.pdf 的 Understanding 请求失败。内层 DirectoryParser 会保留 good.md,并在自己的 meta.failed_files 中记录 bad.pdf 的错误和远端 ID。ZipParser 原样返回这份结果,外层 _process_single_file 也把内层 meta 放进了文件状态;但这里构造外层状态时只复制 doc_namefile_idresponse_id 等单文件字段,没有继续传递内层 failed_files

最终外层只记录 bundle.zip 已处理成功,meta.failed_files 为空。用户不知道 bad.pdf 没有导入,也拿不到排查远端任务所需的 ID。这违反了本 PR 对目录部分失败返回详情的说明。

这个问题需要在合并前解决。请确认嵌套 ZIP 的叶子失败是否属于 meta.failed_files 契约;如果不属于,请说明受支持的嵌套 ZIP 为什么可以在子文件失败时只报告整体成功。具体怎么处理由你决定。

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants