feat(core): add BackoffManager for transient error backoff (2/3)#1152
Closed
feat(core): add BackoffManager for transient error backoff (2/3)#1152
Conversation
3 tasks
abueide
added a commit
that referenced
this pull request
Mar 6, 2026
Adds comprehensive extended test suites for edge cases and implementation details that supplement the core tests in the feature PRs: - UploadStateMachine.extended.test.ts: disabled config, multiple retries, getter tests, persistence tests - BatchUploadManager.extended.test.ts: unique IDs, disabled config, getter tests, detailed exponential backoff algorithm tests, persistence tests - SegmentDestination.extended.test.ts: state reset after success, legacy behavior, Retry-After header parsing These tests provide thorough coverage of edge cases, backwards compatibility, and implementation details without adding bulk to the core feature PRs. Related to PRs: #1150, #1151, #1152, #1153 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add the UploadStateMachine component for managing global rate limiting state for 429 responses, along with supporting types and config validation. Components: - RateLimitConfig, UploadStateData, HttpConfig types - validateRateLimitConfig with SDD-specified bounds - UploadStateMachine with canUpload/handle429/reset/getGlobalRetryCount - Core test suite (10 tests) and test helpers - backoff/index.ts barrel export Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add global transient error backoff manager that replaces the per-batch BatchUploadManager. Uses same exponential backoff formula from the SDD but tracks state globally rather than per-batch, which aligns with the RN SDK's queue model where batch identities are ephemeral. Components: - BackoffConfig, BackoffStateData types - Expanded HttpConfig to include backoffConfig - validateBackoffConfig with SDD-specified bounds - BackoffManager with canRetry/handleTransientError/reset/getRetryCount - Core test suite (12 tests) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fdee650 to
70679d7
Compare
3 tasks
…Manager Improvements to BackoffManager: - Add comprehensive JSDoc comments for all public methods - Add logging when transitioning from BACKING_OFF to READY - Fix template literal expression errors with unknown types - Add edge case tests for multiple status codes and long durations - Fix linting issues (unsafe assignments in mocks) All 14 tests pass. Ready for review. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
CRITICAL FIX: Fixed off-by-one error in exponential backoff calculation - Was using newRetryCount (retry 1 → 2^1 = 2s), now uses state.retryCount (retry 1 → 2^0 = 0.5s) - Now correctly implements SDD progression: 0.5s, 1s, 2s, 4s, 8s, 16s, 32s DOCUMENTATION: Added design rationale for global vs per-batch backoff - Documented deviation from SDD's per-batch approach - Explained RN SDK architecture constraints (no stable batch identities) - Provided rationale: equivalent in practice during TAPI outages TESTS: Updated all tests to verify SDD-compliant behavior - Fixed exponential progression test (was testing wrong values) - Added comprehensive SDD formula validation test (7 retry progression) - Fixed jitter test to match new 0.5s base delay - All 15 tests pass Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Contributor
Author
|
Superseded by #1154 |
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
BackoffManagerfor global transient error backoff (5xx, 408, 410, 460)BackoffConfig,BackoffStateDatatypes totypes.tsHttpConfigto includebackoffConfigvalidateBackoffConfiginconfig-validation.tswith SDD-specified boundsMerge order
Depends on #1153. Rebase onto master after #1153 lands.
Design decision: Global vs per-batch backoff
The SDD assumes file-based batches with stable identifiers (
{writeKey}-{fileIndex}). The RN SDK uses a queue model wherechunk()inSegmentDestination.sendEvents()produces new arrays each flush — there is no stable batch identity across flushes.Solution:
BackoffManagertracks global transient error state instead of per-batch metadata. Same exponential backoff formula, but state is global. This is equivalent in practice because during a TAPI outage all batches fail anyway. Within a single flush, all batches are still attempted sequentially per the SDD.Components
BackoffManager (148 lines)
Global transient error backoff manager.
Methods:
canRetry()— gates the flush (like UploadStateMachine'scanUpload())handleTransientError(statusCode)— sets exponential backoffreset()— clears on successgetRetryCount()— returns current count for X-Retry-Count headerStates:
READY|BACKING_OFFBackoff formula:
min(baseBackoffInterval * 2^retryCount, maxBackoffInterval) + jitterConfig Validation (61 lines added)
Validates and clamps backoff configuration to safe ranges:
maxBackoffInterval: 0.1s – 86,400sbaseBackoffInterval: 0.1s – 300smaxTotalBackoffDuration: 60s – 604,800sjitterPercent: 0 – 100maxRetryCount: 1 – 100Type Definitions (20 lines added to types.ts)
BackoffConfig— backoff settings from Settings CDNBackoffStateData— backoff state persistence shapeHttpConfigto includebackoffConfigTest plan
devbox run test-unitpasses