Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds structured Gmail retry helpers (error extraction, retry classification, delay calculation) and applies withGmailRetry across Gmail utility calls (draft, label, mail, spam, trash). Adds tests for retry logic and bumps version to v2.17.33. Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant Retry as withGmailRetry
participant API as Gmail API
participant Extract as extractErrorInfo
participant Classify as isRetryableError
participant Backoff as calculateRetryDelay
Client->>Retry: call(gmailOperation)
Retry->>API: attempt 1
API-->>Retry: error / success
alt error
Retry->>Extract: extractErrorInfo(error)
Extract-->>Classify: errorInfo
Classify-->>Retry: {retryable, isRateLimit, isServerError}
alt retryable
Retry->>Backoff: calculateRetryDelay(flags, attempt, headers, message)
Backoff-->>Retry: delay_ms
Retry->>Retry: wait(delay_ms)
Retry->>API: attempt 2
API-->>Retry: success / error
else non-retryable
Retry-->>Client: throw error
end
else success
Retry-->>Client: return response
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (9)apps/web/**/*.{ts,tsx}📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
Files:
!{.cursor/rules/*.mdc}📄 CodeRabbit inference engine (.cursor/rules/cursor-rules.mdc)
Files:
**/*.ts📄 CodeRabbit inference engine (.cursor/rules/form-handling.mdc)
Files:
apps/web/utils/gmail/**/*.ts📄 CodeRabbit inference engine (.cursor/rules/gmail-api.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/logging.mdc)
Files:
apps/web/utils/**📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
Files:
apps/web/utils/**/*.ts📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
Files:
**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
Files:
!pages/_document.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
Files:
🧠 Learnings (7)📓 Common learnings📚 Learning: 2025-09-17T22:05:28.646ZApplied to files:
📚 Learning: 2025-09-17T22:05:28.646ZApplied to files:
📚 Learning: 2025-07-18T15:05:34.899ZApplied to files:
📚 Learning: 2025-07-20T09:00:41.968ZApplied to files:
📚 Learning: 2025-09-17T22:05:28.646ZApplied to files:
📚 Learning: 2025-09-17T22:05:28.646ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (5)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/web/utils/gmail/retry.test.ts (2)
5-89: Good test coverage for core retry scenarios.The test suite covers the main retryable error types (server errors 502/503/504, rate limits 429/403) and non-retryable cases (404, 403 without rate limit reason). The HTML error format test on line 17 is particularly valuable.
Consider adding tests for additional edge cases detected by the implementation:
- 403 with
userRateLimitExceededandquotaExceededreasons- "rate limit exceeded" and "quota exceeded" patterns in error messages
- "server error" and "temporarily unavailable" patterns in messages
These tests would validate the complete error detection logic but are optional since the core scenarios are well-covered.
91-102: Solid baseline tests for retry delay calculation.The tests correctly validate the fixed 30s delay for rate limits and the exponential backoff for server errors (5s, 10s, 20s).
Consider adding tests for advanced delay scenarios:
- Retry-After header parsing (both seconds and HTTP-date formats)
- Embedded retry time extraction from error messages
- Backoff cap verification (80_000ms max)
- Precedence order (retry time > Retry-After > fallback)
These would provide more comprehensive coverage but the current tests validate the core delay logic effectively.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
apps/web/utils/gmail/draft.ts(2 hunks)apps/web/utils/gmail/label.ts(3 hunks)apps/web/utils/gmail/mail.ts(4 hunks)apps/web/utils/gmail/retry.test.ts(1 hunks)apps/web/utils/gmail/retry.ts(2 hunks)apps/web/utils/gmail/spam.ts(1 hunks)apps/web/utils/gmail/trash.ts(3 hunks)version.txt(1 hunks)
🧰 Additional context used
📓 Path-based instructions (12)
apps/web/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks
Path aliases: Use@/for imports from project root
Use proper error handling with try/catch blocks
Format code with Prettier
Leverage TypeScript inference for better DX
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
!{.cursor/rules/*.mdc}
📄 CodeRabbit inference engine (.cursor/rules/cursor-rules.mdc)
Never place rule files in the project root, in subdirectories outside .cursor/rules, or in any other location
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.tsversion.txt
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/form-handling.mdc)
**/*.ts: The same validation should be done in the server action too
Define validation schemas using Zod
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
apps/web/utils/gmail/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/gmail-api.mdc)
Keep provider-specific implementation details isolated in the appropriate utils subfolder (e.g., 'apps/web/utils/gmail/')
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/logging.mdc)
**/*.{ts,tsx}: UsecreateScopedLoggerfor logging in backend TypeScript files
Typically add the logger initialization at the top of the file when usingcreateScopedLogger
Only use.with()on a logger instance within a specific function, not for a global loggerImport Prisma in the project using
import prisma from "@/utils/prisma";
**/*.{ts,tsx}: Don't use TypeScript enums.
Don't use TypeScript const enum.
Don't use the TypeScript directive @ts-ignore.
Don't use primitive type aliases or misleading types.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use implicit any type on variable declarations.
Don't let variables evolve into any type through reassignments.
Don't use non-null assertions with the ! postfix operator.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use user-defined types.
Use as const instead of literal types and type annotations.
Use export type for types.
Use import type for types.
Don't declare empty interfaces.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use TypeScript namespaces.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use parameter properties in class constructors.
Use either T[] or Array consistently.
Initialize each enum member value explicitly.
Make sure all enum members are literal values.
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
**/*.test.{ts,js}
📄 CodeRabbit inference engine (.cursor/rules/security.mdc)
Include security tests in your test suites to verify authentication, authorization, and error handling.
Files:
apps/web/utils/gmail/retry.test.ts
apps/web/utils/**
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
Create utility functions in
utils/folder for reusable logic
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
apps/web/utils/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
apps/web/utils/**/*.ts: Use lodash utilities for common operations (arrays, objects, strings)
Import specific lodash functions to minimize bundle size
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{js,jsx,ts,tsx}: Don't useelements in Next.js projects.
Don't use elements in Next.js projects.
Don't use namespace imports.
Don't access namespace imports dynamically.
Don't use global eval().
Don't use console.
Don't use debugger.
Don't use var.
Don't use with statements in non-strict contexts.
Don't use the arguments object.
Don't use consecutive spaces in regular expression literals.
Don't use the comma operator.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use useless this aliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names th...
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
!pages/_document.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
!pages/_document.{js,jsx,ts,tsx}: Don't import next/document outside of pages/_document.jsx in Next.js projects.
Don't import next/document outside of pages/_document.jsx in Next.js projects.
Files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.tsversion.txt
**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{test,spec}.{js,jsx,ts,tsx}: Don't use export or module.exports in test files.
Don't use focused tests.
Don't use disabled tests.
Make sure the assertion function, like expect, is placed inside an it() function call.
Don't nest describe() blocks too deeply in test files.
Don't use focused tests.
Don't use disabled tests.
Don't use export or module.exports in test files.
Files:
apps/web/utils/gmail/retry.test.ts
**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/testing.mdc)
**/*.test.{ts,tsx}: Use Vitest (vitest) as the testing framework
Colocate tests next to the file under test (e.g., dir/format.ts with dir/format.test.ts)
In tests, mock theserver-onlymodule withvi.mock("server-only", () => ({}));
When testing code that uses Prisma, mock it withvi.mock("@/utils/prisma")and use the mock from@/utils/__mocks__/prisma
Use provided helpers for mocks: import{ getEmail, getEmailAccount, getRule }from@/__tests__/helpers
Each test should be independent
Use descriptive test names
Mock external dependencies in tests
Clean up mocks between tests (e.g.,vi.clearAllMocks()inbeforeEach)
Avoid testing implementation details; focus on observable behavior
Do not mock the Logger
Files:
apps/web/utils/gmail/retry.test.ts
🧠 Learnings (16)
📓 Common learnings
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-09-17T22:05:28.646Z
Learning: Applies to apps/web/utils/ai/**/*.{ts,tsx} : Add retry logic for transient failures using withRetry
📚 Learning: 2025-09-17T22:05:28.646Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-09-17T22:05:28.646Z
Learning: Applies to apps/web/utils/ai/**/*.{ts,tsx} : Add retry logic for transient failures using withRetry
Applied to files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
📚 Learning: 2025-10-02T23:23:48.064Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-10-02T23:23:48.064Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Prefer existing helpers from @/__tests__/helpers.ts (getEmailAccount, getEmail, getRule, getMockMessage, getMockExecutedRule) over custom helpers
Applied to files:
apps/web/utils/gmail/retry.test.ts
📚 Learning: 2025-07-18T15:05:34.899Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/gmail-api.mdc:0-0
Timestamp: 2025-07-18T15:05:34.899Z
Learning: Applies to apps/web/utils/gmail/**/*.ts : Keep provider-specific implementation details isolated in the appropriate utils subfolder (e.g., 'apps/web/utils/gmail/')
Applied to files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/draft.tsapps/web/utils/gmail/trash.tsapps/web/utils/gmail/label.tsapps/web/utils/gmail/spam.tsapps/web/utils/gmail/retry.tsapps/web/utils/gmail/mail.ts
📚 Learning: 2025-10-02T23:23:48.064Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-10-02T23:23:48.064Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Include standard test cases: happy path, error handling, edge cases (empty/null), different user configurations, and various input formats
Applied to files:
apps/web/utils/gmail/retry.test.ts
📚 Learning: 2025-10-02T23:23:48.064Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-10-02T23:23:48.064Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Create helper functions for common test data (e.g., getUser, getTestData) to reduce duplication
Applied to files:
apps/web/utils/gmail/retry.test.ts
📚 Learning: 2025-09-20T18:24:34.280Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-09-20T18:24:34.280Z
Learning: Applies to **/*.test.{ts,tsx} : Use provided helpers for mocks: import `{ getEmail, getEmailAccount, getRule }` from `@/__tests__/helpers`
Applied to files:
apps/web/utils/gmail/retry.test.ts
📚 Learning: 2025-10-02T23:23:48.064Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-10-02T23:23:48.064Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Set a TIMEOUT of 15_000ms for LLM-related tests and pass it to long-running tests/describe blocks
Applied to files:
apps/web/utils/gmail/retry.test.ts
📚 Learning: 2025-10-02T23:23:48.064Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-10-02T23:23:48.064Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Test both AI and non-AI paths, including cases where no AI processing is required
Applied to files:
apps/web/utils/gmail/retry.test.ts
📚 Learning: 2025-10-02T23:23:48.064Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-10-02T23:23:48.064Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Gate LLM tests behind RUN_AI_TESTS using describe.runIf(process.env.RUN_AI_TESTS === "true")
Applied to files:
apps/web/utils/gmail/retry.test.ts
📚 Learning: 2025-09-17T22:05:28.646Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-09-17T22:05:28.646Z
Learning: Applies to apps/web/utils/ai/**/*.{ts,tsx} : Use proper error types and logging for failures
Applied to files:
apps/web/utils/gmail/retry.test.tsapps/web/utils/gmail/retry.ts
📚 Learning: 2025-09-17T22:05:28.646Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-09-17T22:05:28.646Z
Learning: Applies to apps/web/utils/{ai,llms}/**/*.{ts,tsx} : Keep related AI functions co-located and extract common patterns into utilities; document complex AI logic with clear comments
Applied to files:
apps/web/utils/gmail/trash.tsapps/web/utils/gmail/retry.ts
📚 Learning: 2025-07-20T09:00:41.968Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/security-audit.mdc:0-0
Timestamp: 2025-07-20T09:00:41.968Z
Learning: Applies to apps/web/app/api/**/*.{ts,js} : Review all new withError usage in API routes to ensure custom authentication is implemented where required.
Applied to files:
apps/web/utils/gmail/retry.ts
📚 Learning: 2025-09-17T22:05:28.646Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/llm.mdc:0-0
Timestamp: 2025-09-17T22:05:28.646Z
Learning: Applies to apps/web/utils/ai/**/*.{ts,tsx} : Implement fallbacks for AI failures
Applied to files:
apps/web/utils/gmail/retry.ts
📚 Learning: 2025-07-18T15:04:30.467Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: apps/web/CLAUDE.md:0-0
Timestamp: 2025-07-18T15:04:30.467Z
Learning: Applies to apps/web/**/*.{ts,tsx} : Use proper error handling with try/catch blocks
Applied to files:
apps/web/utils/gmail/retry.ts
📚 Learning: 2025-07-18T15:05:26.713Z
Learnt from: CR
Repo: elie222/inbox-zero PR: 0
File: .cursor/rules/get-api-route.mdc:0-0
Timestamp: 2025-07-18T15:05:26.713Z
Learning: Applies to app/api/**/route.ts : Always wrap the handler with `withAuth` or `withEmailAccount` for consistent error handling and authentication in GET API routes.
Applied to files:
apps/web/utils/gmail/mail.ts
🧬 Code graph analysis (6)
apps/web/utils/gmail/retry.test.ts (1)
apps/web/utils/gmail/retry.ts (2)
isRetryableError(33-62)calculateRetryDelay(67-106)
apps/web/utils/gmail/draft.ts (1)
apps/web/utils/gmail/retry.ts (1)
withGmailRetry(113-160)
apps/web/utils/gmail/trash.ts (1)
apps/web/utils/gmail/retry.ts (1)
withGmailRetry(113-160)
apps/web/utils/gmail/label.ts (1)
apps/web/utils/gmail/retry.ts (1)
withGmailRetry(113-160)
apps/web/utils/gmail/spam.ts (2)
apps/web/utils/gmail/retry.ts (1)
withGmailRetry(113-160)apps/web/utils/gmail/label.ts (1)
GmailLabel(20-34)
apps/web/utils/gmail/mail.ts (1)
apps/web/utils/gmail/retry.ts (1)
withGmailRetry(113-160)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: test
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (18)
version.txt (1)
1-1: LGTM! Version bump aligns with the new retry functionality.The version increment appropriately reflects the addition of Gmail retry logic across the codebase.
apps/web/utils/gmail/retry.ts (5)
7-28: Well-structured error normalization.The ErrorInfo type and extractErrorInfo helper provide robust error handling by normalizing various error shapes from the Gmail API. The fallback chains for status, reason, and errorMessage ensure resilience across different error structures.
33-62: Comprehensive retry classification logic.The error classification properly distinguishes between rate-limit errors and server errors, with good coverage of both status codes and error message patterns. The regex patterns on lines 47-48 and 55 handle cases where errors are embedded in messages (like HTML error pages).
67-106: Solid retry delay calculation with proper precedence.The delay calculation follows a sensible priority: embedded retry times, Retry-After headers, then fallback strategies. The exponential backoff for server errors (5s → 80s) and fixed 30s delay for rate limits align with Gmail API best practices.
113-160: Well-refactored retry orchestration.The refactored withGmailRetry leverages the new structured helpers effectively. The early exit for non-retryable errors (lines 124-131) prevents wasted retry attempts, and the detailed logging (lines 145-152) provides good observability for debugging retry behavior.
162-180: Robust retry time parsing.The parseRetryTime helper safely extracts and validates timestamps from Gmail error messages. The date validation on line 172 and try-catch block ensure the function never throws, returning null for invalid formats.
apps/web/utils/gmail/label.ts (3)
88-97: Good addition of retry protection for archive operations.The withGmailRetry wrapper adds resilience to the archive operation while preserving the existing Promise.allSettled error handling pattern and 404 detection downstream.
142-148: LGTM! Clean retry integration for label operations.The withGmailRetry wrapper properly protects the message modification call against transient Gmail API failures.
158-170: Proper retry integration for read/unread operations.The retry wrapper correctly protects both read and unread state changes, handling transient failures for either operation path.
apps/web/utils/gmail/spam.ts (1)
11-19: LGTM! Consistent retry integration for spam marking.The withGmailRetry wrapper adds resilience to spam marking operations, following the same pattern established in other Gmail utilities.
apps/web/utils/gmail/draft.ts (2)
10-25: Good retry integration with preserved error handling.The withGmailRetry wrapper on lines 12-18 adds resilience to draft retrieval while maintaining the existing 404 handling that returns null for missing drafts. The isGmailError check ensures type-safe error handling.
27-50: Solid retry integration with enhanced observability.The withGmailRetry wrapper (lines 30-35) adds resilience to draft deletion. The success log on line 39 improves observability, and the existing 404 handling (lines 41-44) continues to gracefully handle already-deleted drafts.
apps/web/utils/gmail/trash.ts (2)
20-25: Proper retry integration for trash operations.The withGmailRetry wrapper adds resilience to thread trashing while preserving the Promise.allSettled error handling pattern and the existing "Requested entity was not found" detection downstream.
77-82: LGTM! Clean retry integration for message trashing.The withGmailRetry wrapper properly protects the message trash operation against transient Gmail API failures.
apps/web/utils/gmail/mail.ts (4)
115-123: Good retry protection for email sending.The withGmailRetry wrapper adds resilience to email sending operations while maintaining the existing raw message construction and thread ID handling.
165-173: Proper retry integration for reply operations.The withGmailRetry wrapper correctly protects reply sending while preserving thread context and reply-to headers.
194-209: Excellent retry protection for attachment fetching.The withGmailRetry wrapper on lines 196-202 adds resilience to attachment downloads during forwarding. The Promise.all pattern maintains parallel fetching efficiency while each individual fetch benefits from retry protection.
226-234: Clean retry integration for forward operations.The withGmailRetry wrapper properly protects the forward email sending operation, completing the retry coverage for the entire forward workflow (attachments + send).
There was a problem hiding this comment.
1 issue found across 8 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="apps/web/utils/gmail/retry.ts">
<violation number="1" location="apps/web/utils/gmail/retry.ts:77">
If parseRetryTime or Retry-After produce a non-positive delay we now return 0, so the fallback 30s/exp backoff never runs. This regresses the previous behavior and causes immediate retries on rate-limited responses with stale retry hints.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
Summary by CodeRabbit
New Features
Tests
Chores