Skip to content

fix(gmail): preserve attachments carried in message body data - #50621

Closed
Afloat16 wants to merge 1 commit into
stablyai:mainfrom
Afloat16:afloat16/orca50-20261127-gmail-inline-attachments
Closed

Afloat16 wants to merge 1 commit into
stablyai:mainfrom
Afloat16:afloat16/orca50-20261127-gmail-inline-attachments

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

ELI5

Keep files Gmail already included in a message so reading, downloading and forwarding do not silently omit them.

What Changed

Recognize named inline-data parts, including empty files, and download their existing bytes without calling the external-attachment endpoint. Preserve external-attachment reads and existing size checks.

Why

Gmail may return attachment bytes directly in MessagePartBody.data without an attachmentId. Orca only lists parts with an attachmentId and therefore silently drops these files when reading or forwarding messages.

Production callers: readGmail exposes downloadable attachment references; downloadGmailAttachment serves CLI/RPC attachment downloads; composeForward and composeRevision retain existing message files through savedAttachments.

Linked Issue

Fixes #50620

Visual Proof

N/A

This changes attachment data delivered by existing CLI/RPC operations, with no graphical layout or interaction control change.

Same production input before After
The exact base production readGmail returned only remote.txt and omitted inline.bin and empty.txt. Actual message reads list all three attachments; downloads and composeForward preserve exact binary, empty and external attachment bytes in order. Unavailable body data remains excluded.

Testing

  • I manually tested these changes locally through the actual production entries below
  • Automated regression added for external data integrity
  • The added regression fails against the original production code and uses the real operation with only provider responses supplied

Read a Gmail message with three named parts: binary bytes in body.data without an attachmentId, an empty body.data attachment, and an external attachmentId. Invoke readGmail, downloadGmailAttachment and composeForward. All three files should remain present with their exact bytes and order; an unavailable part without data or an ID remains excluded.

node config/scripts/test-runtime/execution-policy/run-vitest.mjs run --config config/vitest.config.ts src/main/google/google-gmail-inline-attachments.test.ts --maxWorkers=2

Integrated inline-attachment, existing forwarding-budget and MIME regressions:3files/5tests passed.

Final integrated validation: 32 focused regression tests in 22 files passed, including the unchanged archive-write failure case that had timed out under earlier heavy concurrent checking. The Drive performance contract passed separately (1 file/1 test). Changed-code quality passed with zero new findings across 129 changed paths; final touched-file formatting and git diff --check passed. Node typechecking passed for 17,026 files and web typechecking for 16,094 files using the repository-supported Bun compiler with one worker. These are aggregate validation results for the prepared contributions, not per-PR test counts.

The required pnpm check:changed --base=9890ea181c0f9ae59fb82da64c4a6fbc0504a817 was attempted after the final edits. Its workspace-package build is blocked because this environment rejects the tsx CLI local IPC socket (listen EPERM). The default tsrs typechecker was also terminated with SIGKILL; the supported Bun typechecking route completed successfully. The complete gate/build is not claimed to pass and still requires CI.

Linux was exercised locally. No live Google account, graphical desktop, macOS, Windows or SSH execution is claimed. The provider-neutral code remains on the existing runtime paths.

Performance

Existing account/part validation and declared-size limit remain. Inline attachment bytes are already present in the full message response, so no additional external-attachment request is made. Remote attachment retrieval is unchanged. Recognizing previously omitted files also includes them in the existing aggregate forward-size check. No MIME body-representation changes.

Risk

Level: Low

Previously omitted inline files are now included in downloads and forwarded drafts, so the existing aggregate size check may reject a draft that was previously incomplete. Account validation, external attachment retrieval and declared-size checks remain. No MIME text-representation change is included. A revert restores prior attachment detection; already saved files or sent messages are not altered.

AI Disclosure

Core contribution owner: @Afloat16. Required tooling disclosure: GPT-6 Astra Pro was used for implementation and review.

Review

Reviewed the actual operation, exact-base failure, normal controls, account/target identity, payload limits and cleanup. No new dependency, polling loop or RPC endpoint is introduced.

Agent skill upstream boundary

  • Not applicable: no upstream skill-installer material is copied or mechanically translated.

Notes

Primary sources:

Related submissions checked for distinct scope:

Checklist

  • This PR is small and focused
  • What changed, why and the mechanism are explained
  • Risk and rollback are described
  • N/A visual reason and before/after production data are included
  • Self-reviewed for correctness, security and performance
  • Cross-platform, SSH/remote and path/shortcut impact considered
  • Full lint/typecheck/test/build gate: component validation and environment limitation are reported; the complete gate still requires CI

