feat(core): add UploadStateMachine for rate limiting (1/3)#1153
Closed
feat(core): add UploadStateMachine for rate limiting (1/3)#1153
Conversation
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>
14a1c97 to
160a84c
Compare
This was referenced Mar 6, 2026
Improvements to UploadStateMachine: - Add comprehensive JSDoc comments for all public methods - Add input validation in handle429() for negative/large retryAfterSeconds - Add logging when transitioning from RATE_LIMITED to READY - Add edge case tests for negative, zero, and very large retry values - Fix linting issues (template literal expressions, unsafe assignments) All 13 tests pass. Ready for review. 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
UploadStateMachinefor managing global rate limiting state (429 responses)RateLimitConfig,UploadStateData,HttpConfigtypes totypes.tsvalidateRateLimitConfiginconfig-validation.tswith SDD-specified boundsMerge order
This PR merges first. PR #1152 and #1150 rebase onto master after this lands.
Components
UploadStateMachine (135 lines)
State machine managing global rate limiting for 429 responses per the TAPI SDD.
Methods:
canUpload()— upload gate that respects rate limit wait timeshandle429(retryAfterSeconds)— sets RATE_LIMITED state with configurable retry limitsreset()— clears rate limit state on successful uploadgetGlobalRetryCount()— returns current retry count for X-Retry-Count headerStates:
READY|RATE_LIMITEDPersists state across app restarts via sovran store.
Config Validation (42 lines)
Validates and clamps rate limit configuration to safe ranges:
maxRetryInterval: 0.1s – 86,400smaxRateLimitDuration: 60s – 604,800smaxRetryCount: 1 – 100Type Definitions (19 lines added to types.ts)
RateLimitConfig— rate limit settings from Settings CDNUploadStateData— state machine persistence shapeHttpConfig— container onSegmentAPISettingsTest plan
devbox run test-unitpassesgit diff master -- .github/ scripts/ wiki/is empty)