carlos / platform Public

platform accounts: back off a held pending customer create for 5 minutes

A pending customer-create promise held until an operator repairs the
bucket was tried again on every platform request, reads included: each
try listed and read every account manifest in the bucket and logged the
operator's line (#1295, BEFORE PRODUCTION item 1).

Once a mint is found held, the platform's requests leave it alone for
5 minutes: no bucket scan and no log line. A create for its own ref
still answers create.failed at once, and the promise keeps counting
against capacity. The first request after the window tries again,
finishing it if it was repaired, or logging once more and backing off
again. The state is in memory on the Server (platformSeams), one entry
per held mint id, dropped once its time has come or its promise is no
longer pending. A clock seam drives the tests.

The runbook's log sentence now says the line comes at most once every
5 minutes; the copy pin and the plan's copy ledger follow, awaiting Luna.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d6261c526fdcfd5d325366324e34bab8381264a6 parent cdf9818
6 files changed, +384 −9
  • approved_platform_accounts_copy_test.go +1 −1
  • docs/site/cli.md +1 −1
  • docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md +1 −1
  • internal/console/apiplatformcustomers.go +33 −4
  • internal/console/apiplatformcustomers_backoff_test.go +253 −0
  • internal/console/platform_seams.go +95 −2
diff --git a/approved_platform_accounts_copy_test.go b/approved_platform_accounts_copy_test.go
index ef247b7b5..a59ac576d 100644
--- a/approved_platform_accounts_copy_test.go
+++ b/approved_platform_accounts_copy_test.go
@@ -161,7 +161,7 @@ func TestApprovedPlatformAccountsCopy(t *testing.T) {
{"docs.platform_credentials.ttl", "docs/site/cli.md", "It lasts an hour unless you pass `--ttl`, up to 24 hours. It works only in that one account. It stops working when the platform’s access is turned off, or when the platform credential that minted it is revoked or rotated. Use it as `CARLOS_SERVICE_TOKEN`."},
{"docs.held_promise.heading", "docs/site/cli.md", "#### A customer create that stays pending"},
{"docs.held_promise", "docs/site/cli.md", "When a platform creates a customer account, the console first records a promise for the account. The promise holds the customer’s ref and a place in `--max-customers`. The console then writes the account to the deployment bucket and records it in the database. If the bucket and database disagree, the console stops the create and keeps the promise. Nothing else is written until an operator repairs the mismatch."},
- {"docs.held_promise.log_intro", "docs/site/cli.md", "While a promise is held, the console logs this line for every request from the platform:"},
+ {"docs.held_promise.log_intro", "docs/site/cli.md", "While a promise is held, the console logs this line at most once every 5 minutes, when the platform makes a request:"},
{"docs.held_promise.scope", "docs/site/cli.md", "Only that platform’s create requests are affected. It can still list customers, update them and use its credentials. A create for the held ref fails. If the reason is `is in this console with no manifest in the bucket`, every create on that platform fails because the bucket gives each new create the same id. The promise counts towards `--max-customers` until it is repaired."},
{"docs.held_promise.read", "docs/site/cli.md", "Read the promise and account from the console’s database first:"},
{"docs.held_promise.manifest_key", "docs/site/cli.md", "The account’s manifest is `accounts/<sqid>/account.json` in the deployment bucket."},
diff --git a/docs/site/cli.md b/docs/site/cli.md
index bcad4e8c1..c09f7667e 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -2674,7 +2674,7 @@ Turning platform access off stops the platform’s credentials at once. Its cust
When a platform creates a customer account, the console first records a promise for the account. The promise holds the customer’s ref and a place in `--max-customers`. The console then writes the account to the deployment bucket and records it in the database. If the bucket and database disagree, the console stops the create and keeps the promise. Nothing else is written until an operator repairs the mismatch.
-While a promise is held, the console logs this line for every request from the platform:
+While a promise is held, the console logs this line at most once every 5 minutes, when the platform makes a request:
```text
console: platform <platform>: pending customer create <mint id> held for account <id>: <reason>; repair the bucket or console
diff --git a/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md b/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
index 4d822b1ba..3782a81cd 100644
--- a/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
+++ b/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
@@ -1394,7 +1394,7 @@ Cap names in usage reuse the approved `cliPlanCopyLimit*` labels (apps and insta
| docs.platform_customers_retry | Appended to docs.platform_customers by Task 11: "Without `--ref`, a create retried after a timeout can make a second account, so pass `--ref` when your server retries." | approved |
| docs.held_promise.heading | `#### A customer create that stays pending`, under `### carlos accounts platform` (final fix wave, held-promise runbook) | approved (Luna pass 2026-11-19) |
| docs.held_promise | When a platform creates a customer account, the console first records a promise for the account. The promise holds the customer’s ref and a place in `--max-customers`. The console then writes the account to the deployment bucket and records it in the database. If the bucket and database disagree, the console stops the create and keeps the promise. Nothing else is written until an operator repairs the mismatch. | approved (Luna pass 2026-11-19) |
-| docs.held_promise.log_intro | While a promise is held, the console logs this line for every request from the platform: | approved (Luna pass 2026-11-19) |
+| docs.held_promise.log_intro | While a promise is held, the console logs this line at most once every 5 minutes, when the platform makes a request: | changed by platform-accounts-followups (held-promise backoff, #1295): was "While a promise is held, the console logs this line for every request from the platform:"; awaiting Luna |
| docs.held_promise.scope | Only that platform’s create requests are affected. It can still list customers, update them and use its credentials. A create for the held ref fails. If the reason is `is in this console with no manifest in the bucket`, every create on that platform fails because the bucket gives each new create the same id. The promise counts towards `--max-customers` until it is repaired. | approved (Luna pass 2026-11-19) |
| docs.held_promise.read | Read the promise and account from the console’s database first: | approved (Luna pass 2026-11-19) |
| docs.held_promise.manifest_key | The account’s manifest is `accounts/<sqid>/account.json` in the deployment bucket. | approved (Luna pass 2026-11-19) |
diff --git a/internal/console/apiplatformcustomers.go b/internal/console/apiplatformcustomers.go
index b6a92a766..53750cfea 100644
--- a/internal/console/apiplatformcustomers.go
+++ b/internal/console/apiplatformcustomers.go
@@ -214,6 +214,9 @@ func (s *Server) platformFinishPending(w http.ResponseWriter, r *http.Request, c
ctx := r.Context()
acct := c.Platform
pending, err := s.store.PendingPlatformMints(ctx, acct.Sqid)
+ if err == nil && len(pending) == 0 {
+ s.pruneMintBackoff(acct.Sqid, nil)
+ }
if err == nil && len(pending) > 0 {
unlock := s.lockPlatformLifecycle(acct.Sqid)
err = s.finishPendingMints(ctx, acct)
@@ -479,7 +482,7 @@ func (s *Server) handlePlatformCustomerCreate(w http.ResponseWriter, r *http.Req
if m.Ref != req.Ref {
continue
}
- if _, err := s.finishPlatformMint(ctx, platform, m); err != nil && !errors.Is(err, errPlatformMintEnded) {
+ if _, err := s.finishPlatformMintPaced(ctx, platform, m); err != nil && !errors.Is(err, errPlatformMintEnded) {
log.Printf("console: platform %s: create customer for ref %q refused: its pending create %s "+
"did not finish: %v", platform.Sqid, req.Ref, m.MintID, err)
s.platformDoorFailed(w, c)
@@ -544,7 +547,7 @@ func (s *Server) handlePlatformCustomerCreate(w http.ResponseWriter, r *http.Req
}
// Step 7.
- cust, err := s.finishPlatformMint(ctx, platform, m)
+ cust, err := s.finishPlatformMintPaced(ctx, platform, m)
if err != nil {
if errors.Is(err, errMintNotWritten) {
// Refused before anything named it in the bucket: this
@@ -552,6 +555,8 @@ func (s *Server) handlePlatformCustomerCreate(w http.ResponseWriter, r *http.Req
// leaves nothing behind and holds no slot.
if uerr := s.store.unreservePlatformMint(ctx, platform.Sqid, m.MintID); uerr != nil {
log.Printf("console: platform %s: create customer: withdraw pending create %s: %v", platform.Sqid, m.MintID, uerr)
+ } else {
+ s.forgetMint(m.MintID)
}
}
s.platformDoorFailed(w, c)
@@ -630,14 +635,17 @@ const platformMintHeldOtherID = "is another account in this console, and the man
// that ended without an account (errPlatformMintEnded) is past, and a held
// one (errPlatformMintHeld, its operator line already logged) is passed
// over: one bad record must not stop the platform's other writes (Task 8
-// fix round 2). Any other failure stops it, and is returned (Astra r1-1).
+// fix round 2). A held one is tried at most once per platformMintHeldRetry
+// (finishPlatformMintPaced). Any other failure stops it, and is returned
+// (Astra r1-1).
func (s *Server) finishPendingMints(ctx context.Context, platform *Account) error {
pending, err := s.store.PendingPlatformMints(ctx, platform.Sqid)
if err != nil {
return err
}
+ s.pruneMintBackoff(platform.Sqid, pending)
for _, m := range pending {
- if _, err := s.finishPlatformMint(ctx, platform, m); err != nil &&
+ if _, err := s.finishPlatformMintPaced(ctx, platform, m); err != nil &&
!errors.Is(err, errPlatformMintEnded) && !errors.Is(err, errPlatformMintHeld) {
return err
}
@@ -645,6 +653,27 @@ func (s *Server) finishPendingMints(ctx context.Context, platform *Account) erro
return nil
}
+// finishPlatformMintPaced is finishPlatformMint for the platform's
+// requests, paced for a held promise. Trying one again scans every account
+// manifest in the bucket and logs the operator's line, and nothing changes
+// until an operator repairs it, so once a mint is found held it is not tried
+// again for platformMintHeldRetry: within that window it answers
+// errPlatformMintHeld at once, touching neither the bucket nor the log. The
+// promise is untouched, so it still counts against capacity and holds its
+// ref, and a create for that ref is still refused. The first request after
+// the window tries it again, finishing it if it was repaired. The caller
+// holds the platform lifecycle lock.
+func (s *Server) finishPlatformMintPaced(ctx context.Context, platform *Account, m PendingMint) (*Account, error) {
+ if s.mintBackedOff(m.MintID) {
+ return nil, fmt.Errorf("%w: mint %s: found held less than %s ago", errPlatformMintHeld, m.MintID, platformMintHeldRetry)
+ }
+ cust, err := s.finishPlatformMint(ctx, platform, m)
+ if errors.Is(err, errPlatformMintHeld) {
+ s.backOffMint(platform.Sqid, m.MintID)
+ }
+ return cust, err
+}
+
// finishPlatformMint finishes one pending mint, or refuses to and leaves it
// pending. The caller holds the platform lifecycle lock.
//
diff --git a/internal/console/apiplatformcustomers_backoff_test.go b/internal/console/apiplatformcustomers_backoff_test.go
new file mode 100644
index 000000000..14525a8be
--- /dev/null
+++ b/internal/console/apiplatformcustomers_backoff_test.go
@@ -0,0 +1,253 @@
+package console
+
+import (
+ "context"
+ "log"
+ "net/http"
+ "strings"
+ "sync"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/domains"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// manifestScanCounter counts the bucket calls a pending mint's finish makes
+// to find a free id: lists of accounts/ and reads of account manifests.
+type manifestScanCounter struct {
+ release.Store
+ mu sync.Mutex
+ lists, gets int
+}
+
+func (s *manifestScanCounter) List(ctx context.Context, prefix string) ([]string, error) {
+ if strings.HasPrefix(prefix, "accounts/") {
+ s.mu.Lock()
+ s.lists++
+ s.mu.Unlock()
+ }
+ return s.Store.List(ctx, prefix)
+}
+
+func (s *manifestScanCounter) Get(ctx context.Context, key string) ([]byte, string, error) {
+ if _, ok := domains.AccountManifestSqid(key); ok {
+ s.mu.Lock()
+ s.gets++
+ s.mu.Unlock()
+ }
+ return s.Store.Get(ctx, key)
+}
+
+// take answers the calls counted since the last take, and starts again.
+func (s *manifestScanCounter) take() (lists, gets int) {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ lists, gets = s.lists, s.gets
+ s.lists, s.gets = 0, 0
+ return lists, gets
+}
+
+// heldBackoffWorld is a platform with one accepted promise (ref 4812) that
+// is held because this console holds the id the bucket gives it with no
+// manifest for it, a counting bucket under the console, a fake clock on
+// the backoff and a captured log.
+type heldBackoffWorld struct {
+ fx *consoleFixture
+ acct *Account
+ tok string
+ next int64
+ scans *manifestScanCounter
+ clock atomic.Int64
+ logs *lockedLog
+}
+
+func newHeldBackoffWorld(t *testing.T) *heldBackoffWorld {
+ t.Helper()
+ w := &heldBackoffWorld{scans: &manifestScanCounter{}, logs: &lockedLog{}}
+ w.fx = newConsoleFixtureWith(t, consoleFixtureOptions{WithKey: true, WrapReleases: func(r release.Store) release.Store {
+ w.scans.Store = r
+ return w.scans
+ }})
+ w.clock.Store(time.Unix(1_800_000_000, 0).UnixNano())
+ w.fx.srv.platformClock = func() time.Time { return time.Unix(0, w.clock.Load()) }
+ w.acct = planAccount(t, w.fx, 501)
+ grantPlatformAccount(t, w.fx, w.acct.Sqid, 5)
+ w.tok = platformToken(t, w.fx, w.acct.ID, "cms")
+ next, err := domains.NextAccountID(context.Background(), w.fx.rel)
+ if err != nil {
+ t.Fatal(err)
+ }
+ w.next = next
+ // The promise is accepted, and its first finish fails before writing.
+ w.fx.srv.platformMintStep = failStep("mint", true)
+ status, out, _ := createCustomer(t, w.fx.ts.URL, w.acct.Sqid, w.tok, map[string]any{"name": "shop", "ref": "4812"})
+ wantPlatformError(t, "create with a failed mint", status, out, http.StatusBadGateway, "create.failed")
+ // Then this console gives its id to another account with no manifest.
+ if err := w.fx.st.CreateAccount(next, domains.Sqid(next), "other", "other@example.com", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ w.scans.take()
+ prev := log.Writer()
+ log.SetOutput(w.logs)
+ t.Cleanup(func() { log.SetOutput(prev) })
+ return w
+}
+
+func (w *heldBackoffWorld) advance(d time.Duration) { w.clock.Add(int64(d)) }
+
+// heldLines counts the operator's held line in the log so far.
+func (w *heldBackoffWorld) heldLines() int {
+ return strings.Count(w.logs.String(), " held for account ")
+}
+
+// backoffEntries is how many held promises the server is backing off.
+func (w *heldBackoffWorld) backoffEntries() int {
+ w.fx.srv.mintBackoffMu.Lock()
+ defer w.fx.srv.mintBackoffMu.Unlock()
+ return len(w.fx.srv.mintBackoff)
+}
+
+// list is one platform read request, which runs the gate.
+func (w *heldBackoffWorld) list(t *testing.T) map[string]any {
+ t.Helper()
+ status, out, raw := getPlatform(t, platformCustomersURL(w.fx.ts.URL, w.acct.Sqid), w.tok)
+ if status != http.StatusOK {
+ t.Fatalf("list = %d %s, want the read door to go on past the held promise", status, raw)
+ }
+ return out
+}
+
+// wantScans fails unless the bucket calls since the last take are a scan
+// (scanned) or none at all.
+func (w *heldBackoffWorld) wantScans(t *testing.T, what string, scanned bool) {
+ t.Helper()
+ lists, gets := w.scans.take()
+ if scanned && lists == 0 {
+ t.Fatalf("%s: no manifest list, want the held promise tried again", what)
+ }
+ if !scanned && (lists != 0 || gets != 0) {
+ t.Fatalf("%s: %d manifest lists and %d reads, want none inside the backoff window", what, lists, gets)
+ }
+}
+
+// TestHeldPromiseBacksOffItsScanAndLogLine: a promise found held is not
+// tried again for platformMintHeldRetry. Within that window the platform's
+// requests make no manifest list or read and log nothing more, the promise
+// still counts against capacity, and a create for its own ref is still
+// refused. After the window one request tries it again, logs again and
+// backs off again.
+func TestHeldPromiseBacksOffItsScanAndLogLine(t *testing.T) {
+ w := newHeldBackoffWorld(t)
+ out := w.list(t)
+ w.wantScans(t, "the first request", true)
+ if n := w.heldLines(); n != 1 {
+ t.Fatalf("held lines after the first request = %d, want 1:\n%s", n, w.logs)
+ }
+ if out["count"] != float64(1) {
+ t.Fatalf("list count = %v, want the held promise counted", out["count"])
+ }
+
+ for i := 0; i < 5; i++ {
+ w.advance(time.Minute - time.Second)
+ if out := w.list(t); out["count"] != float64(1) {
+ t.Fatalf("list count = %v inside the window, want the held promise counted", out["count"])
+ }
+ }
+ w.wantScans(t, "five requests inside the window", false)
+ if n := w.heldLines(); n != 1 {
+ t.Fatalf("held lines inside the window = %d, want still 1:\n%s", n, w.logs)
+ }
+ if n := linkedCount(t, w.fx.st, w.acct.Sqid); n != 1 {
+ t.Fatalf("LinkedCustomerCount = %d, want 1: the held promise keeps its slot", n)
+ }
+
+ // A create for the held ref is refused at once, without a rescan.
+ status, out, _ := createCustomer(t, w.fx.ts.URL, w.acct.Sqid, w.tok, map[string]any{"name": "shop", "ref": "4812"})
+ wantPlatformError(t, "create for the held ref inside the window", status, out, http.StatusBadGateway, "create.failed")
+ w.wantScans(t, "the own-ref create", false)
+ if n := w.heldLines(); n != 1 {
+ t.Fatalf("held lines after the own-ref create = %d, want still 1:\n%s", n, w.logs)
+ }
+ wantHeldPromise(t, w.fx, w.acct.Sqid, "4812", 1)
+
+ // After the window one request tries again, logs and backs off again.
+ w.advance(time.Minute)
+ w.list(t)
+ w.wantScans(t, "the first request after the window", true)
+ if n := w.heldLines(); n != 2 {
+ t.Fatalf("held lines after the window = %d, want 2:\n%s", n, w.logs)
+ }
+ w.list(t)
+ w.list(t)
+ w.wantScans(t, "requests after the retry", false)
+ if n := w.heldLines(); n != 2 {
+ t.Fatalf("held lines after the retry = %d, want still 2:\n%s", n, w.logs)
+ }
+ wantHeldPromise(t, w.fx, w.acct.Sqid, "4812", 1)
+}
+
+// TestHeldPromiseFinishesAfterRepairOnceTheWindowEnds: an operator restores
+// the missing manifest. A request inside the window still leaves the
+// promise alone; the first one after it finishes the create, and clears
+// its backoff.
+func TestHeldPromiseFinishesAfterRepairOnceTheWindowEnds(t *testing.T) {
+ w := newHeldBackoffWorld(t)
+ w.list(t)
+ w.wantScans(t, "the first request", true)
+
+ other, err := w.fx.st.AccountBySqid(domains.Sqid(w.next))
+ if err != nil || other == nil {
+ t.Fatalf("the other account %+v %v", other, err)
+ }
+ if err := WriteAccountManifest(context.Background(), w.fx.rel, other.ID, other.Sqid, other.Name, other.CreatedAt); err != nil {
+ t.Fatal(err)
+ }
+
+ w.advance(time.Minute)
+ w.list(t)
+ w.wantScans(t, "a request inside the window after the repair", false)
+ if p := pendingMints(t, w.fx.st, w.acct.Sqid); len(p) != 1 {
+ t.Fatalf("pending mints %+v inside the window, want the promise left alone", p)
+ }
+
+ w.advance(platformMintHeldRetry)
+ if out := w.list(t); len(customersIn(t, out)) != 1 || out["count"] != float64(1) {
+ t.Fatalf("list after the window = %v, want the repaired create finished", out)
+ }
+ w.wantScans(t, "the first request after the window", true)
+ if p := pendingMints(t, w.fx.st, w.acct.Sqid); len(p) != 0 {
+ t.Fatalf("pending mints %+v, want the repaired promise finished", p)
+ }
+ if n := w.heldLines(); n != 1 {
+ t.Fatalf("held lines = %d, want only the first:\n%s", n, w.logs)
+ }
+ if n := w.backoffEntries(); n != 0 {
+ t.Fatalf("backoff entries after the finish = %d, want none", n)
+ }
+ status, out, raw := createCustomer(t, w.fx.ts.URL, w.acct.Sqid, w.tok, map[string]any{"name": "shop", "ref": "4812"})
+ if status != http.StatusOK || out["created"] != false {
+ t.Fatalf("create 4812 after the repair = %d %s, want the finished customer", status, raw)
+ }
+}
+
+// TestHeldPromiseRemovedByAnOperatorDropsItsBackoff: the backoff holds an
+// entry only while its promise is pending. Once an operator removes the
+// promise, the platform's next request drops the entry, inside the window.
+func TestHeldPromiseRemovedByAnOperatorDropsItsBackoff(t *testing.T) {
+ w := newHeldBackoffWorld(t)
+ w.list(t)
+ if n := w.backoffEntries(); n != 1 {
+ t.Fatalf("backoff entries after the held finish = %d, want 1", n)
+ }
+ if _, err := w.fx.st.db.ExecContext(context.Background(), `DELETE FROM platform_pending_mints WHERE platform = ?`, w.acct.Sqid); err != nil {
+ t.Fatal(err)
+ }
+ if out := w.list(t); out["count"] != float64(0) {
+ t.Fatalf("list count = %v, want the removed promise gone", out["count"])
+ }
+ if n := w.backoffEntries(); n != 0 {
+ t.Fatalf("backoff entries after the promise was removed = %d, want none", n)
+ }
+}
diff --git a/internal/console/platform_seams.go b/internal/console/platform_seams.go
index 9ff96c787..e3928e8a3 100644
--- a/internal/console/platform_seams.go
+++ b/internal/console/platform_seams.go
@@ -1,8 +1,14 @@
package console
+import (
+ "slices"
+ "sync"
+ "time"
+)
+
// platformSeams is the platform accounts plan's one addition to Server
-// (pre-flight C1): the platform lifecycle lock's table and the plan's test
-// seams, embedded in Server with a single line. Later tasks of the plan add
+// (pre-flight C1): the platform lifecycle lock's table, the held-promise
+// backoff and the plan's test seams, embedded in Server with a single line. Later tasks of the plan add
// their seams here; nothing else of the plan becomes a Server field. Every
// field's zero value is ready, so &Server{} literals in tests stay safe.
//
@@ -42,6 +48,93 @@ type platformSeams struct {
// manifest and the HA row), just before it hands the request to the
// create handler, with no lock held: a test may recreate the app there.
platformHostBeforeCreate func()
+ // platformClock, when set (tests only), is the clock the held-promise
+ // backoff reads (platformNow); nil is time.Now.
+ platformClock func() time.Time
+ // mintBackoff is the held-promise backoff (finishPlatformMintPaced):
+ // a pending mint found held is not tried again, and its operator line
+ // not logged again, until its entry's time. Keyed by mint id, guarded
+ // by mintBackoffMu; nil until the first held promise.
+ mintBackoffMu sync.Mutex
+ mintBackoff map[string]mintBackoffEntry
+}
+
+// platformMintHeldRetry is how long a held pending mint is left alone
+// before the next platform request tries it again. Each try scans every
+// account manifest in the bucket and logs the operator's line.
+const platformMintHeldRetry = 5 * time.Minute
+
+// mintBackoffEntry is one held pending mint: its platform, and when it is
+// tried again.
+type mintBackoffEntry struct {
+ platform string
+ until time.Time
+}
+
+// platformNow is the held-promise backoff's clock.
+func (s *platformSeams) platformNow() time.Time {
+ if s.platformClock != nil {
+ return s.platformClock()
+ }
+ return time.Now()
+}
+
+// mintBackedOff reports whether the pending mint was found held less than
+// platformMintHeldRetry ago. An entry whose time has come is dropped: it
+// would mean the same as no entry.
+func (s *platformSeams) mintBackedOff(mintID string) bool {
+ s.mintBackoffMu.Lock()
+ defer s.mintBackoffMu.Unlock()
+ e, ok := s.mintBackoff[mintID]
+ if !ok {
+ return false
+ }
+ if s.platformNow().Before(e.until) {
+ return true
+ }
+ delete(s.mintBackoff, mintID)
+ return false
+}
+
+// backOffMint records the pending mint as held, to be tried again after
+// platformMintHeldRetry. It also drops every entry whose time has come, so
+// the map holds only promises found held in the last window.
+func (s *platformSeams) backOffMint(platform, mintID string) {
+ s.mintBackoffMu.Lock()
+ defer s.mintBackoffMu.Unlock()
+ now := s.platformNow()
+ for id, e := range s.mintBackoff {
+ if !now.Before(e.until) {
+ delete(s.mintBackoff, id)
+ }
+ }
+ if s.mintBackoff == nil {
+ s.mintBackoff = map[string]mintBackoffEntry{}
+ }
+ s.mintBackoff[mintID] = mintBackoffEntry{platform: platform, until: now.Add(platformMintHeldRetry)}
+}
+
+// forgetMint drops the pending mint's backoff entry, if it has one.
+func (s *platformSeams) forgetMint(mintID string) {
+ s.mintBackoffMu.Lock()
+ defer s.mintBackoffMu.Unlock()
+ delete(s.mintBackoff, mintID)
+}
+
+// pruneMintBackoff drops the platform's entries for promises no longer
+// pending (finished, or removed by an operator). pending is every pending
+// mint of the platform.
+func (s *platformSeams) pruneMintBackoff(platform string, pending []PendingMint) {
+ s.mintBackoffMu.Lock()
+ defer s.mintBackoffMu.Unlock()
+ for id, e := range s.mintBackoff {
+ if e.platform != platform {
+ continue
+ }
+ if !slices.ContainsFunc(pending, func(m PendingMint) bool { return m.MintID == id }) {
+ delete(s.mintBackoff, id)
+ }
+ }
}
// platformStep runs the platformMintStep seam, if one is set.