Repository navigation
Custom domains page polls certificate progress fast only while a certificate is generating - #1802
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces dynamic polling for custom domain certificate progress, utilizing a 5-second interval during active generation or immediately after a domain change, and a 1-minute interval during idle periods. It also adds corresponding tests and documentation. The review feedback recommends evicting stale entries from the watchingUntil map in getChallengeCertificates.ts to prevent memory accumulation over time as cluster IDs churn.
| export function watchChallengeCertificates(queryClient: QueryClient, clusterId: string) { | ||
| watchingUntil.set(clusterId, Date.now() + CERTIFICATE_WATCH_AFTER_DOMAIN_CHANGE_MS); | ||
| return queryClient.invalidateQueries({ queryKey: challengeCertificatesQueryKey(clusterId) }); | ||
| } |
There was a problem hiding this comment.
To prevent memory accumulation over time as cluster IDs churn (e.g., due to deletion, rolling replacements, or autoscaling), stale entries in the watchingUntil map should be evicted once they exceed their validity horizon.
export function watchChallengeCertificates(queryClient: QueryClient, clusterId: string) {
const now = Date.now();
for (const [id, until] of watchingUntil.entries()) {
if (until <= now) {
watchingUntil.delete(id);
}
}
watchingUntil.set(clusterId, now + CERTIFICATE_WATCH_AFTER_DOMAIN_CHANGE_MS);
return queryClient.invalidateQueries({ queryKey: challengeCertificatesQueryKey(clusterId) });
}References
- When caching or tracking state (such as last observation times) for dynamic entities (e.g., cluster nodes) processed in chronological order, evict stale entries once they exceed their validity horizon. This prevents memory accumulation when entity IDs churn (e.g., due to autoscaling or rolling replacements). Ensure that evicted entities can be correctly re-registered if they reappear.
There was a problem hiding this comment.
Declining. The only writer is watchChallengeCertificates, called once per successful domain change from setDomainIdsOnCluster's onSuccess (setDomainIdsOnCluster.ts:37). The map is keyed by cluster id, so a repeat overwrites the entry. A tab therefore holds at most one number per cluster its user changed domains on by hand. Nothing here churns the way the referenced autoscaling case does. An expired entry is also already inert, because the read compares it against Date.now() (getChallengeCertificates.ts:41). An eviction pass would add code to save a few bytes on a small, bounded set of entries.
🤖 Generated by Claude Code (Claude Opus 5.5); posted via @dawsontoth.
The Domains table polled the cluster's ChallengeCertificate rows every 5s for as long as it was open. A cluster without that table answers 404, which getSearchByValue reads as an empty result, so the poll never errored and pollUnlessForbidden could never stop it: one tab sent ~1,000 doomed requests in two hours. Poll at 5s only while a certificate is generating, or for three minutes after a domain change, and once a minute otherwise. The domain-ids mutation now starts that window and re-reads the rows at once, since nothing else ever invalidated them and the 5s poll was the only way a new challenge was seen. Closes #1630 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Bind selection was page state that outlived its rows. A ticked domain that was then removed, or bound to another cluster, was still counted and sent, and central manager refused every later Bind (404 not found, 400 already associated) until the page was left. Bind now counts and sends the selection intersected with the list's bindable rows, using the same predicate that renders the checkbox. A removal takes its row out of the cached list as soon as it succeeds, so the gap before the refetch lands cannot send it, and Bind waits while a removal is in flight, including a click queued before the controls disabled. Remove likewise refuses a click queued behind a Bind that is still sending its domain. Bind reads the list from the query client at click time, since a removal reaches the button a render later. Closes #1800 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e the guards read The bind, unbind and remove handlers read mutation state and the domain list from useQueryClient() but still invalidated through the module-level queryClient import. Production provides that same instance, so nothing changed there, but any other provider (every test here) never saw the refetch. Tests now pin that each change refetches the list on the page's own client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A domain change that reads the list before sending it (as the pre-send check stacked on this branch does) would satisfy a count taken at click time with no invalidation at all. Counting from the request makes only the post-success refetch pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n the page, and pre-check it
A refused PUT /Cluster/{id} (bind, unbind, or a cluster edit) produced only a toast that faded,
and the domain changes sent whole lists Studio had not checked. RUM showed 39 of 40 such PUTs
refused in a day on one cluster, with users retrying across three pages (#1686).
Domain changes now pass intent (add, remove). The mutation builds the list from a fresh read of
the cluster and the organization's domains rather than from what the page last saw, so a domain
another member bound meanwhile is no longer silently unbound. Before sending, it refuses what
central manager would refuse, mirroring its source:
- the cluster is not RUNNING, or an instance is FAILED or in TRANSITIONING_INSTANCE_STATES
(assertClusterMutable, sharedHelpers.js:587-606; STOPPED and UPDATED included);
- the cluster is self-managed (updateCluster.js:166);
- a domain the change touches is missing, unverified or bound to another cluster
(updateCluster.js:173-191), the cluster's existing ones included; those point at support.
It refuses rather than drops: central manager unbinds whatever the new list leaves out without
checking which cluster holds it (updateCluster.js:199-205).
Bind and unbind failures, refusals and central manager's own reasons alike, now stay on the
Domains page; a cluster edit's failure stays beside its submit button. Both mutations skip the
global toast and report real request failures to RUM at mutation level. #1801's cache write of
the accepted list is gone, since every change now re-reads the cluster.
Refs #1686
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ays why The tooltip's trigger slotted onto a fragment, which can take neither the trigger's props nor its ref, so React dropped every handler and logged an invalid-prop warning on each render. Slot it onto a wrapper around the button instead: a disabled button takes no pointer events, so the hover has to land on something around it. The domain name stays outside the trigger, so reading it does not pop a tooltip about deleting it. Closes #1843 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oard users get the tooltip A disabled button can't take focus, so the explanation for why Remove is off was hover-only. The wrapper the tooltip triggers on is now focusable exactly while the button is disabled; while it is enabled the button keeps the only tab stop and its focus still opens the tooltip. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Radix puts aria-describedby on the trigger, and with the wrapper always the trigger an enabled Remove took focus while the wrapper held the description, so a screen reader never announced it. The button is now the trigger unless the domain is bound; only then does a focusable wrapper stand in, so an in-flight change no longer gives unbound rows a tab stop whose tip doesn't explain the disabled state. Tests check the focused element's aria-describedby against the tooltip, plus the pending case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5b0d6a8 to
b2ee95a
Compare
Closes #1630
⊙ Problem
The cluster Domains table polled the cluster's
ChallengeCertificaterows every 5 seconds for as long as it was open. A cluster without that table answers 404, andgetSearchByValuedeliberately reads a 404 as an empty result. So the poll never errored,pollUnlessForbiddencould never stop it, and one long-lived tab sent 993 doomed requests in 112 minutes. In RUM,/Cluster/{id}/operation404s rose from 71 to 1,399 a week (#1630). The rows exist only to show a certificate being generated, so the 5s rate was spent exactly when there was nothing to watch.💡 Solution
The poll runs at 5s only while a certificate is generating (no
issueDate, orinProgress), or for three minutes after a domain change. Otherwise it polls once a minute. The 403 stop frompollUnlessForbiddenstill applies on top.The issue's recommended option 2 needed one correction. Invalidating the rows when the domain-ids mutation succeeds is not enough on its own: central manager answers the PUT before host manager acts on it, and host manager only upserts a row per added domain once it reconciles the change (deploying the cert component and restarting, the first time). An immediate re-read usually finds nothing yet. So the mutation starts a three-minute watch window and re-reads the rows at once.
⚖️ Alternatives
getSearchByValue's shared 404-as-empty contract, or wrapping it. The watch window already covers the only Studio action that creates the table, and the idle rate bounds everything else.UPDATING: it is a server-side signal, but it couples this query to the cluster record and to statuses that version upgrades also use.🔧 Changes
getChallengeCertificates.ts:challengeCertificatePollIntervalpicks 5s or 60s, and the query'srefetchIntervalwraps it inpollUnlessForbidden.watchChallengeCertificatesopens a per-cluster window and invalidateschallengeCertificatesQueryKey, the key the query itself uses.isGeneratingCertificateis now the one definition of "generating".setDomainIdsOnCluster.ts: the mutation'sonSuccessalso callswatchChallengeCertificates. It runs at mutation level, so it fires even if the table unmounted mid-request.tableDefinition.tsx: both "generating" checks useisGeneratingCertificate.src/features/cluster/DESIGN.md,DESIGN.md: a note on cert intent being cluster-wide (from Unbinding one custom domain no longer turns off certificates for the others #1801) and on why certificate progress is polled this way, plus the index line.✅ Verification
End-to-end route: not observable end-to-end here. It needs a cluster without the
ChallengeCertificatetable and an open Domains tab over minutes. Verified at the query's ownrefetchIntervaland through the realDomainsManagement:getChallengeCertificates.test.ts(new), against the query options' ownrefetchInterval:watchChallengeCertificates, for that cluster only, and idles again once the window passes (fakeDate);falseon a 403.Management.test.tsx: a domain change re-reads the certificate rows at once (a secondsearch_by_valueonChallengeCertificate).onSuccessreverted to the Unbinding one custom domain no longer turns off certificates for the others #1801 version, the re-read test fails (expected 2 calls, got 1). Making the interval constant again fails the idle and window tests, and ignoring the window fails the window test.npx vitest run396 files / 3,675 passed (exit 0),npx tsc -bexit 0,npx oxlint --format stylish .exit 0,npx dprint checkexit 0, with Node 24.21.0.Pre-push review: one full round against the #1801 branch (codex graded, gemini). The verdict was COMMENTS with no defects found. The Harper-domain adjudicator failed on auth and the Cursor legs failed on the 1Password SSH agent, as on #1801. I took the comment trims. I rejected:
.tsimport extensions: this repo's imports are extensionless throughout;watchingUntilmap: it holds one entry per cluster this tab changed domains on;🤖 Generated with Claude Code (Claude Opus 5.5); posted via @dawsontoth.
Related PRs: #1801 overlaps (this PR stacks on it)
Complexity: medium
Review-Coverage: authored=claude; ran=gemini,codex; blocked=cursor-composer(no-receipt),domain(auth); declined=cursor-grok,cursor-kimi,cursor-muse; rounds=1; full=1 @ 5b0d6a8
Review-Attention: read ~3m (raised: degraded review) @ 5b0d6a8