Repository navigation
fix(gmail): limit concurrent attachment downloads when forwarding or revising drafts - #50671
Conversation
…revising drafts Forwarding a message or revising a draft downloaded every saved attachment at once, so messages with more than ten files could trip Gmail's per-user concurrency limit (429) and fail the whole draft. Download them through the existing inBatches helper with the shared GMAIL_CALLS_AT_ONCE budget, keeping attachment order and size limits. Fixes #50596 Co-authored-by: Neil <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
ELI5
When Orca forwards an email or revises a draft that has a lot of attachments, it used to ask Gmail for every attachment at the same moment. Gmail only allows a handful of requests at once per user, so with more than about ten files it said "too many requests" and the whole draft failed. Now Orca downloads the attachments ten at a time, so the draft goes through.
What Changed
savedAttachmentsinsrc/main/google/google-gmail-draft-compose.tsranPromise.allover every saved attachment. A message with more than 10 attachments started more than 10 Gmail requests together. Gmail could answer one of them with a 429 (too many concurrent requests), and that failed the whole forward or revision.inBatcheshelper with the sharedGMAIL_CALLS_AT_ONCElimit (10) fromgoogle-gmail-read.ts, the same limit that thread listing already uses. Attachments keep their order. The total-size check still runs first, unchanged.google-gmail-draft-compose.test.ts, which forwards a message with 12 attachments through a fake Gmail API that returns 429 once more than 10 requests are in flight. It checks that all 12 attachments arrive in order with their contents intact.Why
Both
composeForwardandcomposeRevision(called fromsaveGmailDraft) go throughsavedAttachments, so one change fixes both. Reusing the existing helper and limit keeps every Gmail call path on the same concurrency rule. We didn't add a new limiter or retry logic.Linked Issue
Fixes #50596
Original fix by @Afloat16 in #50598 (authorship preserved on the commit).
Visual Proof
N/A. This is a main-process change to how Gmail requests are scheduled. Nothing in the UI changes. The before/after evidence is test output:
origin/main)GoogleToolError: Too many concurrent requests for user(fails)Testing
Reproduced the failure on
origin/mainwith the new test plus a temporary probe (12-attachment forward, 25-attachment revision). Both fail with the modeled 429. Both pass on this branch.vitestoversrc/main/google/: 7 files, 54 tests passed.CI static gates on the changed files are clean: anti-slop oxlint, native code-quality oxlint, ast-grep,
check-changed-code-quality.mjs, andoxfmt --check.Platform: macOS (unit level). The code is platform-independent main-process logic.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
This only runs when a user forwards a message or revises a draft that has saved attachments. It is async main-process network I/O with no sync work, polling or subprocesses, and the number of requests and bytes is unchanged. Benchmark with a simulated 100 ms Gmail latency per call (old vs new wall time, peak requests in flight):
Up to 10 attachments (the typical case) nothing changes. Above 10, the old path's faster times only hold against a fake that allows unlimited parallel requests. Real Gmail rejects that with a 429. The extra latency only shows up where the old code would have failed.
Risk
Level: Low
The worst case is that forwarding a message with many attachments takes a bit longer, about one extra Gmail round trip per 10 attachments. No saved data, settings, IPC, or remote protocol changes. A plain revert restores the old behavior.
Review
Reviewed the production callers (
composeForward,composeRevisionviasaveGmailDraft), attachment ordering, the aggregate size limit, and error propagation. They are unchanged apart from the concurrency bound.Agent skill upstream boundary
Notes
No security, cross-platform, SSH, mobile, or backwards-compatibility impact. Gmail calls run in the desktop main process, and the change adds no new endpoints or protocol fields.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)