Skip to content

fix(den): harden Google Workspace retrieval - #4260

Merged
reachjalil merged 1 commit into
devfrom
perf/google-drive-end-to-end-latency
Aug 31, 2026
Merged

reachjalil merged 1 commit into
devfrom
perf/google-drive-end-to-end-latency

Conversation

@reachjalil

@reachjalil reachjalil commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Summary

  • require an exact drive.readonly or full drive grant for general Drive search and file read, returning the existing actionable needs_connection response before any provider call when scopes are selected-file-only, missing, or unknown
  • preserve legacy missing-scope behavior for Gmail, Calendar, Drive upload, and Drive share; drive.file remains valid only for the existing upload/share operations that support it
  • search the allDrives corpus with the required Shared Drive flags and avoid the unsupported full-text orderBy combination
  • classify authorization failures from structured Google error reasons, keep ordinary upload/share permission failures as upstream errors, and retain bounded, ambiguity-aware file-read 404 diagnostics
  • reject Drive folders through the existing file-read route without downloading content or adding folder traversal
  • retrieve Gmail metadata with bounded concurrency, stable ordering, failure-response consumption, transport-error mapping, and cancellation of outstanding siblings after the first failure
  • apply the 20K text bound at MCP serialization while retaining the existing 100K Gmail and 200K Drive retrieval limits; compact large JSON, preserve supported small attachment bytes, emit nested image content, and omit oversized non-image binary content
  • avoid downloading metadata-known oversized Drive binaries that cannot be returned safely

Incident assessment

  • Confirmed code defect: drive.file was accepted for general Drive search and read.
  • Strong incident hypothesis: that scope mismatch caused the reported valid-link 404 for content created directly in My Drive.
  • Confirmed secondary defect: Shared Drive requests were missing required compatibility parameters and the search corpus did not cover all member Shared Drives.
  • Out of scope: folder traversal, a Drive browser, new Drive UI, new tools or capabilities, new configuration, and any additional product surface.

Scope

This updates only the existing Google Workspace connector and existing MCP search/execute serialization path. It does not add a Drive app, custom results interface, companion launch tool, React component, HTML entry point, shared app payload, build registration, workflow, public option, or public API.

Verification

  • pnpm --filter @openwork-ee/den-api exec tsc --noEmit
  • pnpm --filter @openwork-ee/den-api exec bun test test/mcp-tool-content.test.ts test/google-workspace-capabilities.test.ts test/google-workspace-api.test.ts — 74 passed, 0 failed, 369 assertions
  • pnpm evals:pr specs/google-workspace-connector-retrieval.test.ts — 1 passed, 0 failed, 0 skipped
  • drive.file, missing scopes, empty scopes, and scope URL lookalikes reject general search/read with zero provider calls
  • the same directly-created My Drive file ID succeeds with drive.readonly and full drive
  • Shared Drive search sends corpora=allDrives, supportsAllDrives=true, and includeItemsFromAllDrives=true, with no incompatible orderBy
  • structured scope failures become actionable connector responses while an ordinary share 403 remains a bounded upstream error
  • Gmail metadata requests overlap at a maximum of four, preserve list order, and stop/cancel remaining work after failure
  • the existing MCP search/execute path bounds Drive and Gmail text, blocks oversized binary downloads where metadata permits, preserves supported small attachment bytes, and strips oversized non-image base64
  • nested images remain available as image content; omission metadata cannot be spoofed and __proto__ keys do not mutate object prototypes
  • exact-head diff check against dev is clean

Operational follow-up

The organization administrator enables Read all Drive files, the affected member reconnects Google Workspace and grants Drive read access, support confirms the recorded scopes, and the same original file ID is retried. That live reconnect/retry is environment-dependent and separate from the code proof above.

@vercel

vercel Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview Aug 31, 2026 10:53pm
openwork-den Ready Ready Preview Aug 31, 2026 10:53pm
openwork-diagnostics Ready Ready Preview Aug 31, 2026 10:53pm
openwork-landing Ready Ready Preview, v0 Aug 31, 2026 10:53pm

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (7d73b7da59b03729c3a4307ecab70a3349136d5d). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@reachjalil
reachjalil merged commit 696e839 into dev Aug 31, 2026
29 checks passed
benjaminshafii pushed a commit that referenced this pull request Nov 3, 2026
* fix(den): read the text of PDFs in Google Drive

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.

* fix(den): read Drive PDFs up to 50 MB in a bounded worker

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.

This branch was successfully deployed

4 active deployments
Preview – openwork-den — 7d73b7da Deployed Aug 31, 2026 by vercel[bot]
Preview – openwork-landing — 7d73b7da Deployed Aug 31, 2026 by vercel[bot]
Preview – openwork-app — 7d73b7da Deployed Aug 31, 2026 by vercel[bot]
Preview – openwork-diagnostics — 7d73b7da Deployed Aug 31, 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.

2 participants