carlos / platform Public

transfers: residual fixes from the scoped re-review

- The CLI wait treats a body-read error after the headers as transient.
- It honours Retry-After in both forms as a minimum, and gives up at once
  when the delay is longer than the budget left.
- A dropped-notice alert is owed as soon as a recipient's permanent
  non-delivery is known, even after a partial delivery.
- The alert names the kind without its owner- prefix.
- An unreachable Keymail lookup on a console with no mailer is transient.
- The terminal is restored on SIGQUIT and SIGHUP (Unix).
- Root envelope re-pinned; the census seal is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1dad6e27813ce6993cc7089444f987cfa78e0d7e parent 49daf04
9 files changed, +327 −51
  • domains_transfer_cli.go +64 −31
  • domains_transfer_cli_test.go +83 −3
  • domains_transfer_signals_other.go +13 −0
  • domains_transfer_signals_unix.go +14 −0
  • internal/console/delivery.go +8 −0
  • internal/console/domaintransfer_bounded_test.go +110 −0
  • internal/console/domaintransfer_copy.go +4 −2
  • internal/console/domaintransfer_notices.go +30 −14
  • internal/provision/testdata/plan14-root-reads-domain-transfers.tsv +1 −1

CI cancelled — superseded by a newer push — run details

CI log
=== gate ===
go: downloading go1.26.10 (linux/arm64)
go version go1.26.10 linux/arm64
opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1
  tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz
  tofu: downloaded, digest verified
  aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip
  aws: downloaded, digest verified
  archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip
  archive: downloaded, digest verified
  installed in /tmp/carlos-opentofu-mqpLNH
.amadan/test-gate.sh
go: downloading github.com/aws/aws-sdk-go-v2 v1.44.0
go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0
go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5
go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0
go: downloading github.com/benbjohnson/litestream v0.5.14
go: downloading github.com/superfly/ltx v0.5.1
go: downloading golang.org/x/net v0.62.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sns v1.43.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0
go: downloading golang.org/x/sys v0.49.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0
go: downloading golang.org/x/crypto v0.58.0
go: downloading github.com/aws/aws-sdk-go-v2/service/route53 v1.64.1
go: downloading github.com/pion/logging v0.2.4
go: downloading github.com/pion/stun/v3 v3.1.5
go: downloading github.com/pion/turn/v4 v4.1.4
go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2
go: downloading github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.37.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ssm v1.74.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sesv2 v1.66.6
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/pion/dtls/v3 v3.1.4
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading golang.org/x/text v0.43.0
go: downloading github.com/prometheus/client_golang v1.17.0
go: downloading golang.org/x/sync v0.24.0
go: downloading github.com/lmittmann/tint v1.1.3
go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/prometheus/common v0.45.0
go: downloading github.com/prometheus/procfs v0.12.0
go: downloading github.com/prometheus/client_model v0.5.0
go: downloading github.com/cespare/xxhash/v2 v2.3.0
go: downloading google.golang.org/protobuf v1.36.10
go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/klauspost/compress v1.20.2
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/google/uuid v1.6.0
go: downloading github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec
go: downloading github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec

