Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(google): omit ephemeral Gmail handles from persisted receipts (#5802, #5818)

garrytan7a3fe9beb99a
diff --git a/src/core/google/attachment-receipts.ts b/src/core/google/attachment-receipts.ts
index f12fd4fcdd..6235c658f3 100644
--- a/src/core/google/attachment-receipts.ts
+++ b/src/core/google/attachment-receipts.ts
@@ -87,7 +87,11 @@ export function inspectGmailAttachments(root: GmailMimePart | undefined, account
id: createHash('sha256').update(JSON.stringify([account.toLowerCase(), messageId, partId, path])).digest('hex'),
account, messageId, partId, filename, mimeType,
size: typeof part.body?.size === 'number' && Number.isSafeInteger(part.body.size) && part.body.size >= 0 ? part.body.size : null,
- attachmentId: part.body?.attachmentId || null,
+ // #5802: attachmentId is an ephemeral fetch handle (Gmail rotates it per
+ // request); persisting it made every receipt differ each sync and forced
+ // permanent re-admission. partId + messageId + sha256 id identify the
+ // attachment; the handle is re-fetched when download is implemented.
+ attachmentId: null,
kind: calendar ? 'calendar' : disposition === 'inline' || gmailPartHeader(part, 'Content-ID') ? 'inline' : 'document',
fetched: false, indexed: false,
};
diff --git a/test/google-attachment-receipts.test.ts b/test/google-attachment-receipts.test.ts
index 2824fe7366..6f4fc8b043 100644
--- a/test/google-attachment-receipts.test.ts
+++ b/test/google-attachment-receipts.test.ts
@@ -80,7 +80,7 @@ describe('Gmail attachment receipts', () => {
expect(calls).toBe(1);
expect(result.messages[0].bodyText).toBe('');
expect(result.messages[0].attachmentInspection).toMatchObject({ state: 'present', attachments: [
- { partId: '1.0', filename: 'nested.pdf', attachmentId: 'opaque', size: 42, fetched: false, indexed: false },
+ { partId: '1.0', filename: 'nested.pdf', attachmentId: null, size: 42, fetched: false, indexed: false },
] });
});
@@ -125,7 +125,7 @@ describe('Gmail attachment receipts', () => {
{ partId: '1', mimeType: 'application/pdf', filename: 'report.pdf', body: { attachmentId: 'opaque-id', size: 42 } },
] });
expect(result.messages[0].attachmentInspection).toMatchObject({ state: 'present', attachments: [
- { filename: 'report.pdf', mimeType: 'application/pdf', size: 42, attachmentId: 'opaque-id', partId: '1', fetched: false, indexed: false },
+ { filename: 'report.pdf', mimeType: 'application/pdf', size: 42, attachmentId: null, partId: '1', fetched: false, indexed: false },
] });
expect(result.messages[0].bodyText).toBe('Hello');
const rendered = renderThreadPage(result)!.markdown;
@@ -160,6 +160,18 @@ describe('Gmail attachment receipts', () => {
expect(a.attachments[0].attachmentId).toBeNull();
});
+ test('an ephemeral attachmentId never reaches the persisted receipt — two fetches produce identical output (#5802)', () => {
+ const part = (id: string): GmailMimePart => ({ mimeType: 'multipart/mixed', parts: [
+ { partId: '1', mimeType: 'application/pdf', filename: 'report.pdf', body: { attachmentId: id, size: 42 } },
+ ] });
+ const first = inspectGmailAttachments(part('ANGjdJ_first'), '[email protected]', 'one');
+ const second = inspectGmailAttachments(part('ANGjdJ_rotated'), '[email protected]', 'one');
+ // Gmail returns a different attachmentId per fetch; the persisted receipt
+ // must be identical or every sync re-admits the thread.
+ expect(second).toEqual(first);
+ expect(first.attachments[0].attachmentId).toBeNull();
+ });
+
test('unclassifiable empty leaves and childless multipart containers remain incomplete', async () => {
for (const payload of [{ mimeType: 'multipart/mixed' }, { mimeType: 'multipart/mixed', parts: [] }, { body: {} }, { mimeType: '', body: {} }]) {
const result = await thread(payload);