🐛 fix(limiter): distinguish TransactionConflict from ConditionalCheckFailed in _commit_initial (#332)#401
Merged
Merged
Conversation
…Failed in _commit_initial (#332) TransactionConflict during cascade contention was incorrectly treated as ConditionalCheckFailed, causing false RateLimitExceeded with retry_after_seconds=0.0. The fix inspects CancellationReasons to distinguish transient contention (retry original transaction with exponential backoff) from optimistic lock failures (consumption-only retry path). - Add _get_cancellation_reason_codes() and _is_transaction_conflict() - Fix _is_condition_check_failure() to inspect CancellationReasons - Add TransactionConflict retry loop (3 retries, 25/50/100ms backoff) - Fix _build_retry_failure_statuses() to compute retry_after_seconds from bucket state via calculate_retry_after() Fixes #332 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #401 +/- ##
==========================================
+ Coverage 91.89% 91.93% +0.03%
==========================================
Files 33 33
Lines 7437 7473 +36
==========================================
+ Hits 6834 6870 +36
Misses 603 603
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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
TransactionConflictfromConditionalCheckFailedin_is_condition_check_failure()by inspectingCancellationReasonscodes instead of treating allTransactionCanceledExceptionthe same_is_transaction_conflict()helper and retry loop with exponential backoff (25ms base, 3 retries) for transient contention errors in_commit_initial()_build_retry_failure_statuses()to computeretry_after_secondsfrom bucket state viacalculate_retry_after()instead of hardcoding0.0lease.py) and sync (sync_lease.py) code pathsTest plan
_is_condition_check_failure(): pure ConditionalCheckFailed, pure TransactionConflict, mixed reasons, no response attribute_is_transaction_conflict(): pure conflict, condition-check-only, unrelated exceptions, ClientError fallback_build_retry_failure_statuses()computes non-zeroretry_after_secondsfrom deficit_build_retry_failure_statuses()returns 0.0 when no deficituv run pytest tests/unit/ -vCloses #332
🤖 Generated with Claude Code