fix: bound inbound email listener polling and add rate-limit retry#248
Open
bukinoshita wants to merge 5 commits intomainfrom
Open
fix: bound inbound email listener polling and add rate-limit retry#248bukinoshita wants to merge 5 commits intomainfrom
bukinoshita wants to merge 5 commits intomainfrom
Conversation
Extract retry logic for rate_limit_exceeded (429) errors into a standalone utility. Retries up to 3 times using the retry-after header when available, falling back to exponential backoff (1s, 2s, 4s). Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
- Cap pages fetched per poll to MAX_PAGES_PER_POLL (5) so large email backlogs don't cause unbounded API request storms. - Checkpoint seenIds after each page fetch so mid-poll errors preserve progress instead of discarding already-fetched emails. - Wrap receiving.list() calls with withRetry to handle 429 rate-limit responses with automatic backoff. - Convert to functional style with const arrow functions and recursive fetchPages replacing the imperative while loop. Closes BU-638 Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
- Add with-retry.test.ts covering success, non-retryable errors, rate-limit retries with backoff, max retry exhaustion, and retry-after header parsing. - Add listen tests for multi-page pagination, page cap enforcement, incremental checkpointing on mid-poll errors, rate-limit retry integration, and chronological email display order. - Switch from mockClear to mockReset with resetModules to prevent mock state leaking between tests. Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
Member
Author
|
@cubic-dev-ai review this PR? |
Contributor
@bukinoshita I have started the AI code review. It will take a few minutes to complete. |
Contributor
There was a problem hiding this comment.
2 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/lib/with-retry.test.ts">
<violation number="1" location="tests/lib/with-retry.test.ts:33">
P2: Restore fake timers in a `finally` block (or shared cleanup). As written, a failure before `vi.useRealTimers()` will leak fake timers into later tests.</violation>
</file>
<file name="src/lib/with-retry.ts">
<violation number="1" location="src/lib/with-retry.ts:17">
P1: Handle HTTP-date `Retry-After` values as well as numeric seconds, or 429 retries can still fire earlier than the server allows.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
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 by cubic
Bound the inbound email listener’s pagination and added automatic 429 retry to prevent request storms and lost progress during inbox bursts.
Bug Fixes
receiving.list()requests.withRetryusingretry-afteror 1s/2s/4s backoff.Refactors
src/lib/with-retry.tsreusable helper (retries up to 3 times).fetchPagesflow using const arrow functions.Written for commit 3d64b3d. Summary will update on new commits.