Skip to content

feat(uploads): send workspace files to Drive/Gmail outside model context, storage-free (revives #3354) - #3458

Merged
benjaminshafii merged 1 commit into
devfrom
feat/direct-uploads-revive-3354
Aug 3, 2026
Merged

benjaminshafii merged 1 commit into
devfrom
feat/direct-uploads-revive-3354

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

What this is

A revival of #3354 by @reachjalil, rebased onto current dev. All design decisions are his (see also #3353, which he closed in favor of this storage-free scope); this PR ports the work across #3441 and migrates the proof to the frozen-corpus-compliant testkit path.

Problem

Attaching a workspace file through the cloud Gmail/Drive capabilities required the model to emit the file as inline base64 tool arguments. That is physically capped by model output budgets (~tens of KB), corrupts or truncates larger files, and the advertised 10 MiB limit was impossible in practice — agents silently degraded files trying to fit (observed live: a 117 KB PDF failed; a video only made it after being crushed to 13 KB).

What changed

  • apps/server — new openwork-cloud-uploads extension: drive_upload_file and gmail_create_draft_with_attachments take authorized workspace paths, read bytes locally (realpath containment, symlink-escape rejection), and POST multipart FormData to Den. 4 MiB total enforced before any network I/O with an honest 413.
  • den-api — POST /v1/direct-uploads/google-workspace/{drive-files,gmail-drafts} behind new cloudTransportRoute() middleware (MCP bearer, mcp:write scope, org-membership resolution). Bytes forward straight to Google (Drive multipart / Gmail drafts.create) and are never persisted.
  • Removed model-facing base64 lanes: the gmail-draft attachments field and the POST /v1/capabilities/google-workspace/drive-files base64 capability are gone. File bytes no longer enter tool JSON or model context at all.
  • Gmail draft creation extracted into executeGmailDraft(...), shared by the JSON capability (no attachments) and the multipart route — dev behavior preserved exactly, including feat(den-api): binary-safe capability content + MCP image delivery lanes #3441's binary read lanes, fix(den-api): preserve Gmail draft formatting #3449's formatting, and multi-account externalAccountId URLs.

Port notes (delta vs #3354 as authored)

  • Resolved conflicts with feat(den-api): binary-safe capability content + MCP image delivery lanes #3441 in google-workspace.ts + capabilities test: all feat(den-api): binary-safe capability content + MCP image delivery lanes #3441 dual-lane read behavior kept intact.
  • evals/flows/google-workspace-gmail-draft-attachments.flow.mjs is deleted, not edited — the legacy flow corpus is frozen (deletions only), and its witnesses asserted the removed base64 contract. Successor proof: evals/specs/google-workspace-direct-uploads.slow.test.ts — cold-boots a real Den, real OAuth connect against a mock Google, drives the production extension code, and asserts byte-for-byte attachment fidelity, metadata-only model-visible results, and pre-network oversize rejection (fetch-call counter = 0).
  • evals/tsconfig.json stops typechecking the frozen flow corpus. Disclosure: pnpm evals:typecheck is red on dev today (pre-existing FlowContext.page errors in den-trim-page-headers.flow.ts); this change fixes it and matches the corpus freeze.
  • packages/docs/openapi.json intentionally untouched (generated snapshot; not regenerated by CI), same call as the original PR.
  • route-access-policy.test.ts: fileURLToPath fix so the suite works from checkouts with spaces in the path.

Tests run

Command Result
pnpm --filter openwork-server exec tsc --noEmit pass
pnpm --filter @openwork-ee/den-api exec tsc --noEmit pass
pnpm evals:typecheck pass (red on dev baseline)
pnpm --filter openwork-server exec bun test src/extensions/cloud-uploads.test.ts src/extensions-connect-gating.test.ts 9 pass / 0 fail
bun test --conditions=development test/google-workspace-capabilities.test.ts test/route-access-policy.test.ts (den-api) 33 pass / 0 fail
bun test --conditions=development test/google-workspace-api.test.ts test/gmail-draft.test.ts test/mcp-tool-content.test.ts (den-api) 37 pass / 0 fail
pnpm --dir evals exec vitest run --config vitest.config.ts --project stack specs/google-workspace-direct-uploads.slow.test.ts 1 pass (17.9s, real Den boot)

Evidence tape from the spec run will be published as the sticky PR comment.

Supersedes #3354 (unmergeable after #3441; branch preserved). Credit: @reachjalil.

…ext, storage-free

Revives #3354 by @reachjalil onto current dev.

- apps/server: new openwork-cloud-uploads extension (drive_upload_file,
  gmail_create_draft_with_attachments) — authorized workspace paths in,
  multipart FormData out to Den; 4 MiB total enforced before network I/O;
  realpath containment incl. symlink escapes.
- den-api: POST /v1/direct-uploads/google-workspace/{drive-files,gmail-drafts}
  behind new cloudTransportRoute() (MCP bearer + mcp:write + org membership);
  bytes forward straight to Google, never persisted.
- Removes the model-facing base64 lanes: gmail-draft attachments field and the
  drive-files base64 upload capability. Gmail draft logic extracted into
  executeGmailDraft, shared by the JSON capability and the multipart route,
  preserving dev behavior (#3441 binary read lanes and #3449 formatting kept).
- Legacy flow deleted per the frozen corpus; successor proof is
  evals/specs/google-workspace-direct-uploads.slow.test.ts (real Den boot,
  mock-Google byte-exact witness, pre-network 413, no bytes in results).
- evals/tsconfig.json stops typechecking the frozen flow corpus, fixing the
  pre-existing red evals:typecheck (FlowContext.page in den-trim-page-headers).

Co-authored-by: Jalil <[email protected]>
@vercel

vercel Bot commented Aug 3, 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 3, 2026 12:18pm
openwork-den Ready Ready Preview Aug 3, 2026 12:18pm
openwork-den-worker-proxy Ready Ready Preview Aug 3, 2026 12:18pm
openwork-diagnostics Ready Ready Preview Aug 3, 2026 12:18pm
openwork-landing Ready Ready Preview, v0 Aug 3, 2026 12:18pm

@benjaminshafii

Copy link
Copy Markdown
Member Author

Photo roll — workspace-paths-upload-directly-to-google-without-model-visible-bytes — 0/0 frames passed · 4 facts

✅ 0/0 frames passed · 4 facts · 4 expectations passed · 0 failed

ℹ️ FACT — 1. Cloud upload inputs expose paths, not bytes

Both registered extension schemas contain only path and message metadata fields; the Den Gmail JSON schema has no attachments field.

  • ✅ PASS Cloud upload inputs expose paths, not bytes — Both registered extension schemas contain only path and message metadata fields; the Den Gmail JSON schema has no attachments field.

ℹ️ FACT — 2. Drive receives the exact authorized workspace file

Mock Drive observed witness.png as image/png with 89504e470d0a1a0a00ff8013 bytes.

  • ✅ PASS Drive receives the exact authorized workspace file — Mock Drive observed witness.png as image/png with 89504e470d0a1a0a00ff8013 bytes.

ℹ️ FACT — 3. Gmail receives exact attachment bytes while the action returns metadata only

Mock Gmail observed witness.png/image/png/12; result fields were ok, draftId, messageId, draftUrl, threadUrl, to, subject, threadId, quotedHistoryIncluded, attachments, filename, mimeType, size.

  • ✅ PASS Gmail receives exact attachment bytes while the action returns metadata only — Mock Gmail observed witness.png/image/png/12; result fields were ok, draftId, messageId, draftUrl, threadUrl, to, subject, threadId, quotedHistoryIncluded, attachments, filename, mimeType, size.

ℹ️ FACT — 4. Oversize aggregate input is rejected before network I/O

The extension fetch call count was 0.

  • ✅ PASS Oversize aggregate input is rejected before network I/O — The extension fetch call count was 0.

Roll created 2026-08-03T12:17:43.138Z · Source: evals/results/rolls/2026-08-03T12-17-43-138Z-workspace-paths-upload-directly-to-google-without-model-visible-bytes/roll.json · Repro: pnpm fraimz:publish -- --pr 3458 --roll 2026-08-03T12-17-43-138Z-workspace-paths-upload-directly-to-google-without-model-visible-bytes

@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 new security issues found in this diff (1172de72c8a9718e1ad6ab86873b609ee9f7ed47). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@benjaminshafii
benjaminshafii merged commit 152a3c2 into dev Aug 3, 2026
20 checks passed
@benjaminshafii
benjaminshafii deleted the feat/direct-uploads-revive-3354 branch August 3, 2026 13:10

This branch was successfully deployed

5 active deployments
Preview – openwork-landing — 1172de72 Deployed Aug 3, 2026 by vercel[bot]
Preview – openwork-den-worker-proxy — 1172de72 Deployed Aug 3, 2026 by vercel[bot]
Preview – openwork-den — 1172de72 Deployed Aug 3, 2026 by vercel[bot]
Preview – openwork-app — 1172de72 Deployed Aug 3, 2026 by vercel[bot]
Preview – openwork-diagnostics — 1172de72 Deployed Aug 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