Repository navigation
Conversation
A refund that transitions FAILED -> REFUNDED (late provider confirmation) was excluded from committedAmount, allowing a second refund to be created for the same amount. The total refunded could then exceed the payment. Three fixes: - committedAmount now includes FAILED refunds that have a provider reference, since the provider may still confirm them - RefundTransitions raises an alert on late refund and on cumulative exceeding the payment amount - Settlement verifies confirmed amounts for refunds and payouts, matching the existing check in settlePayment
mooder1
force-pushed
the
fix/over-refund-settlement-guards
branch
from
November 17, 2026 20:53
d8cadd3 to
88d4164
Compare
- YoonLateSuccess now matches late_refund alongside late_success/late_payout - New critical alert YoonRefundExceedsPayment for over-refund detection - Runbook: amount mismatch section covers refunds and payouts, new section for refund-exceeds-payment with recovery steps
Owner
|
Thanks a lot for this, @mooder1 — the diagnosis is right and the reproduction is exactly the hole: a refund settled FAILED that the provider later confirms REFUNDED frees its amount in the meantime, so a second refund can push the total past the payment. Good catch, and good call using Before this can go in, a few things:
We're going to fold this into a wider money-safety pass on main (it turned up a few related gaps in settlement and recovery), so I'll carry your fix forward with the tests and credit you as co-author on the commit. Feel free to keep the PR open to follow along; we'll close it with a link once it lands. Thanks again! |
crossben
added a commit
that referenced
this pull request
Nov 21, 2026
…efunds and payouts A refund the provider saw and then reported failed keeps its amount until an operator releases it (admin API + refunds CLI); late refunds and over-refunds raise alerts; refunds and payouts confirmed at another amount are flagged for review instead of settled. Money-safety plan M1 (C1, H1), from PR #1. Co-Authored-By: mooder1 <108179967+mooder1@users.noreply.github.com>
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
FAILED → REFUNDED(late provider confirmation) was excluded fromcommittedAmount(), allowing a second refund to consume the freed space. The cumulative refunded total could exceed the payment amount, causing direct financial loss.committedAmount()now includes FAILED refunds that have aprovider_reference(the provider saw the request and may still confirm it)RefundTransitionsraiseslate_refundandrefund_exceeds_paymentalerts when a late success is detected and when the total exceeds the paymentSettlement.settleRefund()andSettlement.settlePayout()now verifyconfirmedAmountagainst expected, matching the existing guard insettlePayment()Reproduction scenario (before fix)
Unknown(timeout after accept),provider_referencesetFAILEDvia provider status APIcommittedAmount()returns 0 (FAILED excluded)remaining = 10 000)REFUNDED(late success),FAILED → REFUNDED = APPLYChanges
Alerts.javalate_refundandrefund_exceeds_paymentalert typesRefundRepository.javacommittedAmountincludes FAILED refunds withprovider_referenceRefundTransitions.javaSettlement.javaDesign notes
FAILED → REFUNDED = APPLY) is intentionally permissive per ADR: losing real money is worse than a surprised app. The fix prevents creating a second refund during the vulnerability window, and raises alerts for operator visibility if the race was already lost.payments.find()is used instead ofpayments.lock()inRefundTransitionsto avoid reversing the documented lock order (payment → refund). The payment amount is immutable, so a snapshot read is sufficient.provider_reference(definitively rejected before the provider processed them) remain excluded fromcommittedAmount, preserving the existing retry behavior tested inRefundApiTest.a_rejected_refund_is_failed_and_frees_the_amount_again.Test plan
RefundApiTest.partial_refunds_are_allowed_up_to_the_payment_amountpassesRefundApiTest.concurrent_refunds_can_never_exceed_what_was_paidpassesRefundApiTest.a_rejected_refund_is_failed_and_frees_the_amount_againpasses (rejected refunds still free the amount)provider_referenceblocks further refunds for the same amountsettleRefundandsettlePayoutreject amount mismatches withAMOUNT_MISMATCH./mvnw verifyclean