Repository navigation
[ENG-20522] fix(pdf): large plan sets read nothing past the page cap and scans get no page images - #265
Closed
orswn wants to merge 3 commits into
Closed
[ENG-20522] fix(pdf): large plan sets read nothing past the page cap and scans get no page images#265orswn wants to merge 3 commits into
orswn wants to merge 3 commits into
Conversation
The pdf tool treated agents.defaults.pdfMaxPages as a cap on the page number, not on the page count. With the fleet value of 120, pages="200-300" parsed to an empty list, extraction was skipped, and the pdf model got the prompt with no document content and no error. On a 922-page set every call for pages above 120 came back as "I don't see any pages". Make pdfMaxPages a per-call page count. Any page number can be requested; the first pdfMaxPages requested pages are read and the rest are reported with the exact pages= value for the next call. Pages past the document end are clipped after the first batch and named in the coverage text instead of producing empty chunks. When no requested page exists in any file, return a tool input error that names the page count. With pages set, extraction now runs before the image model fallback, so a page-selection or extraction error is not retried per model or reported as a model outage; the extraction error keeps its cause text. Scanned sheets with an OCR text layer passed the 200-character text check, so they never got page images and the model read their OCR text as if it were exact. Detect pages whose text is mostly invisible (render mode 3 or 7, at least 30% of 50 or more characters) from the PDFium text page. When the caller opts in with ocrPageImages, render those pages as images within the existing per-batch pixel budget, drop renders whose longest side is under 1000 px, and label the pages in the chunk text, coverage instruction, and result text. Pages with no usable image carry the no-absence-claims instruction even when coverage is complete. Only the pdf tool opts in; OpenResponses input_file extraction is unchanged. The detector uses clawpdf engine internals behind a feature check and never throws; an unmocked test with generated PDFs fails if a clawpdf upgrade removes them. This diverges from upstream, which still caps by page number. Refs: ENG-20522
There was a problem hiding this comment.
cubic analysis
All reported issues were addressed across 19 files
Linked issue analysis
Linked issue: ENG-20522: OpenClaw pdf tool: large plan sets stop at the page cap and never send page images for OCR-layer scans
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Read requested pages beyond the per-call page limit | pdf-tool.ts reads requested page numbers and reports skipped ranges with the exact pages value for the next call. |
| ✅ | Send scanned OCR pages as images or label their text | The extractor detects invisible OCR text, attaches readable page images when possible, and labels OCR pages in the model context. |
| Keep the pdf-coverage-integrity regression scenario green | The PR reports related test shards passing, but the diff does not show this named regression scenario running. |
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
- Reject page numbers outside the safe-integer range. A range such as 9007199254740992-9007199254741000 never advanced and blocked the tool. - Give a read without pages the same continuation line as an explicit range when the document is longer than the page limit, e.g. pages="121-240". - For a text-only model, drop ocrImagePages together with the images, so the OCR note and the no-absence-claims instruction match what the model received. - Classify OCR pages one at a time, so a page that fails to load drops only its own label. - Say in the tool description, config help, and docs that the page limit applies to each PDF in a call, which is what the tool does. - Remove a wall-clock assertion from a parser test and assert that the OCR page image reaches the model. Refs: ENG-20522
There was a problem hiding this comment.
All reported issues were addressed across 12 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
The coverage note for pages skipped by the per-call limit tells the reader to "Call pdf again with pages=...". The same note also went into the prompt of the pdf analysis model, which has no tools. In a live run on a 300-page set with no `pages`, that model wrote a fake pdf call and then invented page text for pages 121-230. The agent reported the invented sheets as read. Tell the analysis model that the skipped pages were not provided and must not be described. Keep the continuation hint in the tool result, where the agent can act on it. Refs: ENG-20522
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: ENG-20522
What Problem This Solves
Fixes an issue where the agent's
pdftool returned no content for large plan sets when it asked for pages above the page limit, and where scanned sheets with an OCR text layer reached the model as plain text with no page image.agents.defaults.pdfMaxPages = 120,pages="200-300"read nothing. The model then answered "I don't see any pages". On one host, 13 calls for pages above 120 on a 922-page set all came back empty, and none was marked as an error.pagesstops at page 120. The coverage note said "processed pages 1-120 of 793" but did not say how to read the rest.Why This Change Was Made
pdfMaxPagesnow limits how many pages one call reads, not which page numbers it can read.pdfMaxPagesrequested pages are read.pages=value for the next call.ocrPageImages. Those pages are rendered within the existing per-batch pixel budget. Renders with a longest side under 1000 px are dropped because they cannot be read.input_fileextraction does not opt in, so its output does not change.parsePageRangeon the next upstream sync.User Impact
pdfMaxPagespages per call, and gets told how to continue.pageson vector PDFs return the same output as before.Evidence
Classifier on real plan sets (all pages, real clawpdf):
ocrPages1-10,ocrImagePages[1].Tests and checks:
node scripts/run-vitest.mjson the 18 related test files: all shards pass. These include the pdf tool, helpers, document-extract extractor and OCR detector, media plumbing, input-files, OpenResponses file-only, and config schema help.run-tsgolanes core, extensions, core-test, extensions-test: exit 0.run-oxlinton changed core files andextensions/document-extract: exit 0.oxfmt --check: clean.generate-config-doc-baseline --check: OK.git diff --check: clean.Live agent smoke: pending, added below when complete.
Summary by cubic
Fixes the
pdftool so requests past the 120-page default read actual pages instead of nothing, and scanned sheets with OCR text layers reach the model as labeled page images.Page limiting
pdfMaxPagesnow caps how many pages one call reads, not which page numbers; any page can be requested and the firstpdfMaxPagesrequested pages are read.pages=value for the next call, including when nopagesis given and the document exceeds the limit. Pages past the document end are clipped and reported. The continuation hint stays in the tool result only; the analysis model has no tools and is instead told the skipped pages were not provided and must not be described, so it cannot invent their content.parsePageRangeon the next upstream sync.OCR page detection
ocrPageImagesfield; those pages are rendered within the existing pixel budget and renders under 1000 px on the longest side are dropped.ocrImagePagesis dropped along with the images so the notes match what the model received.input_fileextraction is unchanged.Written for commit 6d4595a. Summary will update on new commits.