Repository navigation
fix(relay): stop rejecting the near region on a cold first probe - #19233
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Warm-up probe + spread floor —
relay-region-probe.tsdiscards one warm-up/healthrequest per origin before taking three kept samples, compares regions bymin, and relaxes flap rejection tomax(150, median), so a cold first sample (TCP+TLS setup) no longer rejects the near region. - No-hint on incomplete measurement —
refreshonly lets a region win against a measured competitor; a rejected/unmeasurable peer writes anull(no-hint) cache with a 1 h TTL instead of selecting a lone survivor. - Nullable cache + fail-open — the cache
regionis now nullable andlatencyMsoptional; older builds failsafeParseon a no-hint file and re-measure. - Cache self-heal — on
registered, if the cached region differs from the best measured region and the assigned cell is >3× slower, the cache is deleted; deduped per cell per process, no-op underORCA_RELAY_REGION_OVERRIDE. - Wiring + docs —
desktop-relay-servicepassesonAssignedCellActive, the broker fires it onregistered, andrelay-regional-placement.mddocuments the no-hint-is-not-neutral contract (verifiedpreferredRegion ?? RELAY_DEFAULT_REGION=us-central1against the relay server source).
ℹ️ Nitpicks
- Cold start probes every region twice:
resolve()measures all regions and writes a fresh cache, then the firstregisteredevent triggersinvalidateIfAssignedCellIsFar, which re-fetches the catalog and re-probes all regions before concludingbest.region === cache.regionand returning without probing the cell. An in-memory "cache written this process" signal would skip the redundant second pass (2× startup probe load fleet-wide). Non-blocking; the redundant pass is bounded and deduped.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 63d18cc9d8ca9cdeeccde3702a125b643e8d21be and 28529cd. 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughRelay regional placement now uses warm-up probes, three latency samples, minimum-latency selection, instability rejection, and separate region and no-hint cache lifetimes. Shared probing validates catalog entries and HTTPS origins. The relay session broker reports assigned cells to the preference reader. The reader can remove a cached preference when the assigned cell is materially slower, while respecting overrides and per-process probe limits. Tests cover probing, caching, fallback behavior, broker notifications, and self-healing. Merge Risk: 🟡 Moderate · up to Relay regional placement changes remain blocked by a reported fetch-audit failure, so the change may not pass required checks until the fallback is corrected or the audit requirement is satisfied. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, solution, scope, wire impact, and verification. However, it omits required template sections, including ELI5, Linked Issue with an issue reference, Visual Proof or an N/A explanation, Testing checkboxes, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. Resolution Add all missing required sections. Include the linked issue after
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: fde798d7-2f08-4c0c-9690-5225261a10ef
📥 Commits
Reviewing files that changed from the base of the PR and between a62cfed and 63d18cc9d8ca9cdeeccde3702a125b643e8d21be.
📒 Files selected for processing (8)
docs/reference/relay-regional-placement.mdsrc/main/runtime/relay/desktop-relay-service.tssrc/main/runtime/relay/relay-region-preference.test.tssrc/main/runtime/relay/relay-region-preference.tssrc/main/runtime/relay/relay-region-probe.tssrc/main/runtime/relay/relay-session-broker-contract.tssrc/main/runtime/relay/relay-session-broker.test.tssrc/main/runtime/relay/relay-session-broker.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
The region probe counted the process's first /health request, which pays TCP and TLS setup, as a latency sample. The resulting spread rejected the near region on essentially every cold run, leaving the far region as the sole survivor and pinning US desktops to Asia cells for 24 hours. Discard a warm-up probe per origin, compare regions by minimum latency, and keep the spread check only for a genuinely flapping path. A region now wins only against a measured competitor; a rejected or unmeasurable peer sends no hint, which is remembered for an hour so a reconnect does not re-probe. An origin that fails its warm-up is dropped before the sampling rounds, so an unreachable region costs one probe timeout instead of four. After a control socket registers, probe the cell we landed on once per process, and delete the cache only when it names a region other than the best measured one and that cell is more than 3x slower -- a far cell under a correct cache is the director declining the hint, and re-measuring would return the same answer.
63d18cc to
28529cd
Compare
* fix(relay): never cache a region hint from a one-region catalog The director lists only regions with a serving cell, so a roll wave shortens the catalog to one entry. The resolver required only every *listed* region to be measured, so that lone region won against nothing and was cached for 24 h: a US desktop refreshing while US cells rolled published asia-east2 for a day, the incident #19233 was written to end. Now fewer listed regions than the fleet serves withholds the hint (1 h no-hint TTL), the same outcome as an unmeasurable peer. * test(relay): give the unstable-probe case a two-region catalog so it has one cause

Why
The desktop's relay region preference probed each region three times, took the median, and rejected a region when the sample spread exceeded
max(20, median*0.5). On a cold process the first sample carries TLS setup while the next two reuse the socket, so the spread rule rejected the near region on every cold run and the far region won as the sole survivor. Measured on a US-East desktop: us-central1 rejected 6/6 cold runs, asia-east2 selected and cached for 24 h. The relay database is us-central1-only, so a host homed on an Asia cell pays trans-Pacific round trips per phone connect (~10 s to connected instead of ~0.6 s). Fleet census on 2026-09-06 found ~226 non-APAC desktops sitting on asia-east2 cells.What
relay-region-probe.ts(new, split from the preference module): one discarded warm-up probe per origin, then 3 kept samples; an origin whose warm-up fails is dropped before sampling. Regions compare by min. Spread rejects only whenmax - min > max(150, median).refresh: a region only wins against a measured competitor. If fewer regions measured than the catalog lists, no hint is sent (director default placement) and the "no hint" outcome is cached with a 1 h TTL so an unreachable region does not re-probe on every reconnect. Cacheregionis now nullable; older builds failsafeParseon a no-hint file and re-measure (fail-open).registered, if the cached region differs from the best measured region and the assigned cell's RTT is >3× that region's, the cache is deleted. A correct cache the director placed elsewhere is kept without probing the cell. Deduped per cell per resolver, no-op underORCA_RELAY_REGION_OVERRIDE.docs/reference/relay-regional-placement.mdstates that no hint is not neutral: the director defaults to us-central1.Wire
No change. Only the already-optional
preferredRegionhint is affected (omitted more often).Verification
pnpm tc:node;pnpm test src/main/runtime/relay/(15 files, 130 tests) after rebase on main;check:code-quality:changed0 findings; oxlint clean, no max-lines disables.Not for merge until the owner gives the go.