amadan: job cancelled — a newer push superseded it
diff --git a/domains_transfer_cli.go b/domains_transfer_cli.go
index 1d2fb04af..83a8b3d7b 100644
--- a/domains_transfer_cli.go
+++ b/domains_transfer_cli.go
@@ -24,7 +24,6 @@ import (
"os/signal"
"strconv"
"strings"
- "syscall"
"time"
"github.com/carlosframework/platform/internal/plans"
@@ -39,11 +38,13 @@ import (
const domainTransferWaitPoll = time.Minute
// The wait outlasts a console it cannot reach: a poll that fails in
-// transport, with a 5xx or with a 429 is tried again after
-// domainTransferRetryFirst, doubling to domainTransferRetryMax (a 429's
-// Retry-After instead, when it says, within the same bound), keeping the
-// last state it read. After domainTransferGiveUp of nothing but failures it
-// stops, saying the move carries on and how to check on it.
+// transport (before the headers or while reading the body), with a 5xx or
+// with a 429 is tried again after domainTransferRetryFirst, doubling to
+// domainTransferRetryMax, keeping the last state it read. A Retry-After
+// (seconds or an HTTP date, RFC 9110) is a minimum: the wait is never
+// shorter. After domainTransferGiveUp of nothing but failures, or when a
+// Retry-After asks for longer than what is left of it, it stops, saying
+// the move carries on and how to check on it.
const (
domainTransferRetryFirst = 5 * time.Second
domainTransferRetryMax = 5 * time.Minute
@@ -115,7 +116,8 @@ func runDomainsTransfer(args []string) error {
// readTransferCodeTerminal reads one line from the terminal fd without
// echoing it. The terminal is restored when the read returns, and on an
-// interrupt or termination during it, after which the signal is delivered
+// interrupt, termination, quit or hangup (the last two on Unix only,
+// transferCodeSignals) during it, after which the signal is delivered
// again with its default action, so the process ends as it would have
// (where a signal cannot be sent to itself, as on Windows, it is killed).
func readTransferCodeTerminal(fd int) (string, error) {
@@ -124,7 +126,7 @@ func readTransferCodeTerminal(fd int) (string, error) {
return "", err
}
signals := make(chan os.Signal, 1)
- signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
+ signal.Notify(signals, transferCodeSignals...)
done := make(chan struct{})
defer func() {
signal.Stop(signals)
@@ -351,7 +353,7 @@ func pollDomainTransfer(ctx context.Context, s *apiSession, acct apiAcct, id str
var failingSince time.Time
backoff := domainTransferRetryFirst
for {
- p, retryAfter, err := getDomainTransferStatus(ctx, s, acct, id)
+ p, after, err := getDomainTransferStatus(ctx, s, acct, id)
var transient *transientPollError
if err == nil || !errors.As(err, &transient) || ctx.Err() != nil {
return p, err
@@ -360,13 +362,13 @@ func pollDomainTransfer(ctx context.Context, s *apiSession, acct apiAcct, id str
if failingSince.IsZero() {
failingSince = now
}
- if now.Sub(failingSince) >= domainTransferGiveUp {
+ left := domainTransferGiveUp - now.Sub(failingSince)
+ // The console's Retry-After is a minimum; one longer than the wait
+ // has left gives up now rather than ask early.
+ delay := max(backoff, after.wait(now))
+ if left <= 0 || delay > left {
return p, fmt.Errorf(domainsTransferCopy["pollGaveUp"], transient.err)
}
- delay := backoff
- if retryAfter > 0 {
- delay = min(retryAfter, domainTransferRetryMax)
- }
backoff = min(backoff*2, domainTransferRetryMax)
if err := o.wait(ctx, delay); err != nil {
return p, err
@@ -381,34 +383,65 @@ type transientPollError struct{ err error }
func (e *transientPollError) Error() string { return e.err.Error() }
func (e *transientPollError) Unwrap() error { return e.err }
-// getDomainTransferStatus is one status read: the reply, a 429's
+// retryAfter is a response's Retry-After: a delay in seconds, or an HTTP
+// date (RFC 9110 section 10.2.3). The zero value says nothing.
+type retryAfter struct {
+ delay time.Duration
+ at time.Time
+}
+
+// parseRetryAfter reads a Retry-After header value; anything it cannot
+// read says nothing.
+func parseRetryAfter(v string) retryAfter {
+ v = strings.TrimSpace(v)
+ if v == "" {
+ return retryAfter{}
+ }
+ if n, err := strconv.ParseInt(v, 10, 64); err == nil {
+ if n <= 0 {
+ return retryAfter{}
+ }
+ return retryAfter{delay: time.Duration(min(n, int64(1<<31))) * time.Second}
+ }
+ if at, err := http.ParseTime(v); err == nil {
+ return retryAfter{at: at}
+ }
+ return retryAfter{}
+}
+
+// wait is how long from now the header asks to wait; 0 for none or a date
+// already past.
+func (r retryAfter) wait(now time.Time) time.Duration {
+ if !r.at.IsZero() {
+ return max(r.at.Sub(now), 0)
+ }
+ return r.delay
+}
+
+// getDomainTransferStatus is one status read: the reply, a 429's or 5xx's
// Retry-After, and an error that is a *transientPollError when the read
-// may succeed later.
-func getDomainTransferStatus(ctx context.Context, s *apiSession, acct apiAcct, id string) (domainPurchaseResp, time.Duration, error) {
+// may succeed later. A failure after the headers (a reset, a body cut
+// short, a timeout reading it) is transient whatever the status; only a
+// console that has moved (consoleMoved, a permanent redirect) is not.
+func getDomainTransferStatus(ctx context.Context, s *apiSession, acct apiAcct, id string) (domainPurchaseResp, retryAfter, error) {
var out domainPurchaseResp
status, header, body, err := s.getJSONHeader(ctx, domainBuyAPIPath(acct, "/purchases/"+url.PathEscape(id)))
if err != nil {
- if status == 0 {
- return out, 0, &transientPollError{err}
+ if status == http.StatusMovedPermanently || status == http.StatusPermanentRedirect {
+ return out, retryAfter{}, err
}
- return out, 0, err
+ return out, retryAfter{}, &transientPollError{err}
}
switch {
- case status == http.StatusTooManyRequests:
- var after time.Duration
- if n, perr := strconv.Atoi(strings.TrimSpace(header.Get("Retry-After"))); perr == nil && n > 0 {
- after = time.Duration(n) * time.Second
- }
- return out, after, &transientPollError{apiErrorFromBody(status, body)}
- case status >= 500:
- return out, 0, &transientPollError{apiErrorFromBody(status, body)}
+ case status == http.StatusTooManyRequests || status >= 500:
+ return out, parseRetryAfter(header.Get("Retry-After")), &transientPollError{apiErrorFromBody(status, body)}
case status != http.StatusOK:
- return out, 0, apiErrorFromBody(status, body)
+ return out, retryAfter{}, apiErrorFromBody(status, body)
}
if err := json.Unmarshal(body, &out); err != nil {
- return out, 0, fmt.Errorf(domainsBuyCopy["unreadablePurchase"], err)
+ return out, retryAfter{}, fmt.Errorf(domainsBuyCopy["unreadablePurchase"], err)
}
- return out, 0, nil
+ return out, retryAfter{}, nil
}
// transferFailedError is a failed transfer's line: its reason in plain
diff --git a/domains_transfer_cli_test.go b/domains_transfer_cli_test.go
index 8c21f28da..2b9399eea 100644
--- a/domains_transfer_cli_test.go
+++ b/domains_transfer_cli_test.go
@@ -408,7 +408,7 @@ func TestDomainsTransferWaitSurvivesFailedPolls(t *testing.T) {
case 2:
http.Error(w, `{"error":"down"}`, http.StatusBadGateway)
case 3:
- w.Header().Set("Retry-After", "7")
+ w.Header().Set("Retry-After", "20")
http.Error(w, `{"error":"slow down"}`, http.StatusTooManyRequests)
default:
json.NewEncoder(w).Encode(map[string]any{"id": "t1", "kind": "transfer", "state": "done", "stage": "done", "domain": "shop.com"})
@@ -426,11 +426,91 @@ func TestDomainsTransferWaitSurvivesFailedPolls(t *testing.T) {
t.Fatalf("%d polls:\n%s", polls, &out)
}
// The waits before the first two polls, then the 502's backoff,
- // then the 429's Retry-After.
- if len(delays) < 4 || delays[2] != domainTransferRetryFirst || delays[3] != 7*time.Second {
+ // then the 429's Retry-After (longer than the next backoff, 10 s).
+ if len(delays) < 4 || delays[2] != domainTransferRetryFirst || delays[3] != 20*time.Second {
t.Fatalf("delays %v", delays)
}
})
+ t.Run("a body cut short, then the answer", func(t *testing.T) {
+ polls := 0
+ ts := newTransferTestServer(t, nil, func(w http.ResponseWriter, r *http.Request) {
+ polls++
+ switch polls {
+ case 1:
+ json.NewEncoder(w).Encode(map[string]any{"id": "t1", "kind": "transfer", "state": "transfer_pending", "stage": "waiting"})
+ case 2:
+ // A 200 whose body stops short of its length: the read
+ // fails after the headers.
+ w.Header().Set("Content-Length", "500")
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprint(w, `{"id":"t1","kind":"tra`)
+ default:
+ json.NewEncoder(w).Encode(map[string]any{"id": "t1", "kind": "transfer", "state": "done", "stage": "done", "domain": "shop.com"})
+ }
+ })
+ var out bytes.Buffer
+ if err := domainsTransfer(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "shop.com", transferTestOptions(t, &out)); err != nil {
+ t.Fatalf("a truncated body ended the wait: %v\n%s", err, &out)
+ }
+ if polls != 3 || !strings.Contains(out.String(), fmt.Sprintf(domainsTransferCopy["done"], "shop.com")) {
+ t.Fatalf("%d polls:\n%s", polls, &out)
+ }
+ })
+ t.Run("Retry-After is a minimum, in either form", func(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ header func(now time.Time) string
+ want time.Duration
+ }{
+ {"seconds past the backoff cap", func(time.Time) string { return "600" }, 600 * time.Second},
+ {"an HTTP date", func(now time.Time) string { return now.Add(90 * time.Second).UTC().Format(http.TimeFormat) }, 90 * time.Second},
+ {"a date already past", func(now time.Time) string { return now.Add(-time.Hour).UTC().Format(http.TimeFormat) }, domainTransferRetryFirst},
+ {"unreadable", func(time.Time) string { return "soon" }, domainTransferRetryFirst},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ var out bytes.Buffer
+ o := transferTestOptions(t, &out)
+ polls := 0
+ ts := newTransferTestServer(t, nil, func(w http.ResponseWriter, r *http.Request) {
+ polls++
+ if polls == 1 {
+ w.Header().Set("Retry-After", tc.header(o.now()))
+ http.Error(w, `{"error":"slow down"}`, http.StatusTooManyRequests)
+ return
+ }
+ json.NewEncoder(w).Encode(map[string]any{"id": "t1", "kind": "transfer", "state": "done", "stage": "done", "domain": "shop.com"})
+ })
+ var delays []time.Duration
+ wait := o.wait
+ o.wait = func(ctx context.Context, d time.Duration) error { delays = append(delays, d); return wait(ctx, d) }
+ if _, err := pollDomainTransfer(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "t1", o); err != nil {
+ t.Fatal(err)
+ }
+ if len(delays) != 1 || delays[0] != tc.want {
+ t.Fatalf("waited %v, want %s", delays, tc.want)
+ }
+ })
+ }
+ if got := parseRetryAfter("Sun, 06 Nov 1994 08:49:37 GMT").wait(time.Date(1994, 11, 6, 8, 49, 0, 0, time.UTC)); got != 37*time.Second {
+ t.Fatalf("RFC 9110's example date: %s", got)
+ }
+ })
+ t.Run("a Retry-After longer than the wait has left", func(t *testing.T) {
+ polls := 0
+ ts := newTransferTestServer(t, nil, func(w http.ResponseWriter, r *http.Request) {
+ polls++
+ w.Header().Set("Retry-After", "3600")
+ http.Error(w, `{"error":"down for maintenance"}`, http.StatusServiceUnavailable)
+ })
+ var out bytes.Buffer
+ o := transferTestOptions(t, &out)
+ waited := 0
+ o.wait = func(context.Context, time.Duration) error { waited++; return nil }
+ _, err := pollDomainTransfer(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "t1", o)
+ if err == nil || !strings.Contains(err.Error(), "the move carries on") || polls != 1 || waited != 0 {
+ t.Fatalf("gave up with %v after %d polls and %d waits", err, polls, waited)
+ }
+ })
t.Run("half an hour of failures", func(t *testing.T) {
polls := 0
ts := newTransferTestServer(t, nil, func(w http.ResponseWriter, r *http.Request) {
diff --git a/domains_transfer_signals_other.go b/domains_transfer_signals_other.go
new file mode 100644
index 000000000..3b9105a7a
--- /dev/null
+++ b/domains_transfer_signals_other.go
@@ -0,0 +1,13 @@
+//go:build !unix
+
+package main
+
+import (
+ "os"
+ "syscall"
+)
+
+// transferCodeSignals are the signals during the transfer code's no-echo
+// read after which the terminal is restored (readTransferCodeTerminal):
+// where there is no SIGQUIT or SIGHUP, an interrupt and a termination.
+var transferCodeSignals = []os.Signal{os.Interrupt, syscall.SIGTERM}
diff --git a/domains_transfer_signals_unix.go b/domains_transfer_signals_unix.go
new file mode 100644
index 000000000..81fc0d116
--- /dev/null
+++ b/domains_transfer_signals_unix.go
@@ -0,0 +1,14 @@
+//go:build unix
+
+package main
+
+import (
+ "os"
+ "syscall"
+)
+
+// transferCodeSignals are the signals during the transfer code's no-echo
+// read after which the terminal is restored (readTransferCodeTerminal): on
+// Unix, a quit (Ctrl-\) and a hangup as well as an interrupt and a
+// termination.
+var transferCodeSignals = []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP}
diff --git a/internal/console/delivery.go b/internal/console/delivery.go
index 888bf6207..01da54264 100644
--- a/internal/console/delivery.go
+++ b/internal/console/delivery.go
@@ -43,6 +43,10 @@ func domainOf(addr string) string {
// keymailShare bounds Keymail's part of ctx so the mailer keeps the rest.
// On error the channel is "".
func (s *Server) deliver(ctx context.Context, to, subject, body string, keymailShare time.Duration) (deliveryChannel, error) {
+ // lookupErr is an unreachable Keymail lookup that fell through to the
+ // mailer: with no mailer it is the answer, so an outage never reads as
+ // errNoEmailSender, which callers may take as permanent.
+ var lookupErr error
if s.sendFederated != nil {
kctx, cancel := context.WithTimeout(ctx, keymailShare)
_, err := s.sendFederated(kctx, to, subject, body)
@@ -64,6 +68,7 @@ func (s *Server) deliver(ctx context.Context, to, subject, body string, keymailS
return "", err
}
log.Printf("console: delivery to %s: keymail lookup unreachable, trying email: %v", to, err)
+ lookupErr = err
default:
// ErrFederationPriceTooHigh, or a failure after the lookup
// said the mailbox exists.
@@ -72,6 +77,9 @@ func (s *Server) deliver(ctx context.Context, to, subject, body string, keymailS
}
}
if s.consoleMail == nil {
+ if lookupErr != nil {
+ return "", lookupErr
+ }
return "", errNoEmailSender
}
if err := s.consoleMail.Send(ctx, to, subject, body); err != nil {
diff --git a/internal/console/domaintransfer_bounded_test.go b/internal/console/domaintransfer_bounded_test.go
index 62b8e44ab..5c27aa494 100644
--- a/internal/console/domaintransfer_bounded_test.go
+++ b/internal/console/domaintransfer_bounded_test.go
@@ -535,3 +535,113 @@ func TestAPIDomainsListTransferShapes(t *testing.T) {
t.Fatalf("domains: %s", body)
}
}
+
+// TestTransferNoticeDroppedAlertOwedOnLoss: the operator's dropped-notice
+// alert is owed in the move that establishes an owner will not get the
+// email, whoever else was reached and whatever retries are still pending:
+// - owner A delivered, owner B failing transiently, then the account is
+// deleted: owed once, delivered once, B never emailed;
+// - owner A blocked the console, owner B failing transiently: owed after
+// the first try, before B's retries, and not again once B gets it.
+//
+// The alert names the email by its kind without the "owner-" prefix.
+func TestTransferNoticeDroppedAlertOwedOnLoss(t *testing.T) {
+ dropped := alertNoticeDropped + noticeOwnerDone
+ t.Run("delivered to one, then the account gone", func(t *testing.T) {
+ tf := newTransferFixture(t)
+ owner := ownerAddress(t, tf)
+ second := "second-owner@example.test"
+ if err := tf.st.AddMember(tf.acct.ID, second, RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ mail := &addressMail{fail: map[string]error{second: errors.New("mail down for this one")}}
+ tf.srv.consoleMail = mail
+ p := tf.doneTransfer(t)
+ if !tf.read(t, p.ID).Facts.Owed[dropped].IsZero() {
+ t.Fatal("owed before any loss was known")
+ }
+ if _, err := tf.st.db.Exec(`DELETE FROM accounts WHERE id=?`, tf.acct.ID); err != nil {
+ t.Fatal(err)
+ }
+ mail.mu.Lock()
+ mail.fail = nil
+ mail.mu.Unlock()
+ for i := 0; i < 4; i++ {
+ tf.tick(25 * time.Hour)
+ tf.noticePass(t)
+ }
+ p = tf.read(t, p.ID)
+ if p.Facts.Owed[dropped].IsZero() || tf.alerts(dropped) != 1 || len(outstandingNotices(p.Facts)) != 0 {
+ t.Fatalf("dropped alerts %d, facts %+v", tf.alerts(dropped), p.Facts)
+ }
+ if mail.count(owner) != 1 || mail.count(second) != 0 {
+ t.Fatalf("owner %d, second %d", mail.count(owner), mail.count(second))
+ }
+ })
+ t.Run("one blocked, one failing for now", func(t *testing.T) {
+ tf := newTransferFixture(t)
+ blocked, second := "blocked-owner@example.test", "second-owner@example.test"
+ for _, m := range []string{blocked, second} {
+ if err := tf.st.AddMember(tf.acct.ID, m, RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ }
+ mail := &addressMail{fail: map[string]error{second: errors.New("mail down for this one")}}
+ tf.srv.consoleMail = mail
+ tf.srv.sendFederated = func(_ context.Context, to, _, _ string) (string, error) {
+ if to == blocked {
+ return "", &keymailError{Status: 403, Msg: "blocked"}
+ }
+ return "", ErrNoKeymailMailbox
+ }
+ p := tf.read(t, tf.doneTransfer(t).ID)
+ if p.Facts.Owed[dropped].IsZero() || p.Facts.Delivery[noticeOwnerDone].NextAt.IsZero() {
+ t.Fatalf("not owed at once while a retry is pending: %+v", p.Facts)
+ }
+ tf.noticePass(t) // the alert goes; the email still waits out its backoff
+ if tf.alerts(dropped) != 1 || mail.count(second) != 0 {
+ t.Fatalf("dropped alerts %d, second %d", tf.alerts(dropped), mail.count(second))
+ }
+ mail.mu.Lock()
+ mail.fail = nil
+ mail.mu.Unlock()
+ for i := 0; i < 3; i++ {
+ tf.tick(25 * time.Hour)
+ tf.noticePass(t)
+ }
+ if tf.alerts(dropped) != 1 || mail.count(second) != 1 || mail.count(blocked) != 0 {
+ t.Fatalf("dropped alerts %d, second %d, blocked %d", tf.alerts(dropped), mail.count(second), mail.count(blocked))
+ }
+ tf.mu.Lock()
+ pages := strings.Join(tf.pages, "\n")
+ tf.mu.Unlock()
+ if want := fmt.Sprintf(transferNoticeDroppedCopy, "done"); !strings.Contains(pages, want) {
+ t.Fatalf("the alert does not name the email as %q:\n%s", want, pages)
+ }
+ })
+ for kind, name := range map[string]string{noticeOwnerDone: "done", noticeOwnerUnpaid: "unpaid", noticeOwnerFailed: "failed"} {
+ if got, want := transferAlertReason(alertNoticeDropped+kind), fmt.Sprintf(transferNoticeDroppedCopy, name); got != want {
+ t.Errorf("%s: %q, want %q", kind, got, want)
+ }
+ }
+}
+
+// TestDeliverNoMailerKeymailOutageIsTransient: with no mailer, a Keymail
+// lookup that cannot be reached answers with its own error, never
+// errNoEmailSender, so an outage never gives an owner up for good. A
+// definite "no mailbox" with no mailer is still errNoEmailSender.
+func TestDeliverNoMailerKeymailOutageIsTransient(t *testing.T) {
+ tf := newTransferFixture(t)
+ tf.srv.consoleMail = nil
+ tf.srv.sendFederated = func(context.Context, string, string, string) (string, error) {
+ return "", fmt.Errorf("%w: lookup timed out", ErrKeymailUnreachable)
+ }
+ _, err := tf.srv.deliver(context.Background(), "owner@example.test", "s", "b", time.Second)
+ if err == nil || errors.Is(err, errNoEmailSender) || !errors.Is(err, ErrKeymailUnreachable) || deliveryPermanent(err) {
+ t.Fatalf("an unreachable lookup with no mailer: %v", err)
+ }
+ tf.srv.sendFederated = func(context.Context, string, string, string) (string, error) { return "", ErrNoKeymailMailbox }
+ if _, err := tf.srv.deliver(context.Background(), "owner@example.test", "s", "b", time.Second); !errors.Is(err, errNoEmailSender) || !deliveryPermanent(err) {
+ t.Fatalf("no mailbox and no mailer: %v", err)
+ }
+}
diff --git a/internal/console/domaintransfer_copy.go b/internal/console/domaintransfer_copy.go
index 2aa8c60f2..cbb040cda 100644
--- a/internal/console/domaintransfer_copy.go
+++ b/internal/console/domaintransfer_copy.go
@@ -199,7 +199,8 @@ var transferAlertCopy = map[string]string{
}
// transferNoticeDroppedCopy is the operator's alert reason when an owner
-// email was given up (alertNoticeDropped); %s is the email's kind,
+// email was given up (alertNoticeDropped); %s is the email's kind (done,
+// unpaid or failed),
// operator-facing. approved by delegation (Luna), 2026-11-22:
// docs/superpowers/specs/LUNA-COPY-RESULT-TRANSFERS-2.md.
const transferNoticeDroppedCopy = "the owner email %s for this transfer could not reach every owner (an address was refused or blocked, no email sender is configured, or the account was deleted) and was given up; contact the owners another way"
@@ -209,7 +210,8 @@ func transferAlertReason(kind string) string {
return msg
}
if notice, ok := strings.CutPrefix(kind, alertNoticeDropped); ok {
- return fmt.Sprintf(transferNoticeDroppedCopy, notice)
+ // done, unpaid or failed: the email's kind without its prefix.
+ return fmt.Sprintf(transferNoticeDroppedCopy, strings.TrimPrefix(notice, "owner-"))
}
if attempt, ok := strings.CutPrefix(kind, alertRefundFailed); ok {
return "transfer failed and refund attempt " + attempt + " failed; a new attempt is under way"
diff --git a/internal/console/domaintransfer_notices.go b/internal/console/domaintransfer_notices.go
index 5ee2bbaa2..ee45eb04d 100644
--- a/internal/console/domaintransfer_notices.go
+++ b/internal/console/domaintransfer_notices.go
@@ -26,8 +26,11 @@ import (
// 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.
+// or whose account is gone, is dropped. The operator's alert
+// (alertNoticeDropped, owed once per notice) is owed in the move that
+// establishes the loss: an owner given up on, or the account found gone,
+// whoever else was reached and whatever retries are still pending. 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
@@ -60,7 +63,10 @@ func (s *Server) deliverTransferNotices(ctx context.Context, acct *Account, p *D
errs = append(errs, err)
}
at := s.transferNow()
- if err := s.movePurchase(ctx, p, p.State, func(q *DomainPurchase) { recordNoticeTry(q, kind, finished, at) }); err != nil {
+ // The account gone: an owner email still outstanding misses
+ // whoever it has not reached yet.
+ missed := acct == nil && strings.HasPrefix(kind, "owner-")
+ if err := s.movePurchase(ctx, p, p.State, func(q *DomainPurchase) { recordNoticeTry(q, kind, finished, missed, at) }); err != nil {
return errors.Join(append(errs, err)...)
}
}
@@ -69,8 +75,9 @@ func (s *Server) deliverTransferNotices(ctx context.Context, acct *Account, p *D
// recordNoticeTry records one try of kind on q: finished, it is delivered
// (or, with no one reached, dropped), and owes the dropped alert when
-// anyone was missed; otherwise the next try waits out the backoff.
-func recordNoticeTry(q *DomainPurchase, kind string, finished bool, at time.Time) {
+// anyone was missed (missed: the account is gone); otherwise the next try
+// waits out the backoff.
+func recordNoticeTry(q *DomainPurchase, kind string, finished, missed bool, at time.Time) {
f := &q.Facts
f.Delivery = cloneDeliveries(f.Delivery)
d := f.Delivery[kind]
@@ -98,14 +105,20 @@ func recordNoticeTry(q *DomainPurchase, kind string, finished bool, at time.Time
}
f.Alerts[kind] = at
}
- if owner && (len(d.To) == 0 || len(d.Refused) > 0) {
- f.Owed = maps.Clone(f.Owed)
- if f.Owed == nil {
- f.Owed = map[string]time.Time{}
- }
- if dropped := alertNoticeDropped + kind; f.Owed[dropped].IsZero() {
- f.Owed[dropped] = at
- }
+ if owner && (missed || len(d.To) == 0 || len(d.Refused) > 0) {
+ oweNoticeDropped(f, kind, at)
+ }
+}
+
+// oweNoticeDropped owes the operator's alert that kind could not reach an
+// owner, once: a notice already owing it keeps its first time.
+func oweNoticeDropped(f *transferFacts, kind string, at time.Time) {
+ f.Owed = maps.Clone(f.Owed)
+ if f.Owed == nil {
+ f.Owed = map[string]time.Time{}
+ }
+ if dropped := alertNoticeDropped + kind; f.Owed[dropped].IsZero() {
+ f.Owed[dropped] = at
}
}
@@ -176,7 +189,7 @@ func (s *Server) deliverOwnerNotice(ctx context.Context, acct *Account, p *Domai
} else {
log.Printf("console: transfer %s: notice %s: an owner cannot be reached, giving up on them: %v", p.ID, kind, err)
}
- name := member.Name
+ name, at := member.Name, s.transferNow()
if err := s.movePurchase(ctx, p, p.State, func(q *DomainPurchase) {
q.Facts.Delivery = cloneDeliveries(q.Facts.Delivery)
if q.Facts.Delivery == nil {
@@ -184,7 +197,10 @@ func (s *Server) deliverOwnerNotice(ctx context.Context, acct *Account, p *Domai
}
d := q.Facts.Delivery[kind]
if refused {
+ // The loss is known now: the operator hears of it whatever
+ // happens to the other owners.
d.Refused = append(d.Refused, name)
+ oweNoticeDropped(&q.Facts, kind, at)
} else {
d.To = append(d.To, name)
}
diff --git a/internal/provision/testdata/plan14-root-reads-domain-transfers.tsv b/internal/provision/testdata/plan14-root-reads-domain-transfers.tsv
index 77bee18d1..ae2e668a6 100644
--- a/internal/provision/testdata/plan14-root-reads-domain-transfers.tsv
+++ b/internal/provision/testdata/plan14-root-reads-domain-transfers.tsv
@@ -1,4 +1,4 @@
# Census overlay domain-transfers, written by census-propose (#369). census-ruling-domain-transfers, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-domain-transfers.md.
# 0 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@coverage . 341cba6553704492d159ace2c297457712f7e46bd9639f1563c1a446a9a894d1
+@coverage . 30174e1e1ee42954338f5d5fa13848e66d3968be7fc762608c092c80fc4563e6
@coverage internal/registrar e21ce8885350c0ad730c1a885568f4c07af266a1b4d6b4c50b063df76e666798