transfers: retry failing operator alerts within the hour
Controller's ruling on the final-review report's concern 2: owner emails keep their 1 h, 6 h, then daily backoff, but operator alerts, scheduled or owed (lapse, capture, cancel and refund failing, unpaid and the rest), are retried after at most an hour, so a lapse alert never lands after the hold has lapsed. TestTransferOperatorAlertRetriedWithinAnHour pins the 1 h retry on the third and later failures; the simulation's backoff check tightens from a day to the hour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+66
−12
internal/console/domaintransfer_bounded_test.go+44 −0internal/console/domaintransfer_decide.go+12 −3internal/console/domaintransfer_decide_test.go+3 −3internal/console/domaintransfer_notices.go+7 −6
diff --git a/internal/console/domaintransfer_bounded_test.go b/internal/console/domaintransfer_bounded_test.go| index 0a0228e71..62b8e44ab 100644 |
| --- a/internal/console/domaintransfer_bounded_test.go |
| +++ b/internal/console/domaintransfer_bounded_test.go |
| @@ -262,6 +262,50 @@ func TestTransferNoticePerOwnerWithBackoff(t *testing.T) { |
| } |
| } |
| +// TestTransferOperatorAlertRetriedWithinAnHour: an operator alert whose |
| +// page keeps failing is tried again within the hour on every failure, the |
| +// third and later ones included (an owner email would wait 6 h, then a |
| +// day), so a lapse alert never lands after the hold has lapsed. Once the |
| +// page goes through it is delivered once. |
| +func TestTransferOperatorAlertRetriedWithinAnHour(t *testing.T) { |
| + tf := newTransferFixture(t) |
| + tf.fake.CaptureWindow = 30 * time.Hour |
| + p := tf.start(t) |
| + tf.authorise(t, p) |
| + tf.reg.RequestErr = registrar.ErrIndeterminate // unknown: nothing captured, the hold stays |
| + p = tf.pass(t, p.ID) |
| + tf.pageErr = errors.New("paging down") |
| + tf.tick(7 * time.Hour) // within a day of the hold's lapse |
| + p = tf.pass(t, p.ID) |
| + for failures := 1; failures <= 5; failures++ { |
| + d := p.Facts.Delivery[alertLapse] |
| + if d.Failures != failures || d.NextAt.Sub(tf.now) != time.Hour { |
| + t.Fatalf("lapse alert after failure %d: %+v, next try %s from now, want 1h", failures, d, d.NextAt.Sub(tf.now)) |
| + } |
| + tf.tick(time.Hour) |
| + p = tf.pass(t, p.ID) |
| + } |
| + if tf.alerts(alertLapse) != 0 { |
| + t.Fatal("delivered while paging was down") |
| + } |
| + tf.pageErr = nil |
| + tf.tick(time.Hour) |
| + p = tf.pass(t, p.ID) |
| + p = tf.pass(t, p.ID) |
| + if tf.alerts(alertLapse) != 1 || p.Facts.Alerts[alertLapse].IsZero() || !tf.now.Before(p.Facts.CaptureBefore) { |
| + t.Fatalf("lapse alerts %d, delivered at %v, hold lapses %v", tf.alerts(alertLapse), p.Facts.Alerts[alertLapse], p.Facts.CaptureBefore) |
| + } |
| + // The schedules themselves: an owner email backs off further. |
| + for n, want := range []time.Duration{time.Hour, 6 * time.Hour, 24 * time.Hour, 24 * time.Hour} { |
| + if got := noticeBackoff(noticeOwnerDone, n+1); got != want { |
| + t.Fatalf("owner email after %d failures: %s, want %s", n+1, got, want) |
| + } |
| + if got := noticeBackoff(alertUnpaid, n+1); got != time.Hour { |
| + t.Fatalf("operator alert after %d failures: %s", n+1, got) |
| + } |
| + } |
| +} |
| + |
| // TestTransferNoticeDroppedOnPermanentFailures: an owner who blocked the |
| // console, no email sender, or an account deleted after the transfer ended |
| // end the notice's retries: it is given up with one operator alert, and |
diff --git a/internal/console/domaintransfer_decide.go b/internal/console/domaintransfer_decide.go| index 280b0505f..78c5040d4 100644 |
| --- a/internal/console/domaintransfer_decide.go |
| +++ b/internal/console/domaintransfer_decide.go |
| @@ -255,9 +255,14 @@ func nextCaptureAt(now time.Time, failures int, captureBefore time.Time) time.Ti |
| return now.Add(wait) |
| } |
| -// noticeBackoff is the wait after a notice's nth failed try: 1 h, 6 h, then |
| -// daily. |
| -func noticeBackoff(failures int) time.Duration { |
| +// noticeBackoff is the wait after the nth failed try of a notice of kind. |
| +// An owner email waits 1 h, 6 h, then daily. An operator alert (scheduled |
| +// or owed) waits at most transferAlertRetryMax, so a lapse alert, say, |
| +// never lands after the hold it warns of has lapsed. |
| +func noticeBackoff(kind string, failures int) time.Duration { |
| + if !strings.HasPrefix(kind, "owner-") { |
| + return transferAlertRetryMax |
| + } |
| switch { |
| case failures <= 1: |
| return time.Hour |
| @@ -267,6 +272,10 @@ func noticeBackoff(failures int) time.Duration { |
| return 24 * time.Hour |
| } |
| +// transferAlertRetryMax is the longest an operator alert that failed to go |
| +// out waits before it is tried again. |
| +const transferAlertRetryMax = time.Hour |
| + |
| // dueTransferAlerts is every scheduled alert that is due and not yet |
| // delivered: |
| // - an unknown outcome: a day after it became unknown, then weekly after |
diff --git a/internal/console/domaintransfer_decide_test.go b/internal/console/domaintransfer_decide_test.go| index 7305b5d7f..72cc21bca 100644 |
| --- a/internal/console/domaintransfer_decide_test.go |
| +++ b/internal/console/domaintransfer_decide_test.go |
| @@ -1479,9 +1479,9 @@ func (sim *transferSim) checkScheduledAlerts(i int, p *DomainPurchase) { |
| backoff = maxTime(backoff, f.Delivery[alertUnknownWeekly].NextAt) |
| } |
| if !delivered && now.Before(backoff) { |
| - // An earlier try failed: it waits out the notice backoff, a day |
| - // at most. |
| - if backoff.Sub(now) > 24*time.Hour { |
| + // An earlier try failed: it waits out the operator alert |
| + // backoff, an hour at most. |
| + if backoff.Sub(now) > transferAlertRetryMax { |
| sim.fail(i, "alert %s backing off for %s", kind, backoff.Sub(now)) |
| } |
| sim.paths["scheduled alert backing off: "+kind]++ |
diff --git a/internal/console/domaintransfer_notices.go b/internal/console/domaintransfer_notices.go| index f641b24df..5ee2bbaa2 100644 |
| --- a/internal/console/domaintransfer_notices.go |
| +++ b/internal/console/domaintransfer_notices.go |
| @@ -22,11 +22,12 @@ import ( |
| // |
| // Bounded: an owner email is recorded per owner as it goes out |
| // (Facts.Delivery), so a retry mails only the owners it has not reached. |
| -// A try that fails waits out noticeBackoff (1 h, 6 h, then daily) before |
| -// the next. An owner who cannot be reached at all (they blocked the |
| -// console, or there is no email sender) is given up on, and a notice with |
| -// no one left to reach, or whose account is gone, is dropped with one |
| -// operator alert (alertNoticeDropped). Every other failure is transient. |
| +// A try that fails waits out noticeBackoff before the next: an owner |
| +// email 1 h, 6 h, then daily; an operator alert an hour at most. An owner |
| +// who cannot be reached at all (they blocked the console, or there is no |
| +// email sender) is given up on, and a notice with no one left to reach, |
| +// or whose account is gone, is dropped with one operator alert |
| +// (alertNoticeDropped). Every other failure is transient. |
| // |
| // At least once: a crash between a delivery and its record sends it again, |
| // to that one recipient; a recipient whose delivery is recorded never gets |
| @@ -75,7 +76,7 @@ func recordNoticeTry(q *DomainPurchase, kind string, finished bool, at time.Time |
| d := f.Delivery[kind] |
| if !finished { |
| d.Failures++ |
| - d.NextAt = at.Add(noticeBackoff(d.Failures)) |
| + d.NextAt = at.Add(noticeBackoff(kind, d.Failures)) |
| if f.Delivery == nil { |
| f.Delivery = map[string]noticeDelivery{} |
| } |