improvement(file-parsers): bound PDF text extraction - #6425
Conversation
Extract page text through pdf.js's streaming API with page, character, and wall-clock budgets instead of buffering the whole document, so extraction memory stays bounded regardless of input. Release the document proxy when done, and route output through sanitizeTextForUTF8 like the other parsers.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Extraction is capped by page count (10k), total characters (~10M), and a 60s wall-clock deadline. When a limit bites, metadata sets Output goes through Reviewed by Cursor Bugbot for commit 3420641. Configure here. |
Greptile SummaryThis PR bounds PDF text extraction by page count, character count, and elapsed time while releasing pdf.js resources after parsing.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/file-parsers/pdf-parser.ts | Replaces whole-document extraction with budgeted streaming extraction, sanitizes output, reports truncation, and destroys the document proxy. |
| apps/sim/lib/file-parsers/pdf-parser.test.ts | Adds coverage for bounded extraction of a highly compressed text PDF and complete extraction of a small PDF. |
| apps/sim/lib/file-parsers/types.ts | Adds the optional typed truncation indicator already used by parser metadata. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Input[PDF buffer] --> Proxy[Create pdf.js document proxy]
Proxy --> Pages[Visit pages within page limit]
Pages --> Stream[Stream page text]
Stream --> Budget{Character or time budget reached?}
Budget -->|No| Pages
Budget -->|Yes| Truncated[Mark output truncated]
Pages -->|Document exhausted| Complete[Mark output complete]
Truncated --> Sanitize[Sanitize UTF-8 text]
Complete --> Sanitize
Sanitize --> Result[Return content and metadata]
Result --> Destroy[Destroy document proxy]
Reviews (2): Last reviewed commit: "fix(file-parsers): only flag truncation ..." | Re-trigger Greptile
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3420641. Configure here.
Summary
sanitizeTextForUTF8, matching every other parser in the foldertruncatedtoFileParseMetadata(csv and xlsx already emitted it untyped)Type of Change
Testing
Added
pdf-parser.test.ts(the parser had none). Verified output is byte-identical to the previous implementation on real multi-page PDFs, and that the new tests fail against the old code.Checklist