fix(metering): prevent double-metering on checkout retry across second boundary (#1151) - #1206
Closed
ayomidearegbeshola29-dev wants to merge 1 commit into
Conversation
…ing on checkout retry (StellerCraft#1151)
Contributor
Author
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.
Prevent double-metering when a checkout retry crosses a one-second boundary (#1151)
Summary
Closes #1151
PaymentIdempotencyServicede-duplicates a retried checkout within a 24h windowkeyed by
(userId, operationType, requestFingerprint).MeteringService, however,derived its own idempotency key as
operationType-userId-<second>, so a retry thatlanded in a different calendar second was correctly de-charged but incorrectly
metered twice for the same logical operation.
Root-cause fix
MeteringService.recordUsage(...)now accepts an optionaldedupKey. Whensupplied it is used as the
idempotency_key(theonConflicttarget) instead ofthe one-second-derived key, so two calls that share a logical identity collapse to
a single usage record.
MeteringPaymentIntegration.reportUsage(...)now accepts apaymentIdempotencyKeyand forwards it torecordUsage. Callers that already holdthe payment idempotency key for the underlying checkout can now thread it through,
making metering follow the payment layer's notion of "same logical operation"
regardless of elapsed seconds.
Test
metered-billing-payment.checkout-retry-dedup.integration.test.tssimulates acheckout retry (original + retry in a different second) and asserts exactly one
unique
idempotency_keyis produced when the payment idempotency key is threadedthrough. A second case pins
Date.nowacross a second boundary to prove theboundary no longer matters.
Note on the companion fix
The issue references a "companion backend-scoped concurrency-cap fix". This PR is the
metering-layer half; once that concurrency cap lands, the integration test's
large-deployment scenario can be layered on top without further changes to the dedup
path.
closes #1151