feat: Add smart retry system with rate limiting and exponential backoff#426
feat: Add smart retry system with rate limiting and exponential backoff#426didiergarcia wants to merge 19 commits intomainfrom
Conversation
- Add PipelineState enum (ready, rateLimited) - Add RetryBehavior enum (retry, drop) - Add DropReason and UploadDecision types - Add ResponseInfo struct Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #426 +/- ##
==========================================
+ Coverage 71.20% 72.30% +1.09%
==========================================
Files 49 54 +5
Lines 3706 3943 +237
==========================================
+ Hits 2639 2851 +212
- Misses 1067 1092 +25
🚀 New features to boost your workflow:
|
Expand test coverage to match analytics-kotlin implementation: - Add 20 new RetryStateMachine tests (5 → 25) - Add 10 new HttpConfig tests (3 → 13) - Add 5 new Storage tests (2 → 7) - Total: 52 tests (up from 17) New test coverage: - Status code overrides (408→RETRY, 501→DROP, etc) - 4xx/5xx default behaviors and unknown codes - Exponential backoff calculation verification - Rate limit edge cases (clamps, defaults, global retry count reset) - shouldUploadBatch drops (max retries, max duration exceeded) - getRetryCount all scenarios (new batch, per-batch, global, max) - Legacy mode comprehensive tests (all features disabled) - Storage persistence edge cases (null fields, overwrites, multiple batches) All 52 tests passing. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Test Coverage UpdateExpanded test coverage from 17 to 52 tests to match analytics-kotlin implementation. Detailed Breakdown:RetryStateMachine_Tests: 25 tests (+20)
HttpConfig_Tests: 13 tests (+10)
Storage_RetryState_Tests: 7 tests (+5)
RetryChain_Tests: 2 tests
RetryState_Tests: 4 tests All 52 tests passing ✅ |
Add 7 validation tests to guard against corrupted persisted state: **RetryState_Tests (+5 tests):** - testIsRateLimited_HandlesUnreasonableWaitTime: Documents infinite blocking risk when waitUntilTime is corrupted - testExceedsMaxDuration_HandlesClockSkewGracefully: Verifies conservative behavior when firstFailureTime is in future (clock went backwards) - testBatchMetadata_HandlesNegativeFailureCount: Documents that negative failureCount bypasses max retry check - testIsRateLimited_ReturnsFalseWhenWaitTimeIsNil: Verifies guard clause protects against nil waitUntilTime - testExceedsMaxDuration_ReturnsFalseWhenFirstFailureTimeIsNil: Verifies guard clause protects against nil firstFailureTime **Storage_RetryState_Tests (+2 tests):** - testLoadRetryState_ReturnsDefaultsForCorruptData: Verifies PropertyListDecoder error handling returns safe defaults - testLoadRetryState_HandlesUnreasonablePersistedValues: Documents that extreme values (Int.max, far-future timestamps) are loaded without error These tests address potential failure modes from: - System clock changes (NTP sync, user manual adjustment, daylight saving) - Storage corruption (disk errors, incomplete writes) - App updates with schema changes Based on React Native RetryManager persistence validation patterns. Total test count: 52 → 59 tests All 59 tests passing ✅ Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Persistence Validation Tests AddedBased on React Native RetryManager review (PR #1159), added 7 validation tests to guard against corrupted persisted state. Tests Added:RetryState_Tests (+5):
Storage_RetryState_Tests (+2):
Why These Tests Matter:Clock Skew Scenarios:
Storage Corruption:
Test Count: 52 → 59 testsAll 59 tests passing ✅ Commit: 2ed67f1 |
Summary
Port of the smart retry system from analytics-kotlin to analytics-swift, adding HTTP 429 rate limiting and 5xx exponential backoff capabilities to the HTTPClient.
Key Components
Test Coverage
Configuration Example
🤖 Generated with Claude Code