Skip to content

fix(translate): keep pages with no text instead of failing the run - #137

Merged
TranBaDat2607 merged 1 commit into
mainfrom
fix/keep-textless-pages
Oct 23, 2026
Merged

TranBaDat2607 merged 1 commit into
mainfrom
fix/keep-textless-pages

Conversation

@TranBaDat2607

Copy link
Copy Markdown
Owner

Why

Translating a document that has even one page with no text failed the whole job:

Translation failed — BabelDOC chunk 2 failed: The document contains no paragraphs.

  • BabelDOC raises ExtractTextError on a chunk with no paragraphs, and a chunk is one page. So one blank, scanned or image-only page ends the run.
  • Understanding Distributed Systems (346 pages) has 37 empty pages, starting with page 2, so translating it whole failed 4 s in, every time.

Why it was still happening: this fix was written on 2026-10-22 (14092cf), but it only ever lived on the unmerged fix/skip-textless-pages and fix/release-freed-memory branches. No PR was opened for either, so main and every build since never had it. This PR ports it onto current main (processor.py had moved under it) and re-verifies it.

What changes

  • pdf_pages.pages_without_text screens the selected pages before BabelDOC runs. A page with nothing but whitespace is kept as the original and spared a whole pipeline run.
  • A backstop in run_one_chunk: an ExtractTextError from BabelDOC (BabelDOC passes the exception object itself) marks that chunk skipped instead of failing the run. This covers text BabelDOC still can't use, such as its "too many CID paragraphs" refusal for garbled fonts.
  • A skipped page still emits chunk_ready. It re-sends the latest rolling path rather than rebuilding it, so "N of M pages" reaches M and the viewer's mask lifts without a reload (maskAfterArtifact widens the mask for an unchanged path).
  • ETA: skipped pages are left out of the rate.
  • A run where every selected page is textless is an error ("None of the selected pages has text to translate…"), never a copy of the source labelled translated.

Test plan

  • pytest tests: 1432 passed (+7). The screen's tests were seen red against two stubs, one finding no page and one finding every page, before the real helper. ruff clean.

  • Real pipeline, Argos, PyMuPDF 1.25.5 (this branch's pin). processor.py has no unit harness, so these runs are the check:

    pages on main with this PR
    1–5 failed, 0 pages finishes 5/5; blank 2 and 4 unchanged
    27–31 failed finishes; blank 28 and 30 kept, the "Part I" title page translated
    2 alone failed the "None of the selected pages has text" error
  • Backstop: with BabelDOC reporting ExtractTextError for one of three pages, that page is kept as the original and the run finishes.

  • Whole 346-page book in pnpm tauri dev, together with fix(translate): stop the sidecar's RAM climbing with every translated page #136.

Conflicts with #136: both PRs touch processor.py's consumer loop, CLAUDE.md and translation-pipeline.md. Whichever merges second needs a small rebase.

🤖 Generated with Claude Code

BabelDOC raises ExtractTextError ("The document contains no paragraphs.")
on a chunk with no text, and a chunk is one page, so one blank, scanned
or image-only page ended the whole translation as "BabelDOC chunk N
failed". A 346-page book has 37 empty pages, the first of them page 2,
so translating it whole failed four seconds in, every time.

This fix was written on 2026-10-22 (14092cf) but only ever lived on the
unmerged fix/skip-textless-pages and fix/release-freed-memory branches;
no PR was opened, so main never had it. Ported here onto current main.

pdf_pages.pages_without_text screens the selected pages before BabelDOC
runs, sparing them a whole pipeline run; catching ExtractTextError in
run_one_chunk is the backstop for pages with text BabelDOC still can't
use, such as its "too many CID paragraphs" refusal. A skipped page still
emits chunk_ready, re-sending the latest rolling path rather than
rebuilding it, and a run in which every selected page is textless is an
error, not a copy of the source labelled translated.

Re-verified on this branch (PyMuPDF 1.25.5, Argos, the real pipeline):
pages 1-5 of the book failed on main with 0 pages done and now finish
5/5 with pages 2 and 4 unchanged; pages 27-31 finish with the blank 28
and 30 kept and the "Part I" title page translated; page 2 alone is the
"None of the selected pages has text" error; and an ExtractTextError
reported for one of three pages keeps that page and finishes the run.
The screen's 7 tests were seen red against two stubs (one finding no
page, one finding every page) before the real helper.

(cherry picked from commit 14092cf)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TranBaDat2607
TranBaDat2607 merged commit 67de51a into main Oct 23, 2026
6 checks passed
@TranBaDat2607 TranBaDat2607 mentioned this pull request Oct 23, 2026
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