Configure Telegram API retries#528
Conversation
|
Warning Review limit reached
Next review available in: 57 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughStickerify.execute(...) now retries Telegram API responses that include retry_after, waits between attempts, and preserves interrupt status if sleeping is interrupted. Tests add a retryable failure mock and verify the retry path. ChangesExecute Retry Behaviour
Sequence Diagram(s)sequenceDiagram
participant Stickerify
participant Telegram API
Stickerify->>Telegram API: execute(request)
Telegram API-->>Stickerify: non-OK response with retry_after
Stickerify->>Stickerify: sleep(Duration.ofSeconds(retryAfter))
Stickerify->>Telegram API: execute(request) retry
Telegram API-->>Stickerify: retry response
alt response OK
Stickerify-->>Stickerify: return response
else interrupted or still not OK
Stickerify->>Stickerify: throw TelegramApiException
end
Related issues: None specified. Related PRs: None specified. Suggested labels: enhancement, reliability Suggested reviewers: None specified. Poem A request returns with “try again”, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java (1)
227-247: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winRetry only transient Telegram failures. This helper sleeps for 15s and retries every non-OK response, which just delays permanent errors and can duplicate non-idempotent sends. Use
response.parameters()/retry_afterfor 429 responses and fail fast for everything else.
🧹 Nitpick comments (1)
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java (1)
234-245: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMagic number and no retry logging.
Duration.ofSeconds(15)is a hardcoded literal embedded in the method body; extracting it to a named constant (e.g.RETRY_DELAY) would make the intent and tunability clearer. Also consider logging the retry attempt (and eventual failure) for observability, since silent 15s delays followed by a thrown exception are otherwise hard to diagnose in production.♻️ Suggested refactor
+ private static final Duration RETRY_DELAY = Duration.ofSeconds(15); + private <T extends BaseRequest<T, R>, R extends BaseResponse> R execute(BaseRequest<T, R> request) throws TelegramApiException { var response = bot.execute(request); if (response.isOk()) { return response; } try { - Thread.sleep(Duration.ofSeconds(15)); + LOGGER.at(Level.WARN).log("Retrying failed Telegram API request after delay"); + Thread.sleep(RETRY_DELAY);
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a4ce9f04-5d46-49fa-ad11-d5a026ef2a66
📒 Files selected for processing (1)
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
…returned from telegram
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java (1)
227-253: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftAdd test coverage for the new retry behaviour.
This is a non-trivial control-flow change (retry count cap, conditional retry-after check, sleep, interrupt handling) with no accompanying test changes provided.
StickerifyTest.javaexists as the natural home for these cases (successful retry, exhausted retries, interrupt during sleep, no retry-after present).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d7c0d709-4108-4ed7-9a8e-d1928eb4ad05
📒 Files selected for processing (1)
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
…, and added test to check on the new logic
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/test/java/com/github/stickerifier/stickerify/bot/MockResponses.java (1)
16-26: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winReduce
retry_afterto shrink real test wall-time.
Stickerify.execute()performs an actualThread.sleep(Duration.ofSeconds(retryDelay))on retry, so this mock'sretry_after: 3makesretryApiCallgenuinely block for 3 real seconds every run. SinceisRetriableonly requiresretryAfter > 0, using1instead of3still exercises the retry path while keeping the test suite faster.♻️ Proposed fix
static final MockResponse FAILURE_RESPONSE = new MockResponse.Builder().body(""" { ok: false, error_code: 429, - description: "Too Many Requests: retry after 3", + description: "Too Many Requests: retry after 1", parameters: { - retry_after: 3 + retry_after: 1 } } """).build();
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f2a0e62d-15e4-414c-a1c2-3fd7f7f64bc5
📒 Files selected for processing (3)
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.javasrc/test/java/com/github/stickerifier/stickerify/bot/MockResponses.javasrc/test/java/com/github/stickerifier/stickerify/bot/StickerifyTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
Summary by CodeRabbit
retry_afterdelay (up to 3 attempts).