-
Notifications
You must be signed in to change notification settings - Fork 2
feat: auto retry on deployment-related 499 errors #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Refactored fetchEvaluationsInternal to accept options for shouldTrackFailure and timeoutMillis, enabling failure tracking only on the last allowed retry. Updated EvaluationTask to set shouldTrackFailure accordingly and added tests to verify correct behavior for failure tracking during retries.
Removed '(merged)' from the test suite name to accurately reflect the test context in EvaluationTask.spec.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors evaluation fetching to support conditional failure tracking during retries and adds tests to verify that tracking only occurs on the last allowed retry.
- Introduces an options object to fetchEvaluationsInternal to control shouldTrackFailure and timeoutMillis.
- Updates EvaluationTask to flag only the last retry for failure tracking and exposes getRetryCount for assertions.
- Adds unit tests for conditional tracking and improves test cleanup.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/internal/scheduler/EvaluationTask.spec.ts | Adds tests validating shouldTrackFailure behavior and tracking calls; adjusts suite name and test cleanup. |
| src/internal/scheduler/EvaluationTask.ts | Passes shouldTrackFailure based on last retry, adds isLastTry and getRetryCount. |
| src/BKTClient.ts | Refactors fetchEvaluations to pass options; fetchEvaluationsInternal now accepts options and conditionally tracks failures. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Refactored the fetchEvaluationsInternal method in BKTClientImpl to handle default options more explicitly and avoid mutation. Added comments to clarify the purpose of getRetryCount in EvaluationTask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Adjusted spacing in constructor and method calls for consistency. Set a default value for the options parameter in fetchEvaluationsInternal.
Added catch blocks to suppress errors from the storage layer when logging evaluation events, ensuring that these errors do not affect the main execution flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Simplified the way options are passed and destructured in fetchEvaluationsInternal for clarity and conciseness. Also reset the task variable to undefined in EvaluationTask.spec.ts after cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Simplified destructuring of the options parameter by removing the unnecessary nullish coalescing operator. This change improves code clarity.
Updated the mock implementation in EvaluationTask.spec.ts to use parameter types from BKTClientImpl.fetchEvaluationsInternal, improving type safety and maintainability in the test.
Introduces a futureRetriable function for retrying async operations with configurable retry policy and error filtering. Includes comprehensive unit tests covering success, delay, max retries, and conditional retry logic.
Renamed FutureRetriable.ts and its test to PromiseRetriable.ts, updating all references and function names accordingly. Refactored postInternal to use promiseRetriable for retry logic on deployment-related 499 errors, improving clarity and consistency in naming.
Introduces a 'backoffStrategy' option to the RetryPolicy, supporting 'linear' (default) and 'constant' delay strategies for retry attempts. Updates implementation to calculate delay per attempt and adds tests for both linear and constant backoff behaviors.
Introduces unit tests for ApiClientImpl to verify it calls postInternal with correct parameters, and for postInternal to ensure it retries on 499 Client Closed Request errors. These tests improve coverage and validate error handling and request logic.
Simplifies fetchEvaluationsInternal by removing the shouldTrackFailure option and always tracking failures. Refactors EvaluationTask to use a generic promiseRetriable utility for retries, removing custom retry state and logic. Updates tests to remove now-obsolete failure tracking and retry count tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Added 'backoffStrategy' to the retry policy in postInternal and ensured promiseRetriable is only called when EvaluationTask is running. This improves control over retry behavior and prevents unnecessary retries when the task is not active.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Added logic to EvaluationTask to prevent retrying if the polling interval is less than or equal to the retry interval. Updated tests to verify that retries are skipped when the polling interval is short enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Replaces runAllTimersAsync with advanceTimersByTimeAsync(1000) to more precisely control timer advancement during retry delay in postInternal tests. Also adds a comment for future cancellation support in PromiseRetriable.
- Fix scheduler stopping when pollingInterval <= retryInterval on error - Fix scheduler stopping after successful fetch with retryCount === 0 - Add tests to verify continuous scheduling behavior
Extended the test to verify that the timer triggers multiple times by checking the request count after running pending timers twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Adds console.debug statements to log errors from the storage layer in fetchEvaluations trackFailure and trackSuccess handlers. Also fixes a comment formatting issue in PromiseRetriable.ts.
Updated logging in fetchEvaluations to use console.error instead of console.debug for storage layer errors, making error visibility more prominent.
cre8ivejp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Fix #269
This pull request introduces a robust, reusable retry utility for asynchronous operations, applies it to critical networking and scheduling logic, and adds comprehensive tests to ensure reliability. The main improvements are the addition of a generic
promiseRetriablefunction, refactoring of network and evaluation scheduling code to use this utility, and enhanced test coverage for both the new utility and its integrations.Core Retry Utility:
promiseRetriablefunction inPromiseRetriable.tsthat provides configurable retry logic with support for linear and constant backoff strategies, and a customizable retry predicate. This includes theRetryPolicyandShouldRetryFntypes.Networking Improvements:
postInternalinpost.tsto usepromiseRetriable, enabling automatic retries (up to 3 times) on deployment-related 499 errors (ClientClosedRequestException). The core POST logic was moved to a private_postInternalfunction. [1] [2]Scheduler Improvements:
EvaluationTaskto usepromiseRetriablefor fetching evaluations, simplifying retry logic and ensuring retries only occur while the task is running. Removed manual retry counting and rescheduling logic. [1] [2] [3]Testing Enhancements:
promiseRetriablecovering success, failure, delay, backoff strategies, and early termination scenarios inPromiseRetriable.spec.ts.postInternalto verify retry behavior on 499 errors inpost.spec.ts.ApiClientImplto ensure it callspostInternalcorrectly inApiClientImpl.spec.ts.EvaluationTask.spec.tsby ensuringtask.stop()is always called and mocks are restored. [1] [2]Error Handling:
BKTClientImplto ignore errors from the storage layer when logging evaluation failures, preventing unhandled promise rejections. [1] [2]