Support dense CAD content streams - #421
Conversation
Raise the bounded page operator budget to two million so valid CAD pages with roughly 1.3 million operations retain their text. Pages above the safety budget now report a dedicated content_operation_limit OCR reason instead of looking like an empty text page.
There was a problem hiding this comment.
All reported issues were addressed across 8 files
Shadow auto-approve: would not auto-approve because issues were found.
Fix all with cubic | Re-trigger cubic
Report budget-skipped pages in pages_needing_ocr without marking the document as encoding-corrupted, and document where the page-level reason is exposed.
|
Addressed in 4229cf6:
Validation: full |
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="napi/README.md">
<violation number="1" location="napi/README.md:97">
P3: This statement sits in the `extractTextInRegions` section, but that function returns `PageRegionTexts[]`, which has no `ocrReasonsByPage` field — `ocrReasonsByPage` exists only on the `OcrPdfResult` returned by `processPdfWithOcr`. A reader of the region-extraction docs cannot find the reason in that result. Move the `content_operation_limit` note to the `processPdfWithOcr` section (next to `ocrReasonsByPage`) or state explicitly that the page-level reason is exposed only through `processPdfWithOcr`/`processPdf`, not `extractTextInRegions`.</violation>
</file>
Shadow auto-approve: would not auto-approve because issues were found.
Fix all with cubic | Re-trigger cubic
| Extract text within bounding-box regions from a PDF. Designed for hybrid OCR pipelines where a layout model detects regions in rendered page images, and this function extracts text from the PDF structure for text-based pages — skipping GPU OCR. | ||
|
|
||
| Each region result includes a `needsOcr` flag that signals unreliable extraction (empty text, GID-encoded fonts, garbage text, encoding issues). When the cause is a suspected garbled text layer, `ocrReason` is set to `"suspected_garbled_text"`. | ||
| Each region result includes a `needsOcr` flag that signals unreliable extraction (empty text, GID-encoded fonts, garbage text, encoding issues). Known region causes are exposed in `ocrReason`; for example, a suspected garbled text layer reports `"suspected_garbled_text"`. A page skipped by the content-stream safety budget reports `"content_operation_limit"` in the page-level `ocrReasonsByPage` result. |
There was a problem hiding this comment.
P3: This statement sits in the extractTextInRegions section, but that function returns PageRegionTexts[], which has no ocrReasonsByPage field — ocrReasonsByPage exists only on the OcrPdfResult returned by processPdfWithOcr. A reader of the region-extraction docs cannot find the reason in that result. Move the content_operation_limit note to the processPdfWithOcr section (next to ocrReasonsByPage) or state explicitly that the page-level reason is exposed only through processPdfWithOcr/processPdf, not extractTextInRegions.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At napi/README.md, line 97:
<comment>This statement sits in the `extractTextInRegions` section, but that function returns `PageRegionTexts[]`, which has no `ocrReasonsByPage` field — `ocrReasonsByPage` exists only on the `OcrPdfResult` returned by `processPdfWithOcr`. A reader of the region-extraction docs cannot find the reason in that result. Move the `content_operation_limit` note to the `processPdfWithOcr` section (next to `ocrReasonsByPage`) or state explicitly that the page-level reason is exposed only through `processPdfWithOcr`/`processPdf`, not `extractTextInRegions`.</comment>
<file context>
@@ -94,7 +94,7 @@ console.log(result.confidence) // 0.875
Extract text within bounding-box regions from a PDF. Designed for hybrid OCR pipelines where a layout model detects regions in rendered page images, and this function extracts text from the PDF structure for text-based pages — skipping GPU OCR.
-Each region result includes a `needsOcr` flag that signals unreliable extraction (empty text, GID-encoded fonts, garbage text, encoding issues). Known causes are exposed in `ocrReason`; for example, a suspected garbled text layer reports `"suspected_garbled_text"`, and a page skipped by the content-stream safety budget reports `"content_operation_limit"`.
+Each region result includes a `needsOcr` flag that signals unreliable extraction (empty text, GID-encoded fonts, garbage text, encoding issues). Known region causes are exposed in `ocrReason`; for example, a suspected garbled text layer reports `"suspected_garbled_text"`. A page skipped by the content-stream safety budget reports `"content_operation_limit"` in the page-level `ocrReasonsByPage` result.
```typescript
</file context>
| Each region result includes a `needsOcr` flag that signals unreliable extraction (empty text, GID-encoded fonts, garbage text, encoding issues). Known region causes are exposed in `ocrReason`; for example, a suspected garbled text layer reports `"suspected_garbled_text"`. A page skipped by the content-stream safety budget reports `"content_operation_limit"` in the page-level `ocrReasonsByPage` result. | |
| Each region result includes a `needsOcr` flag that signals unreliable extraction (empty text, GID-encoded fonts, garbage text, encoding issues). Known region causes are exposed in `ocrReason`; for example, a suspected garbled text layer reports `"suspected_garbled_text"`. A page skipped by the content-stream safety budget is reported via `processPdfWithOcr`/`processPdf`, which exposes `"content_operation_limit"` in the page-level `ocrReasonsByPage` result. |
Summary
content_operation_limitOCR reason when a page is skipped by that budget, instead of making it indistinguishable from a genuinely empty page.Fixes #307.
Rationale
The existing bounded decoder protects against unbounded operation allocation, but the one-million threshold also rejects real CAD/Revit pages containing native text. The issue reports valid pages at approximately 1.07M and 1.31M operators. A two-million ceiling covers those documents while retaining a finite allocation guard.
The new reason is also deliberately distinct from
no_text: callers can tell that extraction was stopped by the safety budget and choose an appropriate fallback.Testing
cargo testcargo clippy -- -D warnings— passescargo fmt --all -- --check— passesgit diff --check— passesThe optional OCR runtime suites were not run locally; this change does not alter OCR runtime code.
Summary by cubic
Supports dense CAD/Revit PDFs by doubling the content-stream operator budget and emitting a dedicated OCR reason when the limit is hit. Previously, pages over 1,000,000 operators looked like empty text and could imply encoding issues; now the cap is 2,000,000 and over-cap pages are skipped with reason "content_operation_limit" without flagging encoding corruption.
ocrReasonsByPage;extractPagesMarkdownsets the page’socr_reasonaccordingly.pages_needing_ocr; does not sethas_encoding_issueswhen this is the only reason.extract_page_text_items_with_operation_limit; makescontent_exceeds_operation_limitpub(crate); adds regression tests for under/over-cap behavior.@firecrawl/pdf-inspector.Written for commit 4229cf6. Summary will update on new commits.