Skip to content

Bind on the Domains page sends only the domains still offered for binding - #1840

Merged
dawsontoth merged 7 commits into
claude/1630-challenge-cert-poll-backofffrom
claude/1800-bind-only-live-selection
Oct 12, 2026
Merged

dawsontoth merged 7 commits into
claude/1630-challenge-cert-poll-backofffrom
claude/1800-bind-only-live-selection

Conversation

@dawsontoth

@dawsontoth dawsontoth commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1800

Stacked on #1802, which is stacked on #1801: #1801 → #1802 → this PR → #1846 (#1686). Its base is claude/1630-challenge-cert-poll-backoff, so this diff is only the Bind-selection change. Review and merge #1801 and #1802 first.

⊙ Problem

On a cluster's Domains page, the domains ticked for binding are page state that outlived their rows. Tick a domain, then click Remove Domain on it (enabled for any unbound domain, ticked or not): the row disappears, but Bind 1 Domain stays, and clicking it sends the deleted id. Central manager answers 404 Domain <id> not found, and since the selection only clears when a bind succeeds, every later Bind on that page fails the same way until the user leaves it. A ticked domain that gets bound to another cluster meanwhile fails the same way with a 400 (#1800).

❓ Your call: does this need to ship on its own? #1846, the #1686 PR stacked on this one, re-reads the domain list before every domain change and would refuse the stale id with a message. I kept this separate because it needs no extra request, and it fixes what the button counts and sends, which a refusal alone doesn't.

💡 Solution

Bind now counts and sends only the ticked domains that the current list still offers for binding: the selection intersected with the rows canBindDomain accepts, which is the same predicate that renders the checkbox. A domain that was removed, or bound elsewhere, drops out of the count and the request on its own, with no extra state to keep in sync.

Three gaps around a removal are closed as well:

⚖️ Alternatives

  • Prune the selection when the list changes (an effect, or deselect on delete): it is a second copy of the same predicate kept in sync by hand, and it misses a domain that becomes bound elsewhere in a refetch, which no delete callback sees.
  • Disable Remove Domain on a ticked row: it covers the delete but not a domain bound from another tab, and blocks a removal the user is entitled to make.

🔧 Changes

✅ Verification

End-to-end route: not observable end-to-end here — it needs a cluster, verified custom domains and a central manager, and a Bind changes real infrastructure. Verified at the request boundary instead: Management.test.tsx renders the real DomainsManagement and table against a mocked apiClient and asserts the serialized PUT body.

Pre-push review: three full rounds (codex graded, gemini). The Harper-domain adjudicator failed on auth every round and the Cursor legs failed on the 1Password SSH agent, so no round converged. Round 1 found the render-lag click (fixed: Bind reads the list from the query client); round 2 found the reverse race, a Remove queued behind a Bind (fixed: Remove shares isSettingDomainIds). Round 3 returned COMMENTS with no defects. I rejected:

  • "other useDeleteDomain callers break on the new organizationId" (gemini): tableDefinition.tsx is the only caller, and DeleteDomainSchema is only a type;
  • "a double-clicked Bind sends two PUTs" (gemini): Unbinding one custom domain no longer turns off certificates for the others #1801's mutateWhenIdle already refuses a second domain change while one is in flight;
  • the remaining comment nits (both legs): the two kept comments state why the handlers read the query client rather than the render, and why the delete writes the cache, neither of which the code says.

A fourth full round at 3740ab4 (codex graded, gemini, Harper domain adjudicator, all ok) raised nothing against the query-client change. Its one surviving minor predates this PR. After a Bind's PUT settles, the domain row has no clusterId until the [orgId] refetch lands, so for that round trip Remove is enabled on a domain the cluster now holds. Central manager refuses that DELETE with a 400, "Domain is currently assigned to a cluster. Please remove the domain from the cluster first." (src/resources/domain/Domain.js:124-129 in central-manager). It writes the domain's clusterId before the PUT answers (updateCluster.js:194), so the delete cannot land and leave a dangling id. The adjudicator's other surviving notes were a one-tick stale closure in Unbind (also predates this PR), the comment nits above, and extensionless imports (the repo's convention).

