Skip to content

fix(document-extract): render PDF image fallback per page so multi-page scans don't starve later pages#96390

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
ZengWen-DT:fix/96389-pdf-image-fallback-per-page-budget
Jun 25, 2026
Merged

fix(document-extract): render PDF image fallback per page so multi-page scans don't starve later pages#96390
vincentkoc merged 2 commits into
openclaw:mainfrom
ZengWen-DT:fix/96389-pdf-image-fallback-per-page-budget

Conversation

@ZengWen-DT

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closes #96389.

When a non-native model processes a scanned/image-based PDF, document-extract
extracts no text and falls back to rendering each page to a PNG for vision OCR.
That fallback issued a single clawpdf call:

pdf.extract({ mode: "images", maxPages, image: { maxPixels, ... } })

clawpdf's image renderer applies maxPixels as one budget shared across the
whole call
(remainingPixels is decremented after every page). On a multi-page
scan the first page consumes the budget and later pages are rendered with a
near-zero remaining budget — collapsing them to ~1×1 PNGs. Downstream vision
models then reject them, e.g.:

InternalError.Algo.InvalidParameter: The image length and width do not meet the model restrictions. [height:1...]

Why This Change Was Made

The shared-budget behavior lives in the clawpdf dependency
(node_modules/clawpdf/dist/extract.jsrenderImages), but the right owner
boundary for the fix is how this plugin calls clawpdf: each page in a fallback
render must be a usable image, so the pixel budget is meant to bound per-page
render quality, not be split across pages. Rendering each selected page in its
own extract() call resets remainingPixels per page while keeping clawpdf's
maxPixels/maxDimension capping and forms handling intact (no
reimplementation of the render budget in the plugin).

User Impact

Multi-page scanned/image PDFs now render every selected page at the full
per-page pixel budget instead of starving later pages to degenerate images, so
vision OCR succeeds on the whole document. No config or API surface changes;
single-page behavior is unchanged.

Evidence

Unit tests (extensions/document-extract/document-extractor.test.ts, 7 passing)
updated to assert each fallback page renders in its own extract({ mode: "images", pages: [n], ... }) call with the full per-page budget.

Real-behavior proof against the actual clawpdf 0.3.0 dependency — a 3-page
US-Letter PDF rendered at dpi=200 with maxPixels=1,000,000:

OLD (shared budget, one extract call):
  page 1: 879x1137  (999423 px)
  page 2: 21x27     (567 px)      <- starved
  page 3: 3x3       (9 px)        <- collapsed, rejected by vision models

NEW (per-page extract call):
  page 1: 879x1137  (999423 px)
  page 2: 879x1137  (999423 px)
  page 3: 879x1137  (999423 px)

Test run (worktree-safe runner):

node scripts/run-vitest.mjs extensions/document-extract/document-extractor.test.ts
Test Files  1 passed (1)
     Tests  7 passed (7)

AI-assisted.

@clawsweeper

clawsweeper Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 24, 2026, 7:54 AM ET / 11:54 UTC.

Summary
The branch replaces the document-extract PDF image fallback’s single multi-page clawpdf call with one image extraction call per selected page and updates extractor tests for that call shape.

PR surface: Source +13, Tests +26. Total +39 across 2 files.

Reproducibility: yes. at source level: current main batches fallback image extraction, and published [email protected] shares one remainingPixels budget across pages in that call. The PR body also includes before/after terminal-style output from a real 3-page render.

Review metrics: 1 noteworthy metric.

  • PDF pixel budget semantics: 1 changed. The same maxPixels value now bounds each rendered fallback page instead of the whole image extraction call, which affects resource expectations before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #96389
Summary: This PR is the open candidate fix for the linked scanned-PDF fallback issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Clarify or explicitly accept the per-page maxPixels semantics before merge.

Risk before merge

  • [P2] The same configured maxPixels value now applies once per rendered fallback page instead of once per multi-page extraction call, so multi-page scanned PDFs can produce more total rendered pixels than existing users or operators may expect.

Maintainer options:

  1. Clarify per-page budget semantics (recommended)
    Update PR release context or user-facing PDF/OpenResponses docs so existing maxPixels users understand that total fallback image payload can grow with selected page count.
  2. Preserve an aggregate cap
    If maintainers need the existing whole-document cap, revise the implementation to allocate or enforce a total budget across selected pages while avoiding degenerate later-page images.
  3. Accept the runtime increase
    Maintainers can merge as-is if usable per-page OCR is intentionally more important than preserving the prior aggregate render budget behavior.

