feat(core): add TAPI backoff v2 infrastructure (1/3)#1149
Closed
feat(core): add TAPI backoff v2 infrastructure (1/3)#1149
Conversation
Adds core backoff infrastructure without integration into upload flow. This PR establishes the foundation for intelligent retry logic. Components added: - UploadStateMachine: Manages global rate limiting state (429 responses) - BatchUploadManager: Per-batch exponential backoff (transient errors) - Config validation: Validates and applies defaults to backoff configs - Type definitions: HttpConfig, RateLimitConfig, BackoffConfig, etc. Key features: - RATE_LIMITED state with migration from legacy WAITING state - Metadata validation on app restart to handle corrupted timestamps - Batch metadata only created on first failure (not prematurely) - Exponential backoff with jitter for transient errors - Configurable behavior via Settings CDN This PR does not integrate with SegmentDestination yet - that comes in a follow-up PR to keep review size manageable. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This was referenced Mar 6, 2026
Contributor
Author
|
Note: Unit tests for the backoff infrastructure will be added in a separate PR to keep the review focused on the implementation. |
Contributor
Author
|
Closing this PR - infrastructure split into two separate PRs for better reviewability:
New PRs to be created shortly. |
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.
Overview
This PR adds the core backoff infrastructure for TAPI backoff v2. This is part 1 of a 3-part implementation that establishes the foundation without integration into the upload flow.
Related PRs:
Components Added
UploadStateMachine
Manages global rate limiting state for 429 responses.
Key methods:
canUpload(): Upload gate that respects rate limit wait timeshandle429(): Sets rate limit state with configurable retry limitsreset(): Clears rate limit state on successful uploadThe state machine persists state across app restarts and supports two states:
READYandRATE_LIMITED.BatchUploadManager
Handles per-batch exponential backoff for transient errors like 5xx responses and network failures.
Key methods:
createBatch(): Creates metadata for a batch (only called on first failure)handleRetry(): Calculates exponential backoff with jitter and updates metadatavalidatePersistedMetadata(): Validates timestamps on app restart and drops corrupted batchesremoveBatch(): Removes metadata after successful upload or when limits exceededConfig Validation
Provides validation and default application for backoff configurations:
validateRateLimitConfig(): Validates rate limit configurationvalidateBackoffConfig(): Validates backoff configurationEnsures all numeric values are within safe bounds and applies sensible defaults when values are missing.
Type Definitions
Adds TypeScript types for the backoff system:
HttpConfig: Container for Settings CDN configurationRateLimitConfig: Global rate limiting configurationBackoffConfig: Per-batch backoff configurationUploadStateData: State machine persistence typesBatchMetadata: Per-batch retry metadataErrorClassification: Error classification result typeImplementation Details
State Migration
The state machine automatically migrates legacy
WAITINGstate toRATE_LIMITEDon app startup to maintain compatibility with any persisted state from development builds.Metadata Validation
On app restart, the BatchUploadManager validates all persisted batch metadata timestamps. Batches with corrupted or invalid timestamps (negative values, far-future dates, or dates in the past) are automatically dropped to prevent issues.
Batch Lifecycle
Batch metadata is only created on the first failure, not when the batch is initially created. This prevents unnecessary persistence overhead for successful uploads.
Configuration
Both rate limiting and backoff behavior can be configured via Settings CDN through the
httpConfigfield. The implementation includes production-ready defaults that can be overridden per workspace.Testing
These components are designed to be unit-testable in isolation. Integration testing will be covered when these components are integrated into the upload flow in part 3.
Dependencies
This PR has no dependencies and can be reviewed independently.