@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 with inline data, including empty data. Attachment downloads use inline data when the part has no attachment ID. A new test checks inline, empty, remote, and unavailable parts, including their presence in reads and forwarded drafts.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 1b72a

Gmail attachments whose bytes are already in the message body, including empty files, now appear in reads and forwards and can be downloaded. The change is small, is covered by a focused test, and shows no merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(gmail): preserve attachments carried in message body data" matches the main change: named Gmail message parts whose bytes sit in body.data (including empty files) are now recognized and…
Description check Passed The description follows the repository template and covers the required sections. It has an ELI5, a What Changed section, a Why section with production callers, a linked issue (Fixes #50620), Visual P…
Linked Issues check Passed Directly linked issue #50620 requires that Gmail attachments whose bytes sit in body.data without an attachmentId stay visible in readGmail, downloadGmailAttachment, and composeForward. An unavailable…
Out of Scope Changes check Passed The changed areas match the linked issue. The changes are in src/main/google/google-gmail-message.ts (attachmentsOf detection), src/main/google/google-gmail-read.ts (inline data handling in downloadGm…
Full details: Title check

Explanation

The title "fix(gmail): preserve attachments carried in message body data" matches the main change: named Gmail message parts whose bytes sit in body.data (including empty files) are now recognized and kept in reads, downloads, and forwards. It is concise, specific, and follows a conventional commit style.

Full details: Description check

Explanation

The description follows the repository template and covers the required sections. It has an ELI5, a What Changed section, a Why section with production callers, a linked issue (Fixes #50620), Visual Proof marked N/A with a reason, Testing with the regression command and results, a Performance line, a Risk section with level and rollback, AI Disclosure, and the checklist. Testing is detailed and explains what could not be verified (full pnpm gate, live Google account, macOS, Windows, SSH). Minor gaps: the Performance section does not state a measured figure, and the Risk section does not name the platforms affected beyond Linux. These gaps are not critical.

Full details: Linked Issues check

Explanation

Directly linked issue #50620 requires that Gmail attachments whose bytes sit in body.data without an attachmentId stay visible in readGmail, downloadGmailAttachment, and composeForward. An unavailable part with neither data nor an ID must stay excluded.

Code at the reviewed head (src/main/google/google-gmail-message.ts): attachmentsOf now accepts a named part with a partId and a body when body.attachmentId is set or body.data !== undefined. An empty string counts as present. This fixes the listing that dropped inline.bin and empty.txt. Parts without a filename, or without body data or an attachmentId, remain excluded.

Code at the reviewed head (src/main/google/google-gmail-read.ts): readGmail uses attachmentsOf, so the inline and empty files now appear in the read view. downloadGmailAttachment resolves the part by ref. It calls the attachments endpoint only when body.attachmentId exists. Otherwise it decodes body.data (base64url to base64). It still rejects parts with no content source and keeps the TOOL_DOWNLOAD_MAX_BYTES check.

The PR reports a regression test (src/main/google/google-gmail-inline-attachments.test.ts) that covers readGmail, downloadGmailAttachment, and composeForward with exact bytes and order. I did not run this test. I did not inspect the composeForward or savedAttachments path directly, because the diff blobs were unavailable. Its behavior rests on the PR report and the stated reuse of attachmentsOf.

Full details: Out of Scope Changes check

Explanation

The changed areas match the linked issue. The changes are in src/main/google/google-gmail-message.ts (attachmentsOf detection), src/main/google/google-gmail-read.ts (inline data handling in downloadGmailAttachment), a regression test for issue #50620, and a test fixture that supplies the mocked account and HTTP client for that test. The PR description states that no MIME body-representation, RPC endpoint, or dependency change is included. The PR description also says the unrelated items #50497, #50413, and #48067 are not changed. I found no change outside the scope of issue #50620. Diff inspection was limited because the changed blobs were unavailable in the checkout, so this verdict relies on the head file contents and the PR summary.

  • 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: 3d764307-040c-4988-8e51-9c6e0c5b946a
Commits

Reviewing files that changed from the base of the PR and between a788fad and 1b72a4a.

Files selected for processing: 4

  • src/main/google/google-api-http.test-fixture.ts
  • src/main/google/google-gmail-inline-attachments.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; 1 remain after this review.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @Afloat16 for finding and fixing this! We've landed your fix in #50765 (squashed onto current main with the inline-attachment test folded into the existing forward tests). Your authorship is preserved on the commit. Closing this one in favor of that PR.

@nwparker nwparker closed this Nov 27, 2026
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