Repository navigation
fix(den): read the text of PDFs in Google Drive up to 50 MB - #6894
Merged
Merged
Conversation
The Drive read capability (GET /v1/capabilities/google-workspace/drive-file/:fileId) treated a PDF like any other binary file. Since #4260 lowered the inline binary limit from 10 MB to 64 KB, any PDF over 64 KB returned content: null with contentUnavailableReason "file_too_large" without being downloaded, so an agent reading an ordinary ~415 KB PDF got nothing and reported the file as too large. Smaller PDFs came back as base64 the model cannot read. Behind googleDrivePdfText (off), PDFs up to 10 MB are downloaded with alt=media and their text layer extracted with unpdf (pdf.js), page by page up to the existing 200,000-character text limit. A PDF with no text layer returns the new "no_extractable_text" reason. Other file types are unchanged.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Contributor
Warden: advisory — no major findingsNo high or medium security findings and no confidentiality findings. Warden does not block merging or grant or withdraw approvals. Tests and human review remain separate requirements. Reviewed |
Raise the PDF text-extraction cap from 10 MB to 50 MB (a separate constant; the 64 KB inline limit for other binaries is unchanged) and make it safe on a shared API server: - readBytesWithin streams the download with the cap enforced while reading, refusing a declared size over the cap and cutting off a body that grows past it, and reads a declared size into one buffer. - Extraction runs in a worker thread (512 MB heap limit, buffer transferred, not copied). pdf.js parses synchronously, so on the request thread it stalled other requests and no timer could stop it; the worker is terminated at a 15 s deadline, returning extraction_timed_out. At most two run at once. - The loading task is destroyed after every read; pages stop at the 200,000-character limit. - Unavailable PDF reads carry contentUnavailableHint: with a shell, use createGoogleDriveDownloadLink and read the file locally. scripts/measure-pdf-text.ts generates large image-heavy PDFs in memory and records time, memory and event-loop stalls. Worst case measured at 50 MB: 0.55 s, 263 MB above the file, 2 ms stall.
13 tasks done
This branch was successfully deployed
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.
What is this about?
The Google Drive "read file" capability agents use through the MCP gateway (including the Slack agent) now returns the text of PDFs up to 50 MB, behind
googleDrivePdfText.What problem does it solve?
Agents could not read ordinary PDFs shared from Drive. They told people a few-hundred-KB file was "too large" and got nothing back.
What was the situation before?
Reading a ~415 KB PDF returned
content: nullwithcontentUnavailableReason: "file_too_large", without downloading it: every non-Google file over 64 KB is refused (limit lowered from 10 MB in #4260). PDFs under 64 KB came back as base64 the model cannot read.How is this implemented?
drive-file/:fileId(routes/org/google-workspace.ts): with the flag on, PDFs up to 50 MB are downloaded withreadBytesWithin(cap enforced while streaming) and returned asencoding: "text", within the existing 200,000-character limit. Other binaries keep the 64 KB limit.capability-sources/pdf-text.ts:unpdf(pdf.js) runs in a worker thread with a 512 MB heap, a 15 s deadline (extraction_timed_out) and at most two at once; pages stop at the character limit and the document is destroyed.file_too_large,no_extractable_text,extraction_timed_out) carrycontentUnavailableHint: with a shell, usecreateGoogleDriveDownloadLinkand read locally.googleDrivePdfText(connect, off); doc indocs/features/google-drive-pdf-text/.Measured with
scripts/measure-pdf-text.ts(generated 200-page image-heavy PDFs, M3 Max), worst case at 50 MB (broken cross-reference table): 0.55 s, 263 MB above the file, 2 ms stall of other requests. Normal 50 MB PDF: 0.24 s, 64 MB.What else changed?
[email protected]in den-api.pnpm features:sync.Release note
Agents can read the text of PDFs in Google Drive up to 50 MB instead of reporting them as too large.
Evidence
ee/apps/den-api/test/api/google-drive-pdf.api.test.ts: before (flag off), a ~415 KB Drive PDF returnsfile_too_largeand is not downloaded; after, its text comes back over REST andexecute_capability, a scan returnsno_extractable_textand a 51 MB PDF is not downloaded, both with the download-link hint.test/pdf-text.test.tscovers the worker, truncation, timeout and the streaming cap.