Skip to content

fix(clusters): keep the chosen region when a second region is removed on a single-region tier - #1842

Draft
dawsontoth wants to merge 2 commits into
stagefrom
claude/1275-region-removal-keeps-siblings
Draft

dawsontoth wants to merge 2 commits into
stagefrom
claude/1275-region-removal-keeps-siblings

Conversation

@dawsontoth

@dawsontoth dawsontoth commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

⊙ Problem

On a tier that allows only one region (the free tier, which carries allowedRegionIds), removing the second region of a new cluster threw away the first region too: it snapped back to the default US region and its smallest latency (#1275). The free tier's own validation error on the second row ("You can only select one region with this performance tier!") is what asks the user to remove it, so the natural fix-up step is the one that loses their choice.

Reproduced on current stage in a real browser (Playwright against a local dev server with mocked API responses): pick Medium, choose Europe 45ms for region 1, add a region, switch to Free, remove region 2. Region 1 read US / 90ms, small distribution afterwards.

The cause is autoSelectRegionBasedOnAllowedRegionIds in ClusterForm.tsx. It corrects the only remaining region whenever that region is not one the tier allows, and it always corrected to US. Removing the second row is what drops the count to one and fires it. The triage suspect, autoPickLatencyDescription in RegionFormInputs.tsx, is not involved: rows are keyed by field.id and removing a row leaves the other row's region and latency untouched on tiers without a region allow-list (pinned by a test below).

❓ Your call: the requirement as filed asks that the first region "remains". It now keeps its region and moves only the latency when the tier does not offer the chosen latency (Europe 45ms becomes Europe 60ms on the free tier), because the alternative is leaving an invalid selection with an error under it. If you would rather the form never auto-correct after a removal and let the user fix the flagged latency by hand, that is a one-condition change in the same effect.

💡 Solution

The correction now prefers an allowed entry in the region the user already chose, and falls back to US, then the first allowed region, only when the tier offers nothing there.

🔧 Changes

PR #1780 (custom regions) rewrites this effect to work on regionId; it keeps the US-first selection, so it will need the same preference expressed as "an allowed id whose catalog entry has the current entry's name" when it rebases. The two do not otherwise touch the same lines.

✅ Verification

Route: new component test driving the real ClusterForm (react-hook-form, zod resolver, Radix selects, the real Remove button) in jsdom, plus a live browser repro.

Cross-model review: two rounds, codex (graded) and gemini both ran. Their findings were rejected on evidence: a crash if firstRegion is undefined (the effect only runs when exactly one region exists, and the Remove button only renders with two or more), and explicit import extensions (this repo's imports are extensionless throughout). The Cursor leg could not fetch (1Password SSH agent refused to sign) and the Harper domain adjudicator failed authentication, so the outside findings were triaged by hand rather than adjudicated.

Closes #1275

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

🤖 Generated with Claude Code

Related PRs: #1780 overlaps (rewrites the same correction effect for region ids)
Complexity: easy

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

Review-Attention: skim ~2m (raised: degraded review) @ fe4bbe8

dawsontoth and others added 2 commits October 11, 2026 00:54
…ects it

A tier with allowedRegionIds (the free tier) takes a single region, and the
form corrects that region whenever it is the only one left. The correction
always jumped to the default US region, so removing the second region, which
is what the tier's "only one region" error asks the user to do, also threw
away the first region and its latency.

Prefer a latency the tier allows in the region the user chose, and fall back
to the default region only when the tier offers nothing there.

Refs #1275

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… regions

Removing the first row shifts the survivor to index 0 before the correction
runs, so pin that it keeps its region there too.

Refs #1275

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 updates the region correction logic in ClusterForm to prioritize keeping the user's chosen region when correcting regions on a tier that limits allowed regions, falling back to 'US' or the first available region only if the chosen region is not offered. It also adds corresponding documentation in DESIGN.md and a comprehensive suite of unit tests in ClusterForm.test.tsx to verify this behavior. There are no review comments to address.

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 68.96% 10312 / 14953
🔵 Statements 69.1% 11001 / 15919
🔵 Functions 62.36% 2666 / 4275
🔵 Branches 63.96% 7861 / 12290
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/features/clusters/upsert/ClusterForm.tsx 59.61% 41.81% 54.54% 59.73% 107-116, 121-125, 137-141, 160-164, 208, 211-224, 228, 231, 234, 282, 310-319, 338-371, 375-440, 459-463, 467, 471
Generated in workflow #2086 for commit fe4bbe8 by the Vitest Coverage Report Action

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.

[Create Cluster] Deleting the second region will also revert the first chosen region and latency

1 participant