Skip to content

fix(deepdoc): parse bodyless HTML fragments - #16423

Merged
wangq8 merged 10 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/html-parser-fragment-body
Jul 1, 2026
Merged

wangq8 merged 10 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/html-parser-fragment-body

Conversation

@Harsh23Kashyap

@Harsh23Kashyap Harsh23Kashyap commented Jun 28, 2026 •

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Fixes #16422.

RAGFlowHtmlParser.parser_txt always started traversal from soup.body. For HTML fragments without a <body> tag, soup.body is None, so fragment content is not traversed and can be dropped from parsed sections.

This PR falls back to the BeautifulSoup root when no body exists, while keeping full HTML document handling unchanged. It also adds a regression test for a bodyless fragment with a heading and paragraph.

Verification:

  • uv sync --group test
  • uv run pytest test/unit_test/deepdoc/parser/test_html_parser.py -q -> 4 passed
  • uvx ruff check deepdoc/parser/html_parser.py test/unit_test/deepdoc/parser/test_html_parser.py -> All checks passed

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jun 28, 2026
@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

parser_txt now falls back to the BeautifulSoup root when an HTML fragment has no <body> tag, and a unit test verifies that fragment text is extracted.

Changes

Bodyless HTML Fragment Fix

Layer / File(s) Summary
Body fallback and unit test
deepdoc/parser/html_parser.py, test/unit_test/deepdoc/parser/test_html_parser.py
parser_txt uses soup.body or soup as the traversal root and logs when falling back; a new test checks that <h1> and <p> content are extracted from a bodyless fragment.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

ci

Poem

🐇 A fragment hopped in, with no body in sight,
The parser chose soup and made it all right.
# Title appeared, and the text followed through,
A tiny fix for the rabbit crew. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: parsing HTML fragments without a body tag.
Description check ✅ Passed The description explains the bug, the fix, the scope, and verification, though it doesn't use the template's exact Summary heading.
Linked Issues check ✅ Passed The code change matches issue #16422 by falling back to the BeautifulSoup root when body is missing and adding a regression test.
Out of Scope Changes check ✅ Passed The changes are focused on the reported parser bug and its test coverage, with no obvious unrelated additions.

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)
deepdoc/parser/html_parser.py (1)

73-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a debug log when falling back to the BeautifulSoup root.

This introduces a new bodyless-fragment path, but there’s no log when that fallback is taken. That makes it harder to confirm fragment parsing in production/debug traces.

Suggested change
-        root = soup.body or soup
+        root = soup.body or soup
+        if soup.body is None:
+            logging.debug("html_parser: parsing HTML fragment without <body>; falling back to soup root")
         cls.read_text_recursively(root, temp_sections, chunk_token_num=chunk_token_num)

As per coding guidelines, **/*.py: Add logging for new flows.

🤖 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 `@deepdoc/parser/html_parser.py` around lines 73 - 74, Add a debug log in the
HTML parsing fallback path so it’s clear when `HtmlParser` uses `soup` instead
of `soup.body`. Update the `read_text_recursively` call site in `html_parser.py`
to log this branch before invoking `cls.read_text_recursively(...)`, using the
existing parser logger or equivalent logging used elsewhere in
`HtmlParser`/`parse_html_fragment`. Keep the message specific to the
bodyless-fragment fallback so production/debug traces can confirm this path was
taken.

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 `@deepdoc/parser/html_parser.py`:
- Around line 73-74: Add a debug log in the HTML parsing fallback path so it’s
clear when `HtmlParser` uses `soup` instead of `soup.body`. Update the
`read_text_recursively` call site in `html_parser.py` to log this branch before
invoking `cls.read_text_recursively(...)`, using the existing parser logger or
equivalent logging used elsewhere in `HtmlParser`/`parse_html_fragment`. Keep
the message specific to the bodyless-fragment fallback so production/debug
traces can confirm this path was taken.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 214e99c9-08d4-4311-8714-a619643e30a3

📥 Commits

Reviewing files that changed from the base of the PR and between 4712fcb and a55f13b.

📒 Files selected for processing (2)
  • deepdoc/parser/html_parser.py
  • test/unit_test/deepdoc/parser/test_html_parser.py

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Addressed the CodeRabbit logging nit in f3fef3b. I added a debug log for the bodyless-fragment fallback and reran:\n\n- uv run pytest test/unit_test/deepdoc/parser/test_html_parser.py -q\n- uvx ruff check deepdoc/parser/html_parser.py test/unit_test/deepdoc/parser/test_html_parser.py

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Could a maintainer add the required ci label so the workflows can run on this PR?

@yuzhichang
yuzhichang force-pushed the main branch 2 times, most recently from 78db4e9 to f86a0e7 Compare June 29, 2026 01:47
@yuzhichang
yuzhichang force-pushed the Harsh23Kashyap/fix/html-parser-fragment-body branch from f3fef3b to bc5e8e4 Compare June 29, 2026 06:05
Harsh Kashyap added 2 commits June 29, 2026 14:06
HTML snippets without a body tag should still be traversed so fragment content is indexed instead of dropped.

Fixes infiniflow#16422
Record when the HTML parser falls back to the BeautifulSoup root for fragments without a body tag.
@yuzhichang
yuzhichang force-pushed the Harsh23Kashyap/fix/html-parser-fragment-body branch from bc5e8e4 to 4543e5e Compare June 29, 2026 06:06
@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Synced with latest main. Could a maintainer add the ci label so workflows can run? Okay, please review it.

@Harsh23Kashyap
Harsh23Kashyap force-pushed the Harsh23Kashyap/fix/html-parser-fragment-body branch from 66f75b8 to 59ffd94 Compare June 30, 2026 04:49
Harsh Kashyap added 2 commits June 30, 2026 19:14
HTML snippets without a body tag should still be traversed so fragment content is indexed instead of dropped.

Fixes infiniflow#16422
Record when the HTML parser falls back to the BeautifulSoup root for fragments without a body tag.
@Harsh23Kashyap
Harsh23Kashyap force-pushed the Harsh23Kashyap/fix/html-parser-fragment-body branch from 1ae2166 to 1df4bc7 Compare June 30, 2026 13:44
@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Follow-up: branch is current with main (behind_by: 0). CodeRabbit passed; no unresolved review threads. Fork workflows are still skipped until a maintainer adds the ci label. Ready for review when you have a chance.

@wangq8 wangq8 added the ci Continue Integration label Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (828c578) to head (26ee587).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16423   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ 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 merged commit b42414b into infiniflow:main Jul 1, 2026
2 of 3 checks passed
@Harsh23Kashyap
Harsh23Kashyap deleted the Harsh23Kashyap/fix/html-parser-fragment-body branch July 1, 2026 15:06
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 🌈 python Pull requests that update Python code size:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: HTML parser drops fragment content when no body tag exists

2 participants