Next step before merge

  • [P2] The remaining action is maintainer acceptance or documentation of the changed maxPixels semantics, not a mechanical code repair.

Security
Cleared: The diff only changes TypeScript extractor logic and unit tests; no dependency, workflow, secret, or packaging surface changes were introduced.

Review details

Best possible solution:

Land the plugin-owner fix after maintainers explicitly accept or document the per-page maxPixels semantics for PDF fallback rendering.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: current main batches fallback image extraction, and published [email protected] shares one remainingPixels budget across pages in that call. The PR body also includes before/after terminal-style output from a real 3-page render.

Is this the best way to solve the issue?

Yes, with a merge-safety caveat: per-page extract({ mode: "images", pages: [n] }) keeps page validation and render sizing in clawpdf while fixing starvation. The safer pre-merge state is to document or explicitly accept that maxPixels now behaves as a per-page fallback render budget.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1069c60e1e25.

Label changes

Label justifications:

  • P2: This is a bounded user-visible bug fix for scanned PDF OCR fallback with limited blast radius.
  • merge-risk: 🚨 compatibility: Existing PDF fallback users who treated maxPixels as an aggregate render cap can see larger total image payloads after this per-page rendering change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes before/after terminal-style output from a real 3-page PDF render against [email protected], showing later pages no longer collapse after the fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes before/after terminal-style output from a real 3-page PDF render against [email protected], showing later pages no longer collapse after the fix.
Evidence reviewed

PR surface:

Source +13, Tests +26. Total +39 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 23 10 +13
Tests 1 50 24 +26
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 73 34 +39

What I checked:

Likely related people:

  • steipete: Recent merged PRs switched document-extract to clawpdf and added encrypted-PDF support on the same fallback path. (role: recent area contributor and merger; confidence: high; commits: 75c3b53038af, 73168d37acc7; files: extensions/document-extract/document-extractor.ts, extensions/document-extract/document-extractor.test.ts, src/media/pdf-extract.ts)
  • vincentkoc: Introduced the bundled document-extract plugin and generic document extractor boundary used by this fallback path. (role: feature introducer; confidence: medium; commits: e3cba98f3904; files: extensions/document-extract/document-extractor.ts, src/plugins/document-extractor-types.ts, src/media/pdf-extract.ts)
  • shakkernerd: Recent history includes test-hardening work in the document-extract extractor tests around fallback image assertions. (role: adjacent test contributor; confidence: medium; commits: 2faf2303a133; files: extensions/document-extract/document-extractor.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 24, 2026
ZengWen-DT and others added 2 commits June 25, 2026 16:28
…ge scans don't starve later pages

clawpdf's mode:"images" extract applies a single maxPixels budget across
every page, so the first page consumes it and later pages collapse to ~1x1
PNGs that vision OCR models reject. Render each selected page in its own
extract() call so the pixel budget resets per page and every page yields a
usable image.
@vincentkoc
vincentkoc force-pushed the fix/96389-pdf-image-fallback-per-page-budget branch from 99477c3 to fde3690 Compare June 25, 2026 08:28
@vincentkoc
vincentkoc merged commit d7dff3c into openclaw:main Jun 25, 2026
86 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 26, 2026
…ge scans don't starve later pages (openclaw#96390)

* fix(document-extract): render PDF image fallback per page so multi-page scans don't starve later pages

clawpdf's mode:"images" extract applies a single maxPixels budget across
every page, so the first page consumes it and later pages collapse to ~1x1
PNGs that vision OCR models reject. Render each selected page in its own
extract() call so the pixel budget resets per page and every page yields a
usable image.

* fix(document-extract): preserve aggregate PDF render budget

---------

Co-authored-by: Vincent Koc <[email protected]>
QiuYuang pushed a commit to QiuYuang/openclaw that referenced this pull request Jul 1, 2026
…ge scans don't starve later pages (openclaw#96390)

* fix(document-extract): render PDF image fallback per page so multi-page scans don't starve later pages

clawpdf's mode:"images" extract applies a single maxPixels budget across
every page, so the first page consumes it and later pages collapse to ~1x1
PNGs that vision OCR models reject. Render each selected page in its own
extract() call so the pixel budget resets per page and every page yields a
usable image.

* fix(document-extract): preserve aggregate PDF render budget

---------

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

document-extract fallback mode: "images" renders multi-page scanned PDFs to 1x1 pixels due to clawpdf 4M pixel budget

2 participants