Skip to content

fix(relay): stop rejecting the near region on a cold first probe - #19233

Merged
Jinwoo-H merged 2 commits into
mainfrom
relay/region-probe-warm-up
Sep 7, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
relay/region-probe-warm-up

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​324 $\color{#cf222e}{\Huge{\mathbf{−}}}$​51 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​273
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​319 $\color{#cf222e}{\Huge{\mathbf{−}}}$​158 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​161

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 when max - 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. Cache region is now nullable; older builds fail safeParse on a no-hint file and re-measure (fail-open).
  • Cache self-heal: when the broker publishes 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 under ORCA_RELAY_REGION_OVERRIDE.
  • docs/reference/relay-regional-placement.md states that no hint is not neutral: the director defaults to us-central1.

Wire

No change. Only the already-optional preferredRegion hint 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:changed 0 findings; oxlint clean, no max-lines disables.
  • Independent adversarial review, two rounds, replayed the measured cold-run timings through the new exports: us-central1 selected; total us failure yields no hint (not asia); correct cache survives three far-cell migrations with zero cell probes; no-hint cache costs 0 probes on the next reconnect within 1 h; old and new cache formats verified both directions.

Not for merge until the owner gives the go.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Warm-up probe + spread floor — relay-region-probe.ts discards one warm-up /health request per origin before taking three kept samples, compares regions by min, and relaxes flap rejection to max(150, median), so a cold first sample (TCP+TLS setup) no longer rejects the near region.
  • No-hint on incomplete measurement — refresh only lets a region win against a measured competitor; a rejected/unmeasurable peer writes a null (no-hint) cache with a 1 h TTL instead of selecting a lone survivor.
  • Nullable cache + fail-open — the cache region is now nullable and latencyMs optional; older builds fail safeParse on 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 under ORCA_RELAY_REGION_OVERRIDE.
  • Wiring + docs — desktop-relay-service passes onAssignedCellActive, the broker fires it on registered, and relay-regional-placement.md documents the no-hint-is-not-neutral contract (verified preferredRegion ?? RELAY_DEFAULT_REGION = us-central1 against the relay server source).

ℹ️ Nitpicks

  • Cold start probes every region twice: resolve() measures all regions and writes a fresh cache, then the first registered event triggers invalidateIfAssignedCellIsFar, which re-fetches the catalog and re-probes all regions before concluding best.region === cache.region and 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 360500e0-435e-4e35-8efc-25c446856a3f

📥 Commits

Reviewing files that changed from the base of the PR and between 63d18cc9d8ca9cdeeccde3702a125b643e8d21be and 28529cd.

📒 Files selected for processing (1)
  • src/main/global-fetch-call-site-audit.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Relay 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 28529

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 o… Add all missing required sections. Include the linked issue after Fixes #, state N/A with a reason for Visual Proof if no UI or interaction changed, complete the Testing section and required checkboxes, provide the applicable AI Disclos…
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary fix: preventing cold first probes from rejecting a nearby relay region.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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 Fixes #, state N/A with a reason for Visual Proof if no UI or interaction changed, complete the Testing section and required checkboxes, provide the applicable AI Disclosure, complete Review, Agent skill upstream boundary, Notes, and Checklist sections, and add a concise ELI5 explanation.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

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.md
  • src/main/runtime/relay/desktop-relay-service.ts
  • src/main/runtime/relay/relay-region-preference.test.ts
  • src/main/runtime/relay/relay-region-preference.ts
  • src/main/runtime/relay/relay-region-probe.ts
  • src/main/runtime/relay/relay-session-broker-contract.ts
  • src/main/runtime/relay/relay-session-broker.test.ts
  • src/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.
@Jinwoo-H
Jinwoo-H force-pushed the relay/region-probe-warm-up branch from 63d18cc to 28529cd Compare September 7, 2026 08:35
@Jinwoo-H
Jinwoo-H merged commit 33af0af into main Sep 7, 2026
28 checks passed
@Jinwoo-H
Jinwoo-H deleted the relay/region-probe-warm-up branch September 7, 2026 17:11
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
* 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
@pullfrog pullfrog Bot mentioned this pull request Sep 10, 2026
8 of 9 tasks
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.

1 participant