Skip to content

fix(api): return an empty preview when a document yields no QA chunks - #45089

Open
BlueX888 wants to merge 6 commits into
langgenius:mainfrom
BlueX888:fix/qa-preview-empty-documents
Open

BlueX888 wants to merge 6 commits into
langgenius:mainfrom
BlueX888:fix/qa-preview-empty-documents

Conversation

@BlueX888

@BlueX888 BlueX888 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #45087

Summary

The preview branch of QAIndexProcessor.transform() indexed all_documents[0] without checking that the split produced any chunks. A source with zero chunks — whitespace-only text, a blank/no-text PDF, or a URL-sourced image whose images are not persisted — therefore raised IndexError, which the indexing-estimate adapter surfaced as HTTP 500 Knowledge indexing estimate failed: list index out of range instead of an empty preview.

  • Guard the preview on a non-empty chunk list, matching paragraph-mode preview and non-preview QA indexing, and add a regression test for an empty document.

Screenshots

Not a UI change.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues.
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
    • On current main (3e2df10), the new tests fail with IndexError: list index out of range; with this change the full test_qa_index_processor.py is 23/23, and pyrefly strict checking plus ruff check/ruff format --check are clean.
    • Extra routes verified: documents=[], splitter returning no nodes, mixed sources, non-preview empty; the real IndexingEstimateAdapter returns total_segments=0, preview=[], qa_preview=[]. Related suites 108 pass; ruff check, ruff format --check clean.
  • I've updated the documentation accordingly.

From Claude Code

The preview branch of QAIndexProcessor.transform indexed all_documents[0]
without checking that the split produced any chunks. A whitespace-only text,
a blank/no-text PDF, or a URL-sourced image document therefore raised
IndexError, which the indexing-estimate adapter surfaced as HTTP 500
'Knowledge indexing estimate failed: list index out of range' instead of an
empty preview.

Guard the preview on a non-empty chunk list, matching paragraph-mode preview
and non-preview QA indexing, and add a regression test for an empty document.

Co-Authored-By: Claude Code <[email protected]>
@BlueX888
BlueX888 requested a review from JohnJyong as a code owner October 29, 2026 21:28
The other zero-chunk route is an empty extracted document list; the preview
guard covers it through the same non-empty check. Pin it with a regression
test, which fails with IndexError on the pre-fix code.

Co-Authored-By: Claude Code <[email protected]>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 85.69% 85.69% +0.00%
Strict coverage 85.35% 85.35% +0.00%
Typed symbols 91,483 91,493 +10
Untyped symbols 15,341 15,341 0
Modules 4526 4526 0

@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.41%. Comparing base (ab7f0f5) to head (34af1d4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #45089   +/-   ##
=======================================
  Coverage   90.41%   90.41%           
=======================================
  Files        6334     6334           
  Lines      396668   396669    +1     
  Branches    79710    79711    +1     
=======================================
+ Hits       358628   358633    +5     
+ Misses      31933    31930    -3     
+ Partials     6107     6106    -1     
Flag Coverage Δ
api 90.11% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: QA chunk preview returns HTTP 500 (IndexError) for sources with zero chunks

1 participant