Skip to content

fix(gmail): keep attachments whose bytes arrive inline in the message body - #50765

Merged
nwparker merged 1 commit into
mainfrom
bugbash/pr-50621
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/pr-50621

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Some Gmail messages carry a file's contents right inside the message instead of as a separate download link. Orca only looked for the download link, so those files quietly disappeared when you read, downloaded or forwarded the message. Now Orca keeps them.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​62 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​5

What Changed

  • Before: attachmentsOf only listed named parts that had a body.attachmentId. Parts whose bytes Gmail returned inline in MessagePartBody.data (no attachmentId) were dropped from orca gmail read, attachment downloads, forwards and draft revisions.
  • After: a named part counts as an attachment when it has either an attachmentId or inline body.data (including empty files). downloadGmailAttachment fetches from the attachments endpoint only when there is an attachmentId; otherwise it serves the inline bytes that are already in the full message response. Parts with neither are still excluded, and the existing size limit still applies.

Why

Gmail's API documents that MessagePartBody.data may hold the attachment bytes directly, with attachmentId present only when the data is stored separately. Treating both shapes as attachments fixes every caller (read, download, forward, revision) at the single place where attachments are discovered, rather than patching each caller.

Linked Issue

Fixes #50620

Visual Proof

N/A. This changes which attachments Gmail CLI/RPC operations return and forward in the main process; there is no UI layout or interaction change.

Testing

  • 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

Added forwards attachments whose bytes Gmail returns in the part body in src/main/google/google-gmail-draft-compose.test.ts. It runs the real composeForward with only Gmail API responses stubbed: one binary inline part, one remote attachmentId part, and one part with neither. Against main's source the test fails (the inline file is missing); with this change both files are forwarded with exact bytes in order and the unavailable part stays excluded. All src/main/google/google-gmail*.test.ts pass (3 files, 13 tests). oxlint, oxfmt, anti-slop, code-quality native plugins, ast-grep and the changed-code quality gate are clean on the touched files. Tested on macOS (unit level; no live Google account).

Performance

None, because this only runs when an agent or user reads, downloads or forwards a Gmail message (on-demand main-process work, not a hot path). Measured attachmentsOf: 5 parts 0.18/0.12 us old vs 0.19/0.20 us new; 1000 parts 44 us vs 47 us (all remote) and 22 us vs 53 us (mixed, where the new code now lists twice as many attachments); 10000 mixed parts 0.23 ms vs 0.44 ms. Inline downloads skip a network request they never needed.

Risk

Level: Low

Previously dropped inline files now appear in reads and forwarded drafts, so the existing forward size check counts them and may reject a forward that was previously silently incomplete. Remote attachment retrieval is unchanged. A plain revert restores the old detection.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Original fix by @Afloat16 in #50621 (authorship preserved on the commit).

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Gmail can return attachment bytes inline in MessagePartBody.data with no
attachmentId. attachmentsOf only listed parts with an attachmentId, so those
files were dropped from `orca gmail read`, attachment downloads, forwards and
draft revisions. List named parts that carry either, and serve inline bytes
without calling the attachments endpoint.

Fixes #50620

Co-authored-by: Neil <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Gmail attachment discovery now includes named message parts that contain inline body data. Attachment downloads use inline data or fetch data by attachment ID, and tests cover both cases and a part without attachment data.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 73882

Gmail inline attachments are now listed and downloaded correctly, including empty files. No remaining merge-blocking risk was found. Forwards that include newly visible inline files may now hit the existing size limit.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: attachments whose bytes arrive inline in the Gmail message body are now kept. It uses the conventional fix(gmail) prefix. The raw summary and objectives confirm that a…
Description check Passed The description follows the repository template and fills every required section. It has an ELI5, a before/after account of what changed with the mechanism, a rationale, a linked issue (Fixes #50620),…
Linked Issues check Passed Linked issue #50620 has one coding objective: Gmail named parts with inline body.data (including empty data) must stay listed and downloadable, with exact bytes and order, through readGmail, downloadG…
Out of Scope Changes check Passed The PR changes three source files and adds one test in the Gmail area: google-gmail-message.ts (attachmentsOf detection), google-gmail-read.ts (downloadGmailAttachment inline path) and google-gmail-dr…
Full details: Title check

Explanation

The title names the main change: attachments whose bytes arrive inline in the Gmail message body are now kept. It uses the conventional fix(gmail) prefix. The raw summary and objectives confirm that attachmentsOf, downloadGmailAttachment and the forward path now handle inline body.data parts. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description follows the repository template and fills every required section. It has an ELI5, a before/after account of what changed with the mechanism, a rationale, a linked issue (Fixes #50620), N/A visual proof with a reason, testing steps with platform, a performance line with measurements, a risk level with revert guidance, and the agent skill boundary checkbox. The checklist is completed. The HTML comment placeholders are removed. The description is thorough and matches the objectives and summary.

Full details: Linked Issues check

Explanation

Linked issue #50620 has one coding objective: Gmail named parts with inline body.data (including empty data) must stay listed and downloadable, with exact bytes and order, through readGmail, downloadGmailAttachment and composeForward. Parts with neither data nor attachmentId must stay excluded.

Evidence at reviewed head:

  • google-gmail-message.ts, attachmentsOf: a named part with partId is listed when body.attachmentId or body.data !== undefined. The data !== undefined check keeps empty inline files. Parts with neither are excluded.
  • google-gmail-read.ts, readGmail: calls attachmentsOf for each message, so inline files appear in reads.
  • google-gmail-read.ts, downloadGmailAttachment: uses the attachments endpoint only when body.attachmentId is set. Otherwise it uses body.data. The bytes go base64url decode, then base64 encode, so the round trip keeps the bytes.
  • google-gmail-draft-compose.ts, composeForward: calls savedAttachments, which calls attachmentsOf and then downloadGmailAttachment. Inline files therefore reach forwards in order.

The test named in the PR (forwards attachments whose bytes Gmail returns in the part body) was not read directly. Its result rests on the PR author's report. The code path above supports the objective.

No stack evidence was supplied. This objective is fully within the current PR, so no stack roll-up applies.

Full details: Out of Scope Changes check

Explanation

The PR changes three source files and adds one test in the Gmail area: google-gmail-message.ts (attachmentsOf detection), google-gmail-read.ts (downloadGmailAttachment inline path) and google-gmail-draft-compose.test.ts (regression test). Each change serves the #50620 objective. The PR description and raw summary report no unrelated edits. Related issues #50497, #50413 and #48067 are excluded by the issue and are not changed here.

Minor note, not a scope failure: for inline parts, the forward total size check uses body.size. If Gmail omits body.size for inline parts, the check counts them as zero bytes. The per-file download limit then also counts them as zero. This affects the size guard only, not scope.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d289a5a8-626f-41a7-96ec-a1de10d6dc75
Commits

Reviewing files that changed from the base of the PR and between 72aea61 and 7388242.

Files selected for processing: 3

  • src/main/google/google-gmail-draft-compose.test.ts
  • src/main/google/google-gmail-message.ts
  • src/main/google/google-gmail-read.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker merged commit 87ae355 into main Nov 27, 2026
54 checks passed
@nwparker
nwparker deleted the bugbash/pr-50621 branch November 27, 2026 09:58
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.

[Bug]: Gmail attachments stored directly in body.data disappear from reads and forwards

2 participants