Skip to content

Fix QA DOCX table parser dropping cells between repeated text - #17497

Merged
xugangqiang merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/qa-docx-colspan-break
Jul 29, 2026
Merged

xugangqiang merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/qa-docx-colspan-break

Conversation

@devYRPauli

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

The merged-cell scan in rag/app/qa.py's Docx handler never stops at the first non-matching cell. The inner loop keeps scanning to the end of the row, so any later, non-adjacent cell that happens to share text with the current one is folded into the colspan, and every cell in between is dropped from the generated HTML.

The same loop exists in three sibling parsers, and all three break out of the scan correctly:

  • rag/app/manual.py
  • rag/app/naive.py
  • rag/app/laws.py

rag/app/qa.py is the only copy missing the else: break. The loops are otherwise identical.

Impact

The most common trigger is blank cells, which routinely repeat within a row. A row like ["Name", "", "Age", ""] renders as:

<td>Name</td><td colspan='2'></td>

Age is gone. The two blank cells are treated as a merged pair even though they are not adjacent, and the real content between them is discarded along with the cells it belonged to.

This HTML is passed to tokenize_table() in the docx chunk() path, so the dropped content is silently absent from what gets indexed and searched. There is no error and nothing in the logs.

Type of change

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

Change

Add the else: break that the three sibling parsers already have.

Verification

Running the row-building loop from qa.py and from manual.py over the same inputs, before and after:

Row qa.py before qa.py after / siblings
Name, "", Age, "" <td>Name</td><td colspan='2'></td> <td>Name</td><td></td><td>Age</td><td></td>
A, B, A, D <td colspan='2'>A</td><td>D</td> <td>A</td><td>B</td><td>A</td><td>D</td>
M, M, X (real merge) <td colspan='2'>M</td><td>X</td> unchanged
Z, Z, Z <td colspan='3'>Z</td> unchanged
a, b, c <td>a</td><td>b</td><td>c</td> unchanged

Genuine adjacent merges and rows without repeated text are unaffected. After the change, qa.py produces byte-identical output to manual.py on every case above.

The merged-cell scan in qa.py's Docx handler does not stop at the first
non-matching cell. It keeps scanning the rest of the row, so any later
non-adjacent cell sharing text with the current one is folded into the
colspan and every cell in between is dropped from the generated HTML.

A row like ["Name", "", "Age", ""] - two blank cells separated by
real content, a very common table shape - renders as

    <td>Name</td><td colspan='2'></td>

losing "Age" entirely. That HTML is what tokenize_table indexes, so the
content is silently missing from search results.

rag/app/manual.py, rag/app/naive.py and rag/app/laws.py all contain the
same loop with an else: break. qa.py is the only copy without it.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Docx table parser now stops calculating a cell span when subsequent cell text differs, preventing incorrect colspan expansion.

Changes

Docx table parsing

Layer / File(s) Summary
Stop span growth on text mismatch
rag/app/qa.py
The table cell-span loop now breaks when adjacent cell text does not match.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: euvre

Poem

A rabbit spots a table’s trail,
Where matching cells may span the vale.
A mismatch hops into the scene,
And stops the span from growing green.
“Neat columns!” cheers the hare.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the DOCX table parser bug fix.
Description check ✅ Passed The description includes the problem, impact, change, and verification, exceeding the template requirements.
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)
rag/app/qa.py (1)

232-233: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a regression test for rag.app.qa.Docx.

The new break is correct, but the supplied test exercises rag.app.laws.Docx and only verifies adjacent identical cells. Add a focused QA-parser test covering A, B, A and blank cells separated by another value, while retaining the adjacent-merge assertion.

As per coding guidelines, preserve still-valid behavior with focused tests.

🤖 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 `@rag/app/qa.py` around lines 232 - 233, Add a focused regression test for
rag.app.qa.Docx covering non-adjacent repeated cells in the A, B, A pattern and
blank cells separated by another value, while retaining the existing assertion
for adjacent identical-cell merging; ensure the test targets the QA parser
rather than rag.app.laws.Docx.

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 `@rag/app/qa.py`:
- Around line 232-233: Add a focused regression test for rag.app.qa.Docx
covering non-adjacent repeated cells in the A, B, A pattern and blank cells
separated by another value, while retaining the existing assertion for adjacent
identical-cell merging; ensure the test targets the QA parser rather than
rag.app.laws.Docx.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02fc8739-12e5-4c12-a023-e1d7403eb3b0

📥 Commits

Reviewing files that changed from the base of the PR and between 75836cf and 5a43bdb.

📒 Files selected for processing (1)
  • rag/app/qa.py

@yingfeng
yingfeng requested a review from xugangqiang July 29, 2026 08:39
@yingfeng yingfeng added the ci Continue Integration label Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (75836cf) to head (5a43bdb).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17497      +/-   ##
==========================================
- 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.

@xugangqiang

Copy link
Copy Markdown
Contributor

LGTM

@xugangqiang
xugangqiang merged commit 33bfc11 into infiniflow:main Jul 29, 2026
11 of 12 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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants