Skip to content

fix(ext-document-kreuzberg): mark each PDF page with <!-- page N --> - #5680

Open
kwakayama wants to merge 1 commit into
mainfrom
fix/m125-4946-pdf-page-markers
Open

kwakayama wants to merge 1 commit into
mainfrom
fix/m125-4946-pdf-page-markers

Conversation

@kwakayama

Copy link
Copy Markdown
Contributor

Ingested PDFs now mark each page with an invisible <!-- page N --> comment, so answers can cite a page.

  • Whole-file parses (native, native fallback, WASM worker) ask Kreuzberg for page markers through the shared PDF config.
  • Per-page progress extraction (used by veryfront knowledge ingest) adds the same marker itself. It no longer drops blank pages.
  • N is the page's position in the file, not the printed page label.
  • Tests cover the stubbed progress path and real native (whole-file and progress) and WASM parses of a 3-page PDF with a blank middle page.

Refs veryfront/veryfront-issue-inbox#4946

Ingested PDFs had no page boundaries, so answers could not cite a page.
Whole-file parses now ask Kreuzberg for page markers. Per-page progress
extraction adds the same marker itself and keeps blank pages, so N is
always the page's position in the file.
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 66 371 KiB ✅ 0
src/react/components/Head.tsx 5 74 KiB ✅ 0
src/react/router/index.tsx 5 74 KiB ✅ 0
src/react/context/index.tsx 5 74 KiB ✅ 0
src/react/fonts/index.ts 6 81 KiB ✅ 0
src/react/components/ui/index.ts 111 720 KiB ✅ 0
src/react/components/ui/adapter/contract.ts 1 18 KiB ✅ 0
src/react/components/ui/icons/index.ts 3 17 KiB ✅ 0
src/chat/index.ts 305 2055 KiB ✅ 0
src/chat/ag-ui.ts 61 464 KiB ✅ 0
src/chat/protocol.ts 1 11 KiB ✅ 0
src/chat/types.ts 46 248 KiB ✅ 0
src/chat/message-prep.ts 68 519 KiB ✅ 0
src/markdown/index.ts 6 30 KiB ✅ 0
src/mdx/index.ts 2 2 KiB ✅ 0
src/agent/identity-contracts.ts 1 3 KiB ✅ 0
src/schemas/index.ts 43 222 KiB ✅ 0
src/platform/env.ts 5 55 KiB ✅ 0
src/workflow/claude-code/react/index.ts 9 91 KiB ✅ 0
src/events/index.ts 37 631 KiB ✅ 0
src/events/ag-ui/public.ts 36 624 KiB ✅ 0
src/run-events/index.ts 54 323 KiB ✅ 0

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

Copy link
Copy Markdown
Contributor Author

Review score: 66/100

Focused, well-tested change that makes page markers consistent across the native, WASM, and progress paths. It also breaks the "no extractable text" detection for image-only PDFs.

  • Strength: Sharing one config in extraction-config.ts and splitting off PDF_SINGLE_PAGE_EXTRACTION_CONFIG keeps the whole-file and progress paths aligned. The progress path no longer doubles markers, and the unit test checks that it does not send the pages config.

  • Strength: The tests are good. A blank-middle 3-page fixture runs against the stubbed progress path and against real native (whole-file and progress) and WASM parses. Keeping blank-page markers so N matches the page's position is the right call for citations.

  • Concern (blocker): empty-content detection is bypassed. A PDF with no text layer (scanned or image-only) used to extract to "". It now extracts to <!-- page 1 -->\n\n<!-- page 2 -->.... This content is never empty, so these checks stop firing:

    • cli/commands/knowledge/parser.ts:2755: the content || "_No extractable text found in document._" fallback.
    • src/embedding/upload-handler.ts:327: the !text.trim() check that returns 400 "No text could be extracted from file".
    • src/embedding/rag-store.ts:679, src/embedding/rag-store.ts:728, and src/embedding/veryfront-cloud/rag-store.ts:692: the chunks.length === 0 check. Chunking now returns marker-only chunks.

    As a result, a scanned PDF is silently embedded as marker-only chunks. It is no longer rejected or flagged. The progress path (native-extraction.ts, pages.join) causes this directly. The whole-file Kreuzberg config causes it too, because your blank-page test shows Kreuzberg also emits markers for empty pages.

  • Concern: no regression test for the empty case. No test covers a PDF where every page is blank, so the change above went unnoticed.

  • Minor: assertPageMarkers hard-codes pages 1 to 3 and the fixture text, so it only works with this one fixture. A name like assertThreePageBlankMiddleMarkers makes that clear. You can also pass the expected page texts as a parameter.

Required changes

  1. Treat marker-only output as empty. For example, after extraction, return "" when the content with <!-- page \d+ --> markers and whitespace removed is empty. Do this in the PDF paths of native-extraction.ts (both extractPdfByPage and extractWholeFile), in extractWholeFileWithLoader in index.ts, and in the WASM worker (upload-extraction-worker.ts). A single helper next to pdfPageMarker in extraction-config.ts keeps all these paths consistent.
  2. Add a regression test with an all-blank PDF for the progress, native whole-file, and WASM paths. It must assert that the result is "" (or that the knowledge parser shows its "No extractable text" placeholder).
  3. Optional: check whether markers that end up in standalone chunks change chunk counts or retrieval quality for normal PDFs. Merging a marker into the chunk that follows it keeps the citation attached to its text.

Generated by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T19:41:57.751762Z 0c12f0e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kojiwakayama
kojiwakayama added this pull request to the merge queue Dec 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 4, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant