platform accounts: prune held-create backoff under the lock; log refusal once
Fix round 1 on the held-create backoff (Astra, NOT READY). The gate pruned the backoff with a pending-mints list read outside the platform lifecycle lock, so a stale empty list could erase a backoff set since by another request. It no longer prunes from that list: with nothing pending but an entry left for the platform, it takes the lock and finishPendingMints re-reads and prunes there, where every backoff is set. A seam at the prune's start drives a deterministic interleaving test. A create for the held ref logged its refusal on every retry. A refusal answered from the backoff now carries errMintBackedOff and is not logged, so the line comes once per window, with the held line. The test counts every log line across repeated creates. Luna's approved runbook copy (pass 2026-11-20) for the two repair sentences, with "5 minutes" in numerals; the three rows are marked approved in the plan's copy table and pinned in the copy test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
approved_platform_accounts_copy_test.go+2 −2docs/site/cli.md+2 −2docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md+3 −3internal/console/apiplatformcustomers.go+21 −8internal/console/apiplatformcustomers_backoff_test.go+129 −6internal/console/platform_seams.go+23 −1
CI passed — run details
Intent
<task-notification> <task-id>byo5p0hy2</task-id> <tool-use-id>toolu_01D1kgCoZyHdcCTkrsSUPgYi</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/9284fe97-c7c7-4e03-80f2-87c51eb0406d/tasks/byo5p0hy2.output</output-file> <status>completed</status> <summary>Background command "Wait for Astra review and Luna pass" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 15.9 g CO₂e (2,073,112 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on platform-accounts-followups, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/approved_platform_accounts_copy_test.go b/approved_platform_accounts_copy_test.go| index a59ac576d..3156fe2b9 100644 |
| --- a/approved_platform_accounts_copy_test.go |
| +++ b/approved_platform_accounts_copy_test.go |
| @@ -168,10 +168,10 @@ func TestApprovedPlatformAccountsCopy(t *testing.T) { |
| {"docs.held_promise.no_manifest", "docs/site/cli.md", "**The account has no manifest, or the create’s manifest is at its id.** The reason is `is in this console with no manifest in the bucket` or `is another account in this console`. Check that the manifest is missing, or that its `platform_mint` is the mint id and the account row’s `platform_mint` is not the mint id. Then restore the account’s manifest. Write `accounts/<sqid>/account.json` from the row: `id`, `sqid`, `name` and `created_at` as an RFC 3339 UTC time. Add `platform`, `platform_ref` and `platform_mint` when the row has them. Add `deleted_at` as an RFC 3339 UTC time when the row’s value is not 0."}, |
| {"docs.held_promise.owner", "docs/site/cli.md", "If the row has no `platform`, also add `owner`, using the account’s first owner from the console’s memberships table. Find it with this query:"}, |
| {"docs.held_promise.owner_stop", "docs/site/cli.md", "If the query returns no address, stop and escalate. Do not write the manifest. A rebuilt console would give the account no owner. For an account with a `platform`, leave `owner` out. It has no owner until someone claims it."}, |
| - {"docs.held_promise.no_manifest_end", "docs/site/cli.md", "This replaces the create’s manifest if one is present. The platform’s next request creates the customer with a new id."}, |
| + {"docs.held_promise.no_manifest_end", "docs/site/cli.md", "This replaces the create’s manifest if one is present. After the repair, the console retries the create when the platform next requests it, with a delay of up to 5 minutes, and creates the customer with a new id."}, |
| {"docs.held_promise.ref", "docs/site/cli.md", "**Another live customer holds the ref.** The reason starts with `holds ref` or `would take ref`. Check which account holds it:"}, |
| {"docs.held_promise.ref_repair", "docs/site/cli.md", "If it is the customer the platform intended, the promise is stale. Search the bucket’s account manifests for `\"platform_mint\":\"<mint id>\"`. If one has that value, add `deleted_at` with the current UTC time. Do not delete the manifest: an account id is never given out twice. Then remove the promise:"}, |
| - {"docs.held_promise.done", "docs/site/cli.md", "After the repair, the log line stops, and `carlos platform customers list --platform <platform>` shows the expected count."}, |
| + {"docs.held_promise.done", "docs/site/cli.md", "After the repair, the console retries the create on a platform request, with a delay of up to 5 minutes; once it succeeds, the log line stops and `carlos platform customers list --platform <platform>` shows the expected count."}, |
| {"docs.held_promise.log_line", "docs/site/cli.md", "console: platform <platform>: pending customer create <mint id> held for account <id>: <reason>; repair the bucket or console"}, |
| {"log.held_promise", "internal/console/apiplatformcustomers.go", "console: platform %s: pending customer create %s held for account %d: %s; repair the bucket or console"}, |
| } |
diff --git a/docs/site/cli.md b/docs/site/cli.md| index c09f7667e..f0a83e32b 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -2701,7 +2701,7 @@ SELECT address FROM memberships WHERE account_id = <id> AND role = 'owner' ORDER |
| If the query returns no address, stop and escalate. Do not write the manifest. A rebuilt console would give the account no owner. For an account with a `platform`, leave `owner` out. It has no owner until someone claims it. |
| -This replaces the create’s manifest if one is present. The platform’s next request creates the customer with a new id. |
| +This replaces the create’s manifest if one is present. After the repair, the console retries the create when the platform next requests it, with a delay of up to 5 minutes, and creates the customer with a new id. |
| **Another live customer holds the ref.** The reason starts with `holds ref` or `would take ref`. Check which account holds it: |
| @@ -2715,7 +2715,7 @@ If it is the customer the platform intended, the promise is stale. Search the bu |
| DELETE FROM platform_pending_mints WHERE mint_id = '<mint id>'; |
| ``` |
| -After the repair, the log line stops, and `carlos platform customers list --platform <platform>` shows the expected count. |
| +After the repair, the console retries the create on a platform request, with a delay of up to 5 minutes; once it succeeds, the log line stops and `carlos platform customers list --platform <platform>` shows the expected count. |
| ### carlos accounts subdomain |
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 3782a81cd..ddfb723ca 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,17 +1394,17 @@ 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 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.log_intro | While a promise is held, the console logs this line at most once every 5 minutes, when the platform makes a request: | approved (Luna pass 2026-11-20; platform-accounts-followups, held-promise backoff #1295; was "While a promise is held, the console logs this line for every request from the platform:") | |
| | 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) | |
| | docs.held_promise.no_manifest | **The account has no manifest, or the create’s manifest is at its id.** The reason is `is in this console with no manifest in the bucket` or `is another account in this console`. Check that the manifest is missing, or that its `platform_mint` is the mint id and the account row’s `platform_mint` is not the mint id. Then restore the account’s manifest. Write `accounts/<sqid>/account.json` from the row: `id`, `sqid`, `name` and `created_at` as an RFC 3339 UTC time. Add `platform`, `platform_ref` and `platform_mint` when the row has them. Add `deleted_at` as an RFC 3339 UTC time when the row’s value is not 0. | approved (Luna pass 2026-11-19) | |
| | docs.held_promise.owner | If the row has no `platform`, also add `owner`, using the account’s first owner from the console’s memberships table. Find it with this query: | approved (Luna pass 2026-11-19 (owner step)) | |
| | docs.held_promise.owner_stop | If the query returns no address, stop and escalate. Do not write the manifest. A rebuilt console would give the account no owner. For an account with a `platform`, leave `owner` out. It has no owner until someone claims it. | approved (Luna pass 2026-11-19 (owner step)) | |
| -| docs.held_promise.no_manifest_end | This replaces the create’s manifest if one is present. The platform’s next request creates the customer with a new id. | approved (Luna pass 2026-11-19) | |
| +| docs.held_promise.no_manifest_end | This replaces the create’s manifest if one is present. After the repair, the console retries the create when the platform next requests it, with a delay of up to 5 minutes, and creates the customer with a new id. | approved (Luna pass 2026-11-20; platform-accounts-followups, held-promise backoff #1295) | |
| | docs.held_promise.ref | **Another live customer holds the ref.** The reason starts with `holds ref` or `would take ref`. Check which account holds it: | approved (Luna pass 2026-11-19) | |
| | docs.held_promise.ref_repair | If it is the customer the platform intended, the promise is stale. Search the bucket’s account manifests for `"platform_mint":"<mint id>"`. If one has that value, add `deleted_at` with the current UTC time. Do not delete the manifest: an account id is never given out twice. Then remove the promise: | approved (Luna pass 2026-11-19) | |
| -| docs.held_promise.done | After the repair, the log line stops, and `carlos platform customers list --platform <platform>` shows the expected count. | approved (Luna pass 2026-11-19) | |
| +| docs.held_promise.done | After the repair, the console retries the create on a platform request, with a delay of up to 5 minutes; once it succeeds, the log line stops and `carlos platform customers list --platform <platform>` shows the expected count. | approved (Luna pass 2026-11-20; platform-accounts-followups, held-promise backoff #1295) | |
| | log.held_promise | Operator log line, `internal/console/apiplatformcustomers.go` (`held`), quoted by the runbook: `console: platform %s: pending customer create %s held for account %d: %s; repair the bucket or console` | approved (Luna pass 2026-11-19) | |
| **Task 15 (copy review, Luna pass + Paul 2026-11-19).** Paul approved Luna's rows as written except four, which carry his text: `delete.platform_has_customers` (no count), `audit.revoke`, `Minted` (split into `MintedPublish` and `MintedDeploy`, with `audit.credential` split the same way into `audit.credential_publish` and `audit.credential_deploy`: publish names the customer, deploy names the app in the customer), and `email.lapse_grace` for a platform's owners (new `email.platform.lapse_grace`: the approved `email.lapse_grace` without "unless you choose what stays", which only the customer's own owners can act on; the ordinary owner email keeps `email.lapse_grace`). Task 15 also added `list.failed` and `show.failed`, the read doors' own failure rows for a store error (500), in Paul's wording. |
diff --git a/internal/console/apiplatformcustomers.go b/internal/console/apiplatformcustomers.go| index 53750cfea..8ba8e4338 100644 |
| --- a/internal/console/apiplatformcustomers.go |
| +++ b/internal/console/apiplatformcustomers.go |
| @@ -214,10 +214,12 @@ 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 { |
| + // With nothing pending but a held promise still backed off (an operator |
| + // removed it), finishPendingMints drops its entry: it re-reads the |
| + // pending mints under the lock, as every backoff is set under it. This |
| + // snapshot, read outside the lock, may be stale and must never prune |
| + // (Astra, follow-ups review): it could erase a backoff set since. |
| + if err == nil && (len(pending) > 0 || s.mintBackoffFor(acct.Sqid)) { |
| unlock := s.lockPlatformLifecycle(acct.Sqid) |
| err = s.finishPendingMints(ctx, acct) |
| unlock() |
| @@ -483,8 +485,12 @@ func (s *Server) handlePlatformCustomerCreate(w http.ResponseWriter, r *http.Req |
| continue |
| } |
| 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) |
| + // Inside a held promise's backoff window the refusal is not |
| + // logged again: it was logged with the try that held it. |
| + if !errors.Is(err, errMintBackedOff) { |
| + 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) |
| return |
| } |
| @@ -653,19 +659,26 @@ func (s *Server) finishPendingMints(ctx context.Context, platform *Account) erro |
| return nil |
| } |
| +// errMintBackedOff marks an errPlatformMintHeld answered from the backoff, |
| +// without a try: nothing was read or logged, and its caller logs nothing |
| +// either. |
| +var errMintBackedOff = errors.New("console: the held pending customer create was not tried again yet") |
| + |
| // 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 |
| +// errPlatformMintHeld (and errMintBackedOff) 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) |
| + return nil, fmt.Errorf("%w (%w): mint %s: found held less than %s ago", errPlatformMintHeld, errMintBackedOff, |
| + m.MintID, platformMintHeldRetry) |
| } |
| cust, err := s.finishPlatformMint(ctx, platform, m) |
| if errors.Is(err, errPlatformMintHeld) { |
diff --git a/internal/console/apiplatformcustomers_backoff_test.go b/internal/console/apiplatformcustomers_backoff_test.go| index 14525a8be..a809907a2 100644 |
| --- a/internal/console/apiplatformcustomers_backoff_test.go |
| +++ b/internal/console/apiplatformcustomers_backoff_test.go |
| @@ -2,6 +2,7 @@ package console |
| import ( |
| "context" |
| + "fmt" |
| "log" |
| "net/http" |
| "strings" |
| @@ -102,6 +103,42 @@ func (w *heldBackoffWorld) heldLines() int { |
| return strings.Count(w.logs.String(), " held for account ") |
| } |
| +// listAsync makes one platform read request on its own goroutine, and |
| +// answers its status (or its transport error) on the channel. |
| +func (w *heldBackoffWorld) listAsync() <-chan error { |
| + done := make(chan error, 1) |
| + go func() { |
| + status, _, raw, err := callJSON(http.MethodGet, platformCustomersURL(w.fx.ts.URL, w.acct.Sqid), w.tok, nil) |
| + if err == nil && status != http.StatusOK { |
| + err = fmt.Errorf("list = %d %s", status, raw) |
| + } |
| + done <- err |
| + }() |
| + return done |
| +} |
| + |
| +// wantListed fails unless an async list answered 200. |
| +func wantListed(t *testing.T, what string, err error) { |
| + t.Helper() |
| + if err != nil { |
| + t.Fatalf("%s: %v", what, err) |
| + } |
| +} |
| + |
| +// logLines counts every line logged so far. |
| +func (w *heldBackoffWorld) logLines() int { |
| + return strings.Count(w.logs.String(), "\n") |
| +} |
| + |
| +// ownRefCreates makes n creates for the held ref, each refused. |
| +func (w *heldBackoffWorld) ownRefCreates(t *testing.T, n int) { |
| + t.Helper() |
| + for i := 0; i < n; i++ { |
| + 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", status, out, http.StatusBadGateway, "create.failed") |
| + } |
| +} |
| + |
| // backoffEntries is how many held promises the server is backing off. |
| func (w *heldBackoffWorld) backoffEntries() int { |
| w.fx.srv.mintBackoffMu.Lock() |
| @@ -163,12 +200,13 @@ func TestHeldPromiseBacksOffItsScanAndLogLine(t *testing.T) { |
| 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) |
| + // A create for the held ref is refused at once, without a rescan, and |
| + // adds no log line at all, however often it is retried. |
| + before := w.logLines() |
| + w.ownRefCreates(t, 3) |
| + w.wantScans(t, "the own-ref creates", false) |
| + if n := w.logLines() - before; n != 0 { |
| + t.Fatalf("own-ref creates inside the window logged %d lines, want none:\n%s", n, w.logs) |
| } |
| wantHeldPromise(t, w.fx, w.acct.Sqid, "4812", 1) |
| @@ -186,6 +224,91 @@ func TestHeldPromiseBacksOffItsScanAndLogLine(t *testing.T) { |
| 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) |
| + |
| + // A window later, the first create for the held ref tries it: the held |
| + // line and the create's refusal, once each. Its retries log nothing. |
| + w.advance(platformMintHeldRetry) |
| + before = w.logLines() |
| + w.ownRefCreates(t, 1) |
| + w.wantScans(t, "the first own-ref create after the window", true) |
| + if n := w.logLines() - before; n != 2 || w.heldLines() != 3 || |
| + !strings.Contains(w.logs.String(), `create customer for ref "4812" refused`) { |
| + t.Fatalf("the first own-ref create after the window logged %d lines, want the held line and the refusal:\n%s", n, w.logs) |
| + } |
| + before = w.logLines() |
| + w.ownRefCreates(t, 3) |
| + w.wantScans(t, "own-ref creates after the retry", false) |
| + if n := w.logLines() - before; n != 0 { |
| + t.Fatalf("own-ref creates after the retry logged %d lines, want none:\n%s", n, w.logs) |
| + } |
| + wantHeldPromise(t, w.fx, w.acct.Sqid, "4812", 1) |
| +} |
| + |
| +// TestHeldPromiseBackoffSurvivesAStalePrune is Astra's finding on the |
| +// follow-ups: a request that read no pending mints must not prune with |
| +// that list after a concurrent request has held a new promise. The first |
| +// request is paused just as it prunes, and a second promise is reserved and |
| +// held by another request. Prunes run under the platform lifecycle lock, so |
| +// with the first request paused there the second waits for it; were the |
| +// prune outside the lock, the second would hold its promise first and the |
| +// stale prune would erase that backoff. Either way the entry must survive, |
| +// and the next request must neither scan nor log. |
| +func TestHeldPromiseBackoffSurvivesAStalePrune(t *testing.T) { |
| + w := newHeldBackoffWorld(t) |
| + ctx := context.Background() |
| + w.list(t) |
| + // The operator removes the first promise: nothing is pending, and its |
| + // entry is left for the next request's prune. |
| + if _, err := w.fx.st.db.ExecContext(ctx, `DELETE FROM platform_pending_mints WHERE platform = ?`, w.acct.Sqid); err != nil { |
| + t.Fatal(err) |
| + } |
| + w.scans.take() |
| + |
| + paused, resume := make(chan struct{}), make(chan struct{}) |
| + // Only the first prune pauses; a later one (the second request's) goes |
| + // straight through. |
| + var pausedOnce atomic.Bool |
| + w.fx.srv.mintPruneEnter = func() { |
| + if pausedOnce.CompareAndSwap(false, true) { |
| + close(paused) |
| + <-resume |
| + } |
| + } |
| + first := w.listAsync() |
| + <-paused |
| + |
| + // A second promise, held for the same reason as the first. |
| + mintID := strings.Repeat("ef", 16) |
| + if err := w.fx.st.ReservePlatformMint(ctx, PendingMint{MintID: mintID, Platform: w.acct.Sqid, Ref: "4900", Name: "cafe", |
| + By: "service:" + w.acct.Sqid + "/cms", CreatedAt: time.Now()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if w.fx.srv.platformLocks.held(w.acct.Sqid) { |
| + // The paused prune holds the lock: the request holding the new |
| + // promise waits for it, so resume first. |
| + second := w.listAsync() |
| + close(resume) |
| + wantListed(t, "the paused request", <-first) |
| + wantListed(t, "the request holding the new promise", <-second) |
| + } else { |
| + w.list(t) |
| + close(resume) |
| + wantListed(t, "the paused request", <-first) |
| + } |
| + |
| + w.fx.srv.mintBackoffMu.Lock() |
| + _, ok := w.fx.srv.mintBackoff[mintID] |
| + w.fx.srv.mintBackoffMu.Unlock() |
| + if !ok { |
| + t.Fatalf("the new held promise's backoff entry is gone, want it kept") |
| + } |
| + w.scans.take() |
| + before := w.logLines() |
| + w.list(t) |
| + w.wantScans(t, "the request after the prune", false) |
| + if n := w.logLines() - before; n != 0 { |
| + t.Fatalf("the request after the prune logged %d lines, want none:\n%s", n, w.logs) |
| + } |
| } |
| // TestHeldPromiseFinishesAfterRepairOnceTheWindowEnds: an operator restores |
diff --git a/internal/console/platform_seams.go b/internal/console/platform_seams.go| index e3928e8a3..5953fc470 100644 |
| --- a/internal/console/platform_seams.go |
| +++ b/internal/console/platform_seams.go |
| @@ -57,6 +57,10 @@ type platformSeams struct { |
| // by mintBackoffMu; nil until the first held promise. |
| mintBackoffMu sync.Mutex |
| mintBackoff map[string]mintBackoffEntry |
| + // mintPruneEnter, when set (tests only), is the first statement of |
| + // pruneMintBackoff, after its caller read the pending mints: a test may |
| + // pause the prune there. |
| + mintPruneEnter func() |
| } |
| // platformMintHeldRetry is how long a held pending mint is left alone |
| @@ -121,10 +125,28 @@ func (s *platformSeams) forgetMint(mintID string) { |
| delete(s.mintBackoff, mintID) |
| } |
| +// mintBackoffFor reports whether any of the platform's held promises has a |
| +// backoff entry. |
| +func (s *platformSeams) mintBackoffFor(platform string) bool { |
| + s.mintBackoffMu.Lock() |
| + defer s.mintBackoffMu.Unlock() |
| + for _, e := range s.mintBackoff { |
| + if e.platform == platform { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| // 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. |
| +// mint of the platform, read under the platform lifecycle lock, which the |
| +// caller still holds: every backoff is set under that lock, so a list read |
| +// outside it could be older than an entry and erase it. |
| func (s *platformSeams) pruneMintBackoff(platform string, pending []PendingMint) { |
| + if s.mintPruneEnter != nil { |
| + s.mintPruneEnter() |
| + } |
| s.mintBackoffMu.Lock() |
| defer s.mintBackoffMu.Unlock() |
| for id, e := range s.mintBackoff { |