transfers plan: round 3 fixes in the plan text
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+12
−9
docs/superpowers/plans/2026-11-21-domain-registration-transfers-in.md+12 −9
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-4LwF9m .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/aws/smithy-go v1.28.1 go: downloading github.com/benbjohnson/litestream v0.5.14 go: downloading github.com/aws/aws-sdk-go-v2/config v1.32.6 go: downloading github.com/aws/aws-sdk-go-v2/service/sns v1.43.0 go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0 go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0 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/route53 v1.64.1 go: downloading github.com/aws/aws-sdk-go-v2/service/sts v1.45.6 go: downloading golang.org/x/crypto v0.58.0 go: downloading golang.org/x/sys v0.49.0 go: downloading modernc.org/sqlite v1.55.0 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/aws/protocol/eventstream v1.7.14 go: downloading github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.23 go: downloading github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.40 go: downloading github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.31 go: downloading github.com/pion/dtls/v3 v3.1.4 go: downloading github.com/pion/transport/v4 v4.0.2 go: downloading github.com/pion/randutil v0.1.0 go: downloading github.com/pierrec/lz4/v4 v4.1.22 go: downloading github.com/klauspost/compress v1.20.2 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/wlynxg/anet v0.0.5 go: downloading github.com/prometheus/common v0.45.0 go: downloading github.com/cespare/xxhash/v2 v2.3.0 go: downloading modernc.org/sqlite v1.55.0 go: downloading github.com/prometheus/client_model v0.5.0 go: downloading github.com/prometheus/procfs v0.12.0 go: downloading google.golang.org/protobuf v1.36.10 go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e go: downloading github.com/klauspost/compress v1.20.2 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 google.golang.org/protobuf v1.36.10 go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 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/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec amadan: job cancelled — a newer push superseded it
diff --git a/docs/superpowers/plans/2026-11-21-domain-registration-transfers-in.md b/docs/superpowers/plans/2026-11-21-domain-registration-transfers-in.md| index d1b004387..ebeb7762f 100644 |
| --- a/docs/superpowers/plans/2026-11-21-domain-registration-transfers-in.md |
| +++ b/docs/superpowers/plans/2026-11-21-domain-registration-transfers-in.md |
| @@ -12,7 +12,7 @@ |
| **Plans in this series:** 1 buy (live). 2a account-level domains (merged 69b44f53, v0.40.3 on dev). **Transfers in (this plan), ahead of 2b and 3 (spec R16).** 2b reconcile/reconverge/alerts. 3 renewals (must ship within a year of the first completed transfer). 4 customer records, change owner, transfer out. |
| -**Review history:** Astra round 1 on b77e1ec7 (`docs/superpowers/reviews/CODEX-FINDINGS-domain-transfers-plan.md`): NOT READY, 7 P1 and 4 P2, all accepted and folded in, marked **(r1 N)**. Astra round 2 on d2c3c5fc (`CODEX-FINDINGS-domain-transfers-plan-R2.md`): NOT READY, 4 P1 and 1 P2; the payment, refund and unknown-mutation families repeated, so stopping rule 2 applied. **Paul's ruling, 2026-11-22: one settlement function.** Every transfer decision is made by one pure function over a closed set of registrar, payment and refund outcomes, checked by a randomized simulation of outcomes and crash points (Task 6); round 2's findings are resolved inside it, marked **(r2 N)**. Round 3 is the last. |
| +**Review history:** Astra round 1 on b77e1ec7 (`docs/superpowers/reviews/CODEX-FINDINGS-domain-transfers-plan.md`): NOT READY, 7 P1 and 4 P2, all accepted and folded in, marked **(r1 N)**. Astra round 2 on d2c3c5fc (`CODEX-FINDINGS-domain-transfers-plan-R2.md`): NOT READY, 4 P1 and 1 P2; the payment, refund and unknown-mutation families repeated, so stopping rule 2 applied. **Paul's ruling, 2026-11-22: one settlement function.** Every transfer decision is made by one pure function over a closed set of registrar, payment and refund outcomes, checked by a randomized simulation of outcomes and crash points (Task 6); round 2's findings are resolved inside it, marked **(r2 N)**. Astra round 3 on 2d1b31d0 (`CODEX-FINDINGS-domain-transfers-plan-R3.md`): NOT READY, 3 P1 sharing one cause (facts around `decideTransfer` not retained or interpreted in their phase) and 3 P2, all fixed below as **(r3 N)** without a fourth round; the budget is spent. |
| **Switch-on:** rides the buy door (`domainBuyReady`; off while `CARLOS_HOST_CLAIM` is on). The first real transfer is rushedsunlight.com on flagship after the release, with Paul's GO and his auth code (spec §12.7). |
| @@ -117,7 +117,7 @@ |
| Amount int64 |
| Currency string |
| } |
| - // RefundInfo also carries Attempt int (from the refund's metadata "attempt", set at create) (r2 2) |
| + // RefundInfo also carries Purchase string and Attempt int (from the refund's metadata "purchase" and "attempt", set at create) (r2 2, r3 4) |
| // Result gains: Refund *RefundInfo |
| // PaymentInfo gains: CaptureBefore time.Time (Stripe's card capture_before; zero when the provider doesn't say) (r2 5) |
| // Provider gains: |
| @@ -209,13 +209,16 @@ |
| **The settlement function** (`internal/console/domaintransfer_decide.go`, pure, no I/O): |
| ```go |
| type registrarOutcome int // rNotSent, rUnknown (sent, no definite answer), rPending (accepted), rCompleted, rFailed (r2 4: an enum; the reason is kept beside it) |
| - type paymentOutcome int // pUnknown, pAuthorised (requires_capture), pCaptured (succeeded), pCancelled (canceled or lapsed, nothing taken), pFailed (requires_payment_method or another definite failure after a capture attempt, nothing taken) (r2 1) |
| + type paymentOutcome int // pUnknown, pAwaiting (Checkout open, no authorisation yet: includes a declined card the customer may retry, r3 3), pAuthorised (requires_capture), pCaptured (succeeded), pCancelled (Checkout expired, authorisation cancelled or lapsed: nothing taken), pFailed (requires_payment_method or another definite failure AFTER a capture attempt, nothing taken) (r2 1) |
| type refundOutcome int // fNone, fPending (current attempt pending or requires_action), fSucceeded (current attempt succeeded AND amount and currency equal the capture), fFailed (current attempt failed or canceled) |
| type transferFacts struct { |
| Registrar registrarOutcome; RegistrarReason string; Completed *registrar.Registered |
| Payment paymentOutcome |
| Refund refundOutcome; RefundAttempt int; RefundID string |
| Resolution string // operator: "", "failed", "completed" |
| + CaptureAttempted bool // a capture was sent; only then can requires_payment_method mean pFailed (r3 3) |
| + CheckoutExpires time.Time |
| + Alerts map[string]time.Time // alert kind -> last delivered, so the function can tell sent from due (r3 4) |
| Now, SubmittedAt, CaptureBefore time.Time |
| } |
| type transferAction int // aWait, aSubmit, aCapture, aCancelAuthorisation, aCreateRefund, aRecordDone, aRecordUnpaid, aFinishFailed, aAlert |
| @@ -223,23 +226,23 @@ |
| func decideTransfer(f transferFacts) transferDecision |
| ``` |
| Decision table (exhaustive over the enums; anything not listed is `aWait`): |
| - - `rNotSent` + `pAuthorised` → `aSubmit`; `rNotSent` + `pCancelled`/`pFailed` → `aFinishFailed` (not charged). |
| + - `rNotSent` + `pAwaiting` → `aWait` (Checkout open, a declined card may still be retried); `rNotSent` + `pAwaiting` past `CheckoutExpires` → `aFinishFailed` (expired, not charged) (r3 3); `rNotSent` + `pAuthorised` → `aSubmit`; `rNotSent` + `pCancelled` → `aFinishFailed` (not charged). |
| - `rUnknown` → `aWait`, with `aAlert` at 24 h after submit, a day before `CaptureBefore`, then weekly; never terminal (r2 3). `Resolution` "failed" → treat as `rFailed`; "completed" → treat as `rCompleted` with the operator-confirmed registration. |
| - `rPending` + `pAuthorised` → `aCapture`. `rPending` + anything else → `aWait` (a capture refused or failed is alerted once). |
| - `rCompleted` + `pCaptured` → `aRecordDone` (terminal `done`). `rCompleted` + `pAuthorised` → `aCapture`. `rCompleted` + `pCancelled`/`pFailed` → `aRecordUnpaid` (terminal `unpaid`, auto-renew off, owner notice, alert). `rCompleted` + `pUnknown` → `aWait`. |
| - `rFailed` + `pAuthorised` → `aCancelAuthorisation`. `rFailed` + `pCancelled`/`pFailed` → `aFinishFailed` (not charged). `rFailed` + `pCaptured`: refund `fNone` or `fFailed` → `aCreateRefund` (attempt + 1 after a failure, with an alert); `fPending` → `aWait`; `fSucceeded` → `aFinishFailed` (refunded). `rFailed` + `pUnknown` → `aWait`. |
| Invariants, asserted by `TestDecideTransferSimulation` (randomized: 10,000 runs of random registrar, payment and refund answers, lost answers, provider lag and a crash after any step, replayed through the real engine over the fakes and a fresh `Server` on restart; fixed seed printed on failure): |
| - I1 a terminal state is only reached with `Registrar` in {rCompleted, rFailed} or an operator resolution; I2 `done` ⇒ captured; I3 `unpaid` ⇒ completed and nothing captured; I4 terminal `failed` ⇒ nothing captured, or a refund of the full captured amount and currency succeeded; I5 `RequestTransfer` is called at most once per purchase; I6 at most one refund attempt is outstanding, and a failed attempt is never selected again (r2 2); I7 the purchase stays live (counted by `DomainObligations`, holding the domain's unique index) until terminal; I8 no `AuthCode` in the record after the submit move. |
| + I1 a terminal state is only reached with `Registrar` in {rCompleted, rFailed}, an operator resolution, or `rNotSent` with nothing taken (r3 5); I2 `done` ⇒ captured; I3 `unpaid` ⇒ completed and nothing captured; I4 terminal `failed` ⇒ nothing captured, or a refund of the full captured amount and currency succeeded; I5 `RequestTransfer` is called at most once per purchase; I6 at most one refund attempt is outstanding, and a failed attempt is never selected again (r2 2); I7 the purchase stays live (counted by `DomainObligations`, holding the domain's unique index) until terminal; I8 no `AuthCode` in the record after the submit move; I9 definite registrar outcomes are sticky: a recorded `rFailed` (from a submit refusal or a status read) or `rCompleted` is never replaced by `rUnknown` or `TransferNone` (r3 1); I10 progress: once the fakes give stable definite outcomes and injected failures stop, every purchase reaches a terminal state within 20 passes, and a purchase still live after its alert thresholds has delivered each due alert exactly once per its schedule (r3 5). The simulation generates valid provider transitions (pending → completed or failed; requires_capture → succeeded or canceled; refund pending → succeeded or failed) and, separately, lost and stale observations. |
| **The engine** (`domaintransfer.go`), one pass per live transfer purchase: |
| - 1. **Gather facts:** registrar status (`TransferStatus`, at `NextStatusAt` only; before submit it is `rNotSent`; after submit, none or an error is `rUnknown`; the reason is stored beside the outcome); payment (`PaymentCheckout` read of the PaymentIntent: `requires_capture` → pAuthorised, `succeeded` → pCaptured, `canceled` → pCancelled, `requires_payment_method` or a failed capture → pFailed, unreadable → pUnknown; `CaptureBefore` stored when the provider gives it); refund (`Refund(RefundID)`, or when `RefundID` is empty `Refunds(pi)` filtered to metadata purchase = this purchase AND attempt = `RefundAttempt` (r2 2), ignoring other attempts). |
| + 1. **Gather facts:** registrar status (`TransferStatus`, at `NextStatusAt` only; before submit it is `rNotSent`; after submit, none or an error is `rUnknown` UNLESS a definite outcome is already recorded, which a read never downgrades (I9, r3 1); the reason is stored beside the outcome); payment (`PaymentCheckout` read: before any authorisation, an open session is pAwaiting whatever its PaymentIntent says, an expired one pCancelled (r3 3); after: `requires_capture` → pAuthorised, `succeeded` → pCaptured, `canceled` → pCancelled, `requires_payment_method` → pFailed only when `CaptureAttempted`, unreadable → pUnknown; `CaptureBefore` stored when the provider gives it); refund (`Refund(RefundID)`, or when `RefundID` is empty `Refunds(pi)` filtered to `Purchase` = this purchase AND `Attempt` = `RefundAttempt` (r2 2), ignoring other attempts; a persisted unsent attempt (below) is reconciled by that list before it is resent). |
| 2. **Decide:** `decideTransfer(facts)`. |
| - 3. **Act**, then record facts and the result in one CAS move: `aSubmit` is the at-most-once submit (CAS to `transfer_submitting` clearing `AuthCode`, then `RequestTransfer` from memory; a crash after the move is `rUnknown`, settled only by status or an operator); `aCapture` `PrepareCapture(pi, id+":capture")`; `aCancelAuthorisation` `PrepareCancelPayment`; `aCreateRefund` `PrepareRefund(pi, id, attempt, fmt.Sprintf("%s:refund:%d", id, attempt))` storing `RefundID`; `aRecordDone`/`aRecordUnpaid` the idempotent registration helper (r1 5) then the terminal move; `aFinishFailed` the terminal move; `aAlert` `alertOperator` (Task 7), recording the send only on delivery. |
| + 3. **Act**, then record facts and the result in one CAS move: `aSubmit` is the at-most-once submit (CAS to `transfer_submitting` clearing `AuthCode`, then `RequestTransfer` from memory; a crash after the move is `rUnknown`, settled only by status or an operator; a definite `ErrRefused` reply is recorded as `rFailed` with its reason in the following move and is sticky, I9, r3 1); `aCapture` `PrepareCapture(pi, id+":capture")`, recording `CaptureAttempted` in the move before the send (r3 3); `aCancelAuthorisation` `PrepareCancelPayment`; `aCreateRefund` (r3 2): FIRST one CAS move that sets `RefundAttempt` to the new attempt, clears `RefundID` and stores the `Prepared` request from `PrepareRefund(pi, id, attempt, fmt.Sprintf("%s:refund:%d", id, attempt))` (the persist-before-send contract at `billing.go:238`, as `CheckoutPrepared` does); then send that stored request and record `RefundID` from the reply. After a crash or lost reply, the next pass lists refunds for this purchase and attempt and adopts the one it finds; only when none exists is the stored request resent; `aRecordDone`/`aRecordUnpaid` the idempotent registration helper (r1 5) then the terminal move; `aFinishFailed` the terminal move; `aAlert` `alertOperator` (Task 7), recording the send only on delivery. |
| Whatever a send answers, the next pass's fact gathering, not the send's reply, decides what happened. |
| - **Operator resolution (r2 3):** `POST /api/cli/accounts/{account}/domains/purchases/{id}/resolve` `{"outcome":"failed"|"completed","note"}`, gated as the existing system-operator doors (find the gate the billing operator pages use: `git grep -n 'systemOperator\|SystemOperator' internal/console`), service-closed, audited; only for a transfer whose registrar outcome is `rUnknown`; records `Resolution` and `ResolvedBy`. "completed" requires the registrar's `Lookup` to show the domain in our account (its `Registered` becomes `Completed`). |
| + **Operator resolution (r2 3, r3 6):** `POST /api/cli/system/domains/purchases/{id}/resolve` `{"outcome":"failed"|"completed","note"}`, authorised by `apiSystemOperator` (`internal/console/apisystem.go:49`: a person on the store's system-operator list; no ops-account-owner fallback), service-closed (`svcrole.Set{}`), audited; only for a transfer whose registrar outcome is `rUnknown`; records `Resolution` and `ResolvedBy`. "completed" requires the registrar's `Lookup` to show the domain in our account (its `Registered` becomes `Completed`). |
| Start refusals, all before Checkout: the Global Constraints list, plus `CheckTransfer` and `QuoteTransfer` errors mapped to plain copy (`domaintransfer_copy.go`, drafts). Nameservers come from `LookupNS` (lower-case, trailing dot stripped, sorted); none or an error → refusal. `LookupDS` true → the DNSSEC refusal; error → "couldn't check, try again" refusal (fail closed). |
| -- [ ] **Step 1: Write failing tests:** `TestDecideTransferTable` (every row of the decision table above, incl. pFailed after completion → unpaid, an empty-reason rFailed after capture → refund, a failed refund attempt → a new attempt), `TestDecideTransferSimulation` (invariants I1-I8, randomized as above), and on a transfer fixture beside `newPurchaseFixture`: `TestTransferHappyPathRecordsRegistrationWithoutZone` (nameservers sent = those read; registrant frozen; registration ZoneID ""; expiry from the fake; captured once; claims untouched), `TestTransferStartRefusals` (table: not registrable, TLD unmarked, premium, already ours, another account's apex claim, own apps' claims ALLOWED, DS present, DS lookup error, NS unreadable, empty NS, check says locked, daily cap, registrar balance short, sponsored account allowed), `TestTransferUnknownStaysLiveBlocksDeletionAndSecondStart` (r2 3), `TestTransferOperatorResolveOnlyForUnknownAndAudited`, `TestTransferCaptureBeforeDrivesLapseAlert` (r2 5: authorisation observed late; the alert still comes a day before the provider's deadline; fallback CreatedAt + 6 days), `TestTransferRefundIgnoresFailedEarlierAttemptInList` (r2 2), `TestTransferAuthCodeClearedAtSubmitAndNeverLogged` (Review Focus 4), `TestTransferAuthCodeClearedOnEveryPreSubmitTerminal`, `TestTransferCompletionReplayAfterCrashBetweenInsertAndMove`, `TestBuyAndTransferResumeOnlyTheirOwnKind`, `TestTransferStatusCadence` (30 minutes for 7 days after submit, then daily), `TestLookupDSAnswersAndFailures` (a local responder on an ephemeral 127.0.0.1 port via `Config.DNSServer`: DS present, NODATA, NXDOMAIN, SERVFAIL, mismatched ID, malformed, timeout, truncated UDP then TCP; no network). |
| +- [ ] **Step 1: Write failing tests:** `TestDecideTransferTable` (every row of the decision table above, incl. pFailed after completion → unpaid, an empty-reason rFailed after capture → refund, a failed refund attempt → a new attempt), `TestDecideTransferSimulation` (invariants I1-I8, randomized as above), and on a transfer fixture beside `newPurchaseFixture`: `TestTransferHappyPathRecordsRegistrationWithoutZone` (nameservers sent = those read; registrant frozen; registration ZoneID ""; expiry from the fake; captured once; claims untouched), `TestTransferStartRefusals` (table: not registrable, TLD unmarked, premium, already ours, another account's apex claim, own apps' claims ALLOWED, DS present, DS lookup error, NS unreadable, empty NS, check says locked, daily cap, registrar balance short, sponsored account allowed), `TestTransferUnknownStaysLiveBlocksDeletionAndSecondStart` (r2 3), `TestTransferOperatorResolveOnlyForUnknownAndAudited` (a listed system operator allowed; an ops-account owner not on the list, an ordinary account owner and a service principal refused), `TestTransferSubmitRefusalIsStickyAgainstLaterNone` (r3 1, incl. restart), `TestTransferReplacementRefundSurvivesCrashPastKeyRetention` (r3 2: R0 failed and still listed, R1 succeeded with its reply lost, restart: R1 adopted, no third refund), `TestTransferDeclinedCardThenRetriedInSameCheckout` (r3 3: a decline, a worker pass and a restart, then authorisation: the transfer submits), `TestDecideTransferAlertsOncePerSchedule` (r3 4), `TestTransferCaptureBeforeDrivesLapseAlert` (r2 5: authorisation observed late; the alert still comes a day before the provider's deadline; fallback CreatedAt + 6 days), `TestTransferRefundIgnoresFailedEarlierAttemptInList` (r2 2), `TestTransferAuthCodeClearedAtSubmitAndNeverLogged` (Review Focus 4), `TestTransferAuthCodeClearedOnEveryPreSubmitTerminal`, `TestTransferCompletionReplayAfterCrashBetweenInsertAndMove`, `TestBuyAndTransferResumeOnlyTheirOwnKind`, `TestTransferStatusCadence` (30 minutes for 7 days after submit, then daily), `TestLookupDSAnswersAndFailures` (a local responder on an ephemeral 127.0.0.1 port via `Config.DNSServer`: DS present, NODATA, NXDOMAIN, SERVFAIL, mismatched ID, malformed, timeout, truncated UDP then TCP; no network). |
| - [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestDecideTransfer|TestTransfer|TestLookupDS|TestBuyAndTransfer'`; expect FAIL. |
| - [ ] **Step 3: Implement.** |
| - [ ] **Step 4: Run** the same plus `-run 'TestPurchase|TestStart|DomainBuy|APIDomain'` (buying unchanged); expect PASS. The operator resolve route joins the route registers and parity (Global Constraints). |