Repository navigation
perf(gmail): API efficiency, atomic label updates, metadata search, audit accuracy, and HTTP retry resilience - #20
Merged
Conversation
…nd HTTP retry resilience
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improves Gmail API efficiency, atomicity, drafts-audit accuracy, and HTTP timeout/retry resilience in
GmailServiceanddrafts-audit:downloadAttachmentsdouble-fetch cache bug (src/gmail-service.ts):sizefromdownloadPartsForMessagesintodownloadAttachments.attachment.size > 0matches the on-disk file size, return{ cached: true }immediately with 0 Gmail API calls.attachments.getonce (never twice), decode the payload, reuse disk if decoded length matches, otherwise write with0600perms.modifyLabels+ whitespace trimming (src/gmail-service.ts):resolveLabelIdsandmodifyLabels.addLabelIdsandremoveLabelIdsinto a single atomicgmail.users.threads.modifyrequest per thread, eliminating partial-failure states.searchThreads(src/gmail-service.ts):format: "metadata"andmetadataHeaders: ["From", "To", "Cc", "Subject", "Date"]instead offormat: "full".5) viamapWithConcurrency, preserving input order and fullThreadSearchResultcompatibility.drafts auditerror swallowing, bounded concurrency & multi-recipient search (src/gmail-service.ts,src/drafts-audit.ts):fetchThreadandfetchMessageMetadata, treat only genuine HTTP404(isGmailNotFoundError) asnull; propagate401,403,429,5xx, and network errors so transient/auth failures never silently produce falsenot_proven_duplicateresults.buildSentSearchQuery, search across uniqueTo/Ccrecipients with(to:a@x.com OR to:b@y.com)(capped at 5 unique emails) instead of only the first recipient.5) with in-flight promise deduplication when fetching draft details, threads, and sent-message metadata inauditDrafts.src/gmail-service.ts):30_000ms timeout on both theOAuth2Clienttransporter andgoogle.gmail(...)client.retry: truewith exponential backoff (retry: 3,429+500–599,httpMethodsToRetry: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]), explicitly excludingPOSTso non-idempotent sends/draft creates are never auto-retried.Verification
npm ci --no-audit --no-fundnpm run lint(biome check src/) — passed (7 files, 0 issues)npm run typecheck(tsc --noEmit) — passednpm run build— passednpm test— 50/50 tests passing, including new unit tests intest/gmail-service-perf.test.jsand expanded tests intest/drafts-audit.test.js