[codex] 忽略语义分块中的空标题#836
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the markdown chunking parser to correctly handle empty headings by skipping them and preserving the current title context, and adds a corresponding unit test. The review feedback suggests adding a boundary check when accessing the next token in the stream to prevent a potential IndexError if the token stream is truncated.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| inline_token = tokens[i + 1] | ||
| full_title = inline_token.content.strip() if inline_token.type == "inline" else "" |
There was a problem hiding this comment.
为了确保健壮的防御性编程,并防止在 Token 流格式错误或被截断时发生潜在的 IndexError 崩溃,在获取 inline token 之前,对前瞻索引访问 tokens[i + 1] 进行边界检查会更加安全。
| inline_token = tokens[i + 1] | |
| full_title = inline_token.content.strip() if inline_token.type == "inline" else "" | |
| inline_token = tokens[i + 1] if i + 1 < len(tokens) else None | |
| full_title = inline_token.content.strip() if inline_token and inline_token.type == "inline" else "" |
变更内容
问题原因
HTML 转 Markdown 等处理可能产生空 ATX 标题,例如
###。MarkdownIt 会将其解析为标题节点,但标题内容为空。原实现仍会刷新当前内容并用空字符串更新标题栈,导致后续 Chunk 丢失有效的子标题上下文。影响
仅改变空标题这一退化输入的处理方式;正常非空标题的分块和标题路径行为保持不变。
验证
21 passed, 1 skipped:Semantic 与 RagFlow-like 相关单元测试。git diff --check通过。