Skip to content

fix(den): read the text of PDFs in Google Drive up to 50 MB - #6894

Merged
benjaminshafii merged 2 commits into
devfrom
fix/den-drive-read-pdf-text
Nov 3, 2026
Merged

benjaminshafii merged 2 commits into
devfrom
fix/den-drive-read-pdf-text

Conversation

@benjaminshafii

@benjaminshafii benjaminshafii commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

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: null with contentUnavailableReason: "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 with readBytesWithin (cap enforced while streaming) and returned as encoding: "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.
  • Unavailable PDFs (file_too_large, no_extractable_text, extraction_timed_out) carry contentUnavailableHint: with a shell, use createGoogleDriveDownloadLink and read locally.
  • Feature googleDrivePdfText (connect, off); doc in docs/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?

  • New dependency [email protected] in den-api.
  • Helm values regenerated by 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 returns file_too_large and is not downloaded; after, its text comes back over REST and execute_capability, a scan returns no_extractable_text and a 51 MB PDF is not downloaded, both with the download-link hint. test/pdf-text.test.ts covers the worker, truncation, timeout and the streaming cap.

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.
@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-den Ready Ready Preview Nov 3, 2026 6:07am UTC
3 Skipped Deployments
Project Deployment Actions Updated
openwork-app Ignored Ignored Preview Nov 3, 2026 6:07am UTC
openwork-diagnostics Ignored Ignored Preview Nov 3, 2026 6:07am UTC
openwork-landing Ignored Ignored Preview Nov 3, 2026 6:07am UTC

Request Review

@diff-warden

diff-warden Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Warden: advisory — no major findings

No 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 e1ffee85d38e · Warden run · Updates after every Warden run.

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.
@benjaminshafii benjaminshafii changed the title fix(den): read the text of PDFs in Google Drive fix(den): read the text of PDFs in Google Drive up to 50 MB Nov 3, 2026
@benjaminshafii
benjaminshafii merged commit 98fc3ff into dev Nov 3, 2026
22 checks passed

This branch was successfully deployed

4 active (3 outdated) deployments
Preview – openwork-den — e1ffee85 Deployed Nov 3, 2026 by vercel[bot]
Preview – openwork-app — acd52fe0 Deployed Nov 3, 2026 by vercel[bot]
Preview – openwork-landing — acd52fe0 Deployed Nov 3, 2026 by vercel[bot]
Preview – openwork-diagnostics — acd52fe0 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant