This repository was archived by the owner on Nov 14, 2025. It is now read-only.
feat: Add automatic retry with exponential backoff and circuit breaker#180
Merged
sapientpants merged 11 commits intomainfrom Sep 23, 2025
Merged
feat: Add automatic retry with exponential backoff and circuit breaker#180sapientpants merged 11 commits intomainfrom
sapientpants merged 11 commits intomainfrom
Conversation
Implements intelligent retry logic for improved reliability when the DeepSource API experiences transient failures. This feature ensures high availability without user intervention during API instability, rate limit spikes, or temporary network issues. Key features: - Exponential backoff with jitter to prevent thundering herd - Per-endpoint circuit breaker pattern to prevent cascade failures - Retry budget management to limit resource consumption - Respect for Retry-After headers from the API - Automatic handling of transient failures (network, 502, 503, 504) - Rate-limited requests (429) are automatically retried Configuration via environment variables: - RETRY_MAX_ATTEMPTS (default: 3) - RETRY_BASE_DELAY_MS (default: 1000ms) - RETRY_MAX_DELAY_MS (default: 30000ms) - RETRY_BUDGET_PER_MINUTE (default: 10) - CIRCUIT_BREAKER_THRESHOLD (default: 5) - CIRCUIT_BREAKER_TIMEOUT_MS (default: 30000ms) Safety features: - Only retries idempotent operations (queries/GET requests) - Never retries mutations (update operations) - Transparent to MCP clients - no user-visible errors during transient failures Closes #153 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Here's the code health analysis summary for commits Analysis Summary
Code Coverage Report
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements automatic retry logic with exponential backoff and circuit breaker patterns to improve reliability when the DeepSource API experiences transient failures. The implementation ensures high availability without user intervention during API instability, rate limiting, or temporary network issues.
Key changes include:
- Intelligent retry policies for different operation types (aggressive for critical reads, none for mutations)
- Exponential backoff with jitter and circuit breaker patterns for fault tolerance
- Retry budget management to prevent resource exhaustion
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/utils/retry/retry-policy.ts |
Configurable retry policies with environment variable support |
src/utils/retry/retry-executor.ts |
Main orchestrator combining all retry components |
src/utils/retry/retry-budget.ts |
Budget management to limit retries per time window |
src/utils/retry/exponential-backoff.ts |
Exponential backoff calculations with jitter |
src/utils/retry/circuit-breaker.ts |
Circuit breaker implementation for fault tolerance |
src/utils/retry/index.ts |
Export aggregation for retry utilities |
src/utils/errors/handlers.ts |
Enhanced error handlers with retry support |
src/client/base-client.ts |
Integration of retry logic into GraphQL execution |
src/__tests__/utils/retry/*.test.ts |
Comprehensive test coverage for all components |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Remove unused beforeEach import from test file - Replace non-null assertions with proper error handling - Fix lexical declaration scoping in switch statements - Update test expectations to match corrected behavior - Remove unused @playwright/test dev dependency Fixes issues identified in PR #180 by DeepSource: - JS-0356: Unused variables (1 major issue) - JS-0339: Non-null assertions (2 major issues) - JS-0054: Lexical declarations in case clauses (3 minor issues) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
The non-null assertions are safe because we just set the value in the Map immediately before retrieving it. Using ESLint disable comments instead of runtime checks avoids adding uncovered branches that would fail coverage thresholds.
Refactored getBreaker and getBudget methods to avoid non-null assertions entirely by storing the created instance in a variable before setting it in the Map. This eliminates the DeepSource JS-0339 issue while maintaining the required test coverage thresholds.
Fixed the test case 'should throw error when all retries fail' to properly handle the promise rejection, preventing unhandled rejection warnings and test failures in CI.
- JS-0105: Make isAxiosError method static as it doesn't use 'this' - JS-0047: Add default cases to switch statements in recordSuccess and recordFailure - JS-0045: Add explicit return statement in extractRetryAfter for consistency All DeepSource issues have been resolved. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Remove async keyword from sleep function and ensure all code paths return a Promise consistently. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add tests for circuit breaker default case handling (99.53% coverage) - Add comprehensive tests for RetryBudget and RetryBudgetManager (100% coverage) - Test getAllStats, resetAll, and clear methods - Overall retry module coverage improved to 97.26% 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add undefined check when accessing retryTimestamps array element - Add DeepSource skip comments for intentional any usage in tests - Fix formatting in circuit-breaker.ts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Implements intelligent retry logic with exponential backoff and circuit breaker pattern for improved reliability when the DeepSource API experiences transient failures. This feature ensures high availability without user intervention during API instability, rate limit spikes, or temporary network issues.
Changes
Core Retry Components
retry-policy.ts): Configurable policies for different endpoint types (aggressive, standard, cautious, none)exponential-backoff.ts): Implements exponential backoff with jitter to prevent thundering herdcircuit-breaker.ts): Per-endpoint circuit breakers with three states (closed, open, half-open)retry-budget.ts): Prevents resource exhaustion with per-minute retry limitsretry-executor.ts): Orchestrates all retry componentsIntegration
BaseClientto use retry logic for all GraphQL queriesKey Features
✅ Automatic Retry for Transient Failures
✅ Safety Features
✅ Resource Protection
Configuration
All retry parameters are configurable via environment variables:
RETRY_MAX_ATTEMPTSRETRY_BASE_DELAY_MSRETRY_MAX_DELAY_MSRETRY_BUDGET_PER_MINUTECIRCUIT_BREAKER_THRESHOLDCIRCUIT_BREAKER_TIMEOUT_MSTesting
Impact
This change significantly improves the reliability of the DeepSource MCP server:
Closes #153
🤖 Generated with Claude Code