DeepTutor icon indicating copy to clipboard operation
DeepTutor copied to clipboard

[Bug]: Legacy Office formats (.doc/.xls/.ppt) pass upload validation but the extractor cannot parse them — uploads yield no text and IMA retrieval returns content_unavailable

Open plmn638 opened this issue 1 month ago • 5 comments

Do you need to file an issue?

  • [x] I have searched the existing issues and this bug is not already filed.
  • [x] I believe this is a legitimate bug, not just a question or feature request.

Describe the bug

Legacy Office formats are accepted by upload validation but cannot be text-extracted anywhere, so they silently produce no evidence:

  • deeptutor/utils/document_validator.py (ALLOWED_EXTENSIONS) accepts .doc, .xls, .ppt, .rtf (and the matching legacy MIME types such as application/msword);
  • but deeptutor/utils/file_types.py defines OFFICE_EXTENSIONS = {".docx", ".xlsx", ".pptx"}, and SUPPORTED_DOC_EXTENSIONS in deeptutor/utils/document_extractor.py (parser + text-like sets) therefore lacks .doc — there is no decoder for the legacy binary formats at all.

Live wire evidence from a connected Tencent IMA library holding legacy .doc files (this surfaces as a retrieval failure on top of #2326 / PR #2332):

  1. search_knowledge matches the documents: media_type: 3, media id word_41c6****…, item title ending in .doc;
  2. get_media_info returns a valid COS url_info (host skb.ima.myqcloud.com, inside the trusted allowlist) and the download succeeds — ~235 KB, first bytes d0 cf 11 e0 a1 b1 1a e1 (OLE2 compound document = genuine legacy Word);
  3. the download's own filename is a hash with .doc (01988e06….doc), and the item title also ends .doc;
  4. _extractable_filename() in deeptutor/services/rag/pipelines/ima/media.py only accepts SUPPORTED_DOC_EXTENSIONS → returns "";
  5. extract_text → "" → hydration records {'source_id': 'word_41c6****', 'error_type': 'content_unavailable'};
  6. under the #1500 policy every match is dropped → retrieval_status: "content_unavailable" with zero sources, even though the bytes were fetched fine and the same library's .docx documents extract correctly end-to-end.

So the bytes are good; only the extension gate blocks extraction. The same mismatch applies to any .doc uploaded directly to a knowledge base or attached to chat: validation passes, extraction yields nothing (KB indexing logs the document as failed/no text, chat gets no content) — with no error explaining why.

Steps to reproduce

  1. Upload a legacy .doc file to any knowledge base (or attach it to a chat): validation accepts it (application/msword is in the allowed MIME set), but no text is ever extracted.
  2. Connect a Tencent IMA knowledge base that contains legacy .doc files and search for a keyword matching them.
  3. Observe retrieval_status: content_unavailable, hydration_failures entries with error_type: content_unavailable for the word_* media ids, zero sources — while the same library's .docx files retrieve and hydrate normally.

Expected Behavior

Either:

  • extract the legacy formats (e.g. an optional LibreOffice/soffice --headless --convert-to fallback, or a maintained pure-Python OLE2 parser), or
  • reject/warn at validation time so an unextractable format cannot silently produce empty evidence.

For the IMA path specifically, hydration_targets could also skip extensions that can never extract, so they don't consume the 4-document hydration budget ahead of extractable documents (same budget-crowding concern as #2326).

Related Module

Knowledge Base Management

Configuration Used

Source checkout, default document parsing settings, IMA engine connected via the Knowledge page. Credential values redacted.

Logs and screenshots

Wire sample and diagnostics included above (identifiers masked). Server log shows Could not load IMA media 'word_…' (content_unavailable) warnings for every matched legacy document.

Additional Information

  • DeepTutor Version: 1.7.0 (verified current main has the same OFFICE_EXTENSIONS / validator sets)
  • Operating System: Windows 11
  • Python Version: 3.12
  • Node.js Version: (web not involved)
  • Browser (if applicable): N/A (backend extraction/retrieval path)
  • Related Issues: #2326 (IMA folder matches — the fix in PR #2332 surfaced this second layer), #1500 (drop-unreadable-matches policy)

plmn638 avatar Nov 02 '26 05:11 plmn638

The IMA trace makes this one concrete, thanks. Before anyone writes code, which direction would you prefer, @pancacake?

(a) Make upload validation match what can be extracted: drop .doc, .xls, .ppt and .rtf (and their legacy MIME types) from ALLOWED_EXTENSIONS, with an error suggesting conversion to .docx/.xlsx/.pptx, and have the IMA path skip them with a logged reason instead of returning empty text. (b) Add extraction for the legacy formats, which needs a new parser dependency.

(a) is small and adds no dependencies. I'm happy to do either.

NishilRathod avatar Nov 02 '26 05:11 NishilRathod

The trace already isolates the extension-gate mismatch well. One additional boundary worth preserving in either option is per-file evidence coverage, especially for mixed uploads and IMA batches:

  • Derive admission from the capabilities of the configured extraction backend, rather than maintaining a second static extension list. If an optional legacy converter is later enabled, the accepted set and the extractor set should change together.
  • Keep unsupported_format, empty_extraction, and download_failed as distinct outcomes, with the source id and detected format attached. A downloaded OLE2 file that cannot be decoded is not equivalent to an empty document.
  • Return an explicit batch receipt such as matched / hydrated / indexed / skipped_unsupported / failed; a response with zero usable sources should not look like an ordinary no-match result.

A small regression matrix could cover both direct upload and IMA with: one valid .docx, one genuine OLE2 .doc, one empty-but-supported file, and one download failure. Assert that unsupported files fail loudly (or convert successfully if that option is chosen), never consume the usable-document budget, and never become empty evidence. It would also be useful to sniff OLE2/ZIP magic bytes so a renamed extension does not bypass the same boundary.

This keeps the immediate fix compatible with option (a), while leaving a clean capability contract for option (b).

zeweihan avatar Nov 02 '26 06:11 zeweihan

Good point on (1). Deriving ALLOWED_EXTENSIONS (and the legacy MIME types) from what the extractor actually supports keeps the two from drifting again, and it would slot straight into option (a) without a second static list. I'd keep the outcome taxonomy and batch receipts (2–3) as a follow-up, since they change what the IMA path returns. @pancacake, does (a) built this way work for you?

NishilRathod avatar Nov 02 '26 06:11 NishilRathod

One architectural fact that should shape (a): extraction capability in this codebase is already engine-plural. The KB ingestion path runs through the parsing-engine service with per-engine format sets — docling, liteparse and tika all list .doc/.docm (services/parsing/engines/{docling,liteparse,tika}/formats.py), while mineru, markitdown and text_only do not. With a Tika/Docling/LiteParse engine configured, a .doc upload parses today.

So "derive admission from what the extractor supports" needs to be per surface, or (a) regresses a real capability:

KB upload/ingestion: derive admission from the parsing-engine union (engines/formats.py already computes it) — .doc stays admitted where it genuinely parses, and the validator can never drift from the engines again. Chat attachments & IMA hydration: both are hard-bound to document_extractor today; their admission should match SUPPORTED_DOC_EXTENSIONS (reject .doc with a conversion hint). Routing them through the engine service would be the natural step toward (b) later. IMA hydration: skip non-extractable ids with a logged reason, and adopt the proposed outcome taxonomy — right now media.py::_extractable_filename returning "" conflates "download failed", "unsupported format" and "empty text" into one content_unavailable. This also scopes my original report: "uploads yield no text" holds for the default text_only path; Tika/Docling/LiteParse-configured KBs extract .doc today. The @pancacake question then becomes: confirm (a) with per-surface derivation, taxonomy + receipts as the follow-up.

plmn638 avatar Nov 02 '26 10:11 plmn638

Fixed on local dev (8ecf2da95f98305d861245b20836af23e006ed63). fix(parsing): validate uploads against available parser formats. 212 Python regressions passed.

will be fixed in the next releases!

pancacake avatar Nov 14 '26 17:11 pancacake