fix(retry): enforce overall deadline budget across attempts#93
Merged
Conversation
Add `total_timeout` to `RetryConfig` so the wall-clock budget is shared across all retry attempts. Without this, a caller with `timeout=10` and `max_attempts=3` could wait up to `3*(10+backoff)` seconds total. When set, backoff sleeps are clipped to the remaining budget and the loop exits immediately when the budget is exhausted — either at the loop-top check or when `remaining <= 0` after a failure. `write_safe_config` propagates `total_timeout` to the derived config. Closes #58 Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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
timeout=10andmax_attempts=3could wait up to3*(10+backoff)seconds — far exceeding the intended budget.total_timeouttoRetryConfigso the wall-clock budget is enforced across all attempts: backoff sleeps are clipped to the remaining time, and the loop exits immediately when the budget is exhausted.Test plan
test_deadline_clips_sleep— verifies sleep is clipped to remaining budgettest_deadline_exhausted_raises_immediately— verifies no sleep occurs when budget is gone after a failuretest_deadline_already_passed_before_second_attempt— verifies loop-top check halts further attemptstest_write_safe_config_preserves_total_timeout— verifieswrite_safe_configpropagates the fieldtest_async_deadline_exhausted_raises_immediately— async variant of the exhausted-budget caseCloses #58