console: customer-create recovery spends one resend (plans 6b branch review round 2)
sendCustomerLocked caps its retries at zero whenever it recovers a stored customer attempt, so a Checkout POST's recovery is budget F (one clock probe and at most one resend), as Confirm now's already was. A newly prepared attempt keeps the three in-handler retries.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+30
−2
internal/console/billingcheckout.go+6 −2internal/console/billingcheckout_test.go+24 −0
diff --git a/internal/console/billingcheckout.go b/internal/console/billingcheckout.go| index 1c0d9846f..9a04fc335 100644 |
| --- a/internal/console/billingcheckout.go |
| +++ b/internal/console/billingcheckout.go |
| @@ -504,12 +504,16 @@ func customerResendState(b *billingAccount) resendState { |
| } |
| // sendCustomerLocked sends the stored customer create: first, when this |
| -// request just stored it; otherwise as a recovery, gated first. An unknown |
| -// delivery (no response, 409, 429) is resent up to retries times, each after |
| +// request just stored it; otherwise as a recovery, gated first and sent at |
| +// most once whatever retries says (budget F). An unknown delivery (no |
| +// response, 409, 429) on a first send is resent up to retries times, each after |
| // the backoff and only while recoveryEligible; there is no read to make, so |
| // the resend is the check, and provider time comes from the request's |
| // recorder or one probe. |
| func (s *Server) sendCustomerLocked(h billingHold, ctx context.Context, acct *Account, b *billingAccount, recovering bool, retries int, now time.Time) (customerOutcome, error) { |
| + if recovering { |
| + retries = 0 // a recovery is F: at most one resend, whoever calls |
| + } |
| for attempt := 0; ; attempt++ { |
| if recovering || attempt > 0 { |
| if attempt > 0 { |
diff --git a/internal/console/billingcheckout_test.go b/internal/console/billingcheckout_test.go| index 667ef5c35..12c3ab36c 100644 |
| --- a/internal/console/billingcheckout_test.go |
| +++ b/internal/console/billingcheckout_test.go |
| @@ -697,6 +697,30 @@ func TestCustomerCreateWindowClosedNewAttempt(t *testing.T) { |
| } |
| } |
| +// TestCustomerRecoverySpendsOneResend: a Checkout POST whose customer |
| +// create gets no answer through every in-handler retry leaves the attempt |
| +// stored; the next Checkout POST recovers it with one clock probe and at |
| +// most one resend of the stored bytes (budget F), however many times that |
| +// resend gets no answer. |
| +func TestCustomerRecoverySpendsOneResend(t *testing.T) { |
| + o := newCheckoutFixture(t, false) |
| + o.fake.FailBeforeDelivery = 1 + handlerRetries |
| + o.wantRefused(t, o.checkout(t, "plan", "personal", "currency", "usd"), billingCopy["checkout.uncertain"]) |
| + b, _ := o.st.BillingAccount(o.acct.ID) |
| + if b == nil || b.Customer != "" || b.CustomerPrepared == nil { |
| + t.Fatalf("billing row = %+v, want a stored customer attempt", b) |
| + } |
| + o.reset() |
| + o.fake.FailBeforeDelivery = 10 |
| + o.wantRefused(t, o.checkout(t, "plan", "personal", "currency", "usd"), billingCopy["checkout.uncertain"]) |
| + wantCounts(t, o.counts(), map[string]int{"ClockProbe": 1, "Send": 1}) |
| + for _, p := range o.sent() { |
| + if p.Key != b.CustomerPrepared.Key { |
| + t.Fatalf("sent %q, want only the stored attempt %q", p.Key, b.CustomerPrepared.Key) |
| + } |
| + } |
| +} |
| + |
| func TestCustomerRetryCountsNoRead(t *testing.T) { |
| o := newCheckoutFixture(t, false) |
| o.fresh() |