Repository navigation
feat(relay): log the region probe and name the assigned cell - #19307
Conversation
A desktop silently pinned itself to a far relay region for a day and every phone connect paid the round trip. Nothing in the desktop logs said which regions were probed, what they measured, why one was rejected, or which cell the host landed on, so the only way to diagnose it was a bench harness. The resolver now emits one line per outcome. A refresh carries every region's probe origins, the discarded warm-up, the kept samples, the minimum, the spread, and a verdict, then the chosen region or no-hint with the reason it withheld one. Cache hits, diagnostic overrides, and a director that cannot list its regions each get their own line so a quiet run is never ambiguous. Self-heal logs the cached region, the best measured region, the assigned cell's round trip, and whether it kept or deleted the cache. Only a refresh reports a catalog failure; a self-heal never chose a region, so a line saying it withheld a hint would be a lie. Relay status now carries the assigned cell so the pairing panel can name it. The field is optional because an offline host holds no assignment and the web client answers from a stub that never has one. Splitting catalog fetching out of the preference module keeps both files inside the line budget without a lint disable.
The origin pool publishes offline while it still holds the assignment it is about to rotate, so the panel kept naming a cell nothing was served from. The same class of bug hid a second instance: the coordinator republishes registered right after the broker announces its cell, and that republish carried no cell, blanking the value moments after it was set. The cell would never have reached the panel in the real flow. Deriving the cell from the status at each publisher removes both. The rule lives beside the status type because it defines when the optional field is populated, and the coordinator reads the owned broker's endpoint rather than trusting a call site to remember to pass it.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
relay-region-probe-log.ts— new[relay-region]JSON log event factory plus aconsole.infodefault sink, one line per event;relay_region_probeandrelay_region_self_healevent types.relay-region-probe.ts—sampleMinLatenciesnow returns warm-up + kept samples;measureRegionreturns aRelayRegionProbeReportwith averdict;regionMeasurement()recovers the priorRegionMeasurementshape so selection stays byte-equivalent.relay-region-catalog-fetch.ts— catalog fetching extracted out ofrelay-region-preference.ts(max-lines) plusrelayDirectorHost.relay-region-preference.ts— emits override/cache-hit/refresh/catalog-failure/self-heal events;measurements.length < reports.lengthis behavior-preserving (one report per region).mobile-relay-status.ts—MobileRelayStatusDetailand a sharedrelayStatusCellUrl()rule applied in both the broker and the coordinator so the cell is only forwarded forregistered/draining.- IPC/preload/renderer —
mobile:getRelayStatus/mobile:relayStatusChangednow carry{ status, cellUrl? }; the pairing panel renders a mutedRelay cell: hostline.
Selection, cache, self-heal, and the cell-publishing rule are all equivalent to prior behavior; the log fields are hostnames, catalog-validated origins, region names, latencies, enums, and booleans, and cellUrl is already bounded to a canonical origin by isAllowedRelayOrigin, so nothing sensitive reaches either log line. Tests are precise (exact toEqual/toMatchObject assertions rather than loose truthiness), cover the reachable verdict/reason branches, and pin the credential-free invariants.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
📝 WalkthroughWalkthroughRelay status now uses structured details with an optional relay cell URL across broker callbacks, main-process state, IPC, preload APIs, and the mobile pairing UI. The UI displays the relay cell host for registered and draining states. Relay region catalog fetching now uses a dedicated validation module. Region probes return explicit verdicts and preserve diagnostic samples. Region preference resolution emits structured probe and self-heal logs. Tests cover status propagation, region outcomes, logging, and fetch call-site accounting. Merge Risk: 🟡 Moderate · up to Relay selection can withhold a usable regional hint after transient probe failures, and a failed self-heal cache removal can leave a distant relay preference active without recording the outcome or retrying it. These reliability and diagnostics gaps should be addressed before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, and verification, but it omits required template sections and information, including ELI5, What Changed, Linked Issue with
✨ 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: a2d98ee9-107b-40b4-b36a-32f8e24d5214
📒 Files selected for processing (22)
src/main/global-fetch-call-site-audit.test.tssrc/main/ipc/mobile.test.tssrc/main/ipc/mobile.tssrc/main/runtime/relay/desktop-relay-service.tssrc/main/runtime/relay/relay-auth-coordinator.test.tssrc/main/runtime/relay/relay-auth-coordinator.tssrc/main/runtime/relay/relay-region-catalog-fetch.tssrc/main/runtime/relay/relay-region-preference.tssrc/main/runtime/relay/relay-region-probe-log.test.tssrc/main/runtime/relay/relay-region-probe-log.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.tssrc/main/startup/main-process-runtime-launch.tssrc/main/startup/main-process-state.tssrc/preload/api/mobile-api.tssrc/preload/api/mobile-bridge.tssrc/renderer/src/components/settings/MobilePairingConnectionOptions.test.tsxsrc/renderer/src/components/settings/MobilePairingConnectionOptions.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/shared/mobile-relay-status.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Self-heal catalog-failure reporting —
invalidateIfAssignedCellIsFarhoists its logoutcome(defaulting toreason: 'catalog-unavailable') and passes anonCatalogFailurecallback intoprobeCatalog, so a director that cannot list its regions is now reported underrelay_region_self_healbefore the throw instead of staying silent. probeCatalogcleanup —fetchRelayRegionCatalogis inlined and the now-dead privatefetchCatalogwrapper is removed.- Reason union + test — the self-heal
reasonunion gainscatalog-unavailable, with a test pinning the new report and a second asserting the failure surfaces under the self-heal event rather than as a withheld-hint probe event.
The catalog-unavailable default is only observed when the catalog fetch throws; logSelfHeal spreads outcome synchronously, so the emitted event is a correct snapshot (null bestRegion/bestLatencyMs, decision: kept) and the success path still logs exactly once. Tests pass (25/25 in relay-region-preference.test.ts).
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/runtime/relay/relay-region-preference.ts (1)
158-158: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winEmit the self-heal event when cache removal fails.
If
rmSyncthrows, control reaches the outer catch beforethis.logSelfHeal(outcome). The cache remains active, andselfHealedCellsprevents another attempt for that cell. Catch the removal error locally and log the outcome withdecision: 'kept'. Add a test for a failed cache removal.Proposed fix
- outcome.decision = far ? 'deleted' : 'kept' + outcome.decision = 'kept' outcome.reason = far ? 'assigned-cell-far' : 'assigned-cell-near' if (far) { - rmSync(this.cachePath(), { force: true }) + try { + rmSync(this.cachePath(), { force: true }) + outcome.decision = 'deleted' + } catch { + // Keep the cache and still report the measured self-heal outcome. + } } this.logSelfHeal(outcome)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 4fad7584-223c-433b-a5cd-f8d6db76af31
📒 Files selected for processing (4)
src/main/runtime/relay/relay-region-preference.test.tssrc/main/runtime/relay/relay-region-preference.tssrc/main/runtime/relay/relay-region-probe-log.test.tssrc/main/runtime/relay/relay-region-probe-log.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/runtime/relay/relay-region-probe-log.test.ts
- src/main/runtime/relay/relay-region-probe-log.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.

Stacked on #19233
Base is
relay/region-probe-warm-up. Retarget tomainafter #19233 merges.Why
A desktop silently picked a far relay region for a day and every phone connect paid ~10 s. Nothing in the desktop logs said which regions were probed, what the samples were, why a region was rejected, or which cell the host ended up on. Diagnosing it took a bench harness.
What
[relay-region]JSON events in the main process:relay_region_probeper refresh: per region the origins, discarded warm-up sample, kept samples, min, spread, verdict (measured/rejected-spread/unreachable), then the chosen region or no hint with a reason (measured,held-previous,sole-survivor-forbidden,all-rejected,all-unreachable,catalog-unavailable,override,cached), whether the outcome was cached, and its TTL.relay_region_self_healper check: cached region, best measured region and latency, assigned cell URL and latency, decision, reason.MobileRelayStatusDetail.cellUrl(optional) on the relay status IPC, rendered in the pairing panel as a muted line. A shared rule keeps the cell only forregisteredanddraining, applied in the broker and the auth coordinator so an offline or reconnecting status never shows a stale cell.relay-region-catalog-fetch.ts(max-lines).No secrets reach either log line: fields are hostnames, catalog-validated origins, region names, latencies, enums, booleans. The status payload travels only over Electron IPC (main, preload, renderer ship together); the event shape changed from a bare string to an object, so do not cherry-pick one half.
Verification
pnpm tc(node, cli, web), relay + mobile IPC + panel tests (18 files, 199 tests),check:code-quality:changed0 across 21 files, react-doctor 0 new, oxlint clean, no max-lines disables.Not for merge until the owner gives the go.