❓ Your call: close that Remove-after-Bind window here, by writing the bound domains' clusterId into the cached list on success the way a delete removes its row, or leave it to central manager's refusal? I left it, because the refusal is accurate and #1846 rebuilds this mutation.

❓ Your call: two smaller choices from the same round. A Bind or Remove refused by a guard returns silently. That only happens when a click lands in the render between another change starting and the controls disabling, so a toast would mostly be explaining a double-click. And the guards are two mutation keys that check each other, not one shared domain-change key. One key would be simpler to reason about, at the cost of re-keying #1801's useIsSettingDomainIds.

gemini-code-assist feedback: both comments, "invalidate through activeQueryClient, not the global import", were right in substance: no runtime effect, but a test's client never saw the refetch. Fixed in 3740ab4, and the tests were tightened in 594707c.

🤖 Generated with Claude Code (Claude Opus 5.5); posted via @dawsontoth.

Related PRs: #1801 overlaps (this PR stacks on it), #1802 overlaps (this PR's base), #1846 overlaps (stacked on this PR; it rebuilds the same domain-change handlers), 2 others independent
Complexity: easy

Review-Coverage: authored=claude; ran=gemini,codex; adjudicated=domain; blocked=cursor-composer(no-receipt),cursor-muse(no-receipt); declined=cursor-grok,cursor-kimi; rounds=4; full=1 @ 594707c

Review-Attention: read ~4m (decisions: settle-before-refetch, per-mutation-guards, silent-refusal, do-less-alternative) @ 594707c

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the domain binding and removal flow in the cluster domains management feature by handling race conditions between concurrent bind and delete actions. It introduces state checks to ensure only bindable domains are processed, disables controls while mutations are in flight, and optimistically updates the React Query cache upon domain deletion. The review feedback correctly points out that the global queryClient is still being used for query invalidation in Management.tsx and tableDefinition.tsx instead of the newly introduced activeQueryClient hook, which could lead to issues in test environments or custom configurations.

Comment thread src/features/cluster/domains/Management.tsx
Comment thread src/features/cluster/domains/constants/tableDefinition.tsx
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.24% 11413 / 16020
🔵 Statements 71.36% 12166 / 17048
🔵 Functions 65.75% 3014 / 4584
🔵 Branches 66.71% 8893 / 13329
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/features/cluster/domains/Management.tsx 78.02% 84.21% 82.35% 79.31% 88, 114, 117-118, 210-236, 244, 250-251
src/features/cluster/domains/canBindDomain.ts 100% 100% 100% 100%
src/features/cluster/domains/constants/tableDefinition.tsx 93.33% 83.87% 93.33% 95.34% 141, 174, 187
src/features/clusters/hooks/useUpdateCluster.ts 0% 100% 0% 0% 12-23
src/features/clusters/mutations/setDomainIdsOnCluster.ts 100% 100% 100% 100%
src/features/clusters/upsert/ClusterBilling.tsx 0% 0% 0% 0% 33-134
src/features/clusters/upsert/ClusterDetails.tsx 0% 0% 0% 0% 62-260
src/features/clusters/upsert/ClusterForm.tsx 0% 0% 0% 0% 72-590
src/features/organization/mutations/deleteDomain.ts 100% 100% 100% 100%
src/features/organization/queries/getOrganizationDomains.ts 100% 100% 100% 100%
Generated in workflow #2247 for commit e1c66ca by the Vitest Coverage Report Action

dawsontoth and others added 7 commits October 12, 2026 13:03
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>
@dawsontoth
dawsontoth marked this pull request as ready for review October 12, 2026 17:07
@dawsontoth
dawsontoth requested a review from a team as a code owner October 12, 2026 17:07
@dawsontoth
dawsontoth force-pushed the claude/1800-bind-only-live-selection branch from 594707c to e1c66ca Compare October 12, 2026 17:07
@dawsontoth
dawsontoth merged commit d56bf21 into stage Oct 12, 2026
4 checks passed
@dawsontoth
dawsontoth deleted the claude/1800-bind-only-live-selection branch October 12, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bind keeps sending a domain that was deleted after it was ticked, and fails until the page is left

1 participant