Skip to content

feat(relay): log the region probe and name the assigned cell - #19307

Merged
Jinwoo-H merged 5 commits into
mainfrom
relay/region-probe-logging
Sep 7, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
relay/region-probe-logging

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor

Re-opened against main after #19233 merged and its branch deletion auto-closed #19240. Head is the same work rebased plus one audit-table commit.

Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​513 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​506
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​454 $\color{#cf222e}{\Huge{\mathbf{−}}}$​129 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​325

Stacked on #19233

Base is relay/region-probe-warm-up. Retarget to main after #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

  • One-line [relay-region] JSON events in the main process:
    • relay_region_probe per 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_heal per 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 for registered and draining, applied in the broker and the auth coordinator so an offline or reconnecting status never shows a stale cell.
  • Catalog fetching moved into 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:changed 0 across 21 files, react-doctor 0 new, oxlint clean, no max-lines disables.
  • Independent adversarial review: lane A selection, cache, and self-heal behaviour byte-equivalent by replay; log cardinality one event per refresh / per check; the nit round found and fixed a second publisher that would have blanked the cell in the real flow.

Not for merge until the owner gives the go.

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.

@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

  • relay-region-probe-log.ts — new [relay-region] JSON log event factory plus a console.info default sink, one line per event; relay_region_probe and relay_region_self_heal event types.
  • relay-region-probe.ts — sampleMinLatencies now returns warm-up + kept samples; measureRegion returns a RelayRegionProbeReport with a verdict; regionMeasurement() recovers the prior RegionMeasurement shape so selection stays byte-equivalent.
  • relay-region-catalog-fetch.ts — catalog fetching extracted out of relay-region-preference.ts (max-lines) plus relayDirectorHost.
  • relay-region-preference.ts — emits override/cache-hit/refresh/catalog-failure/self-heal events; measurements.length < reports.length is behavior-preserving (one report per region).
  • mobile-relay-status.ts — MobileRelayStatusDetail and a shared relayStatusCellUrl() rule applied in both the broker and the coordinator so the cell is only forwarded for registered/draining.
  • IPC/preload/renderer — mobile:getRelayStatus / mobile:relayStatusChanged now carry { status, cellUrl? }; the pairing panel renders a muted Relay cell: host line.

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.

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

📝 Walkthrough

Walkthrough

Relay 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 1fe72

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, implementation, and verification, but it omits required template sections and information, including ELI5, What Changed, Linked Issue with Fixes #, Visual Proof… Complete the required template sections. Add the linked issue reference, provide UI before/after proof or state N/A with a reason, complete the testing and checklist items, and address the remaining required sections explicitly.
Docstring Coverage ⚠️ Warning Docstring coverage is 14.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 22 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 changes: relay-region probe logging and assigned-cell visibility.
Linked Issues check ✅ Passed The changes satisfy the linked issue objectives [#19240]. They add probe and self-heal diagnostics, expose the assigned cell through IPC and the pairing panel, suppress stale cells for non-assigned st…
Out of Scope Changes check ✅ Passed The production and test changes remain within the linked issue scope [#19240]. The audit expectation update, catalog-fetch module, relay status propagation, diagnostics, UI display, and related tests …
Full details: Description check

Explanation

The description explains the problem, implementation, and verification, but it omits required template sections and information, including ELI5, What Changed, Linked Issue with Fixes #, Visual Proof or N/A with a reason, checklist state, AI Disclosure, Review, and Notes.

  • 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: a2d98ee9-107b-40b4-b36a-32f8e24d5214

📥 Commits

Reviewing files that changed from the base of the PR and between 33af0af and 4e8586a.

📒 Files selected for processing (22)
  • src/main/global-fetch-call-site-audit.test.ts
  • src/main/ipc/mobile.test.ts
  • src/main/ipc/mobile.ts
  • src/main/runtime/relay/desktop-relay-service.ts
  • src/main/runtime/relay/relay-auth-coordinator.test.ts
  • src/main/runtime/relay/relay-auth-coordinator.ts
  • src/main/runtime/relay/relay-region-catalog-fetch.ts
  • src/main/runtime/relay/relay-region-preference.ts
  • src/main/runtime/relay/relay-region-probe-log.test.ts
  • src/main/runtime/relay/relay-region-probe-log.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
  • src/main/startup/main-process-runtime-launch.ts
  • src/main/startup/main-process-state.ts
  • src/preload/api/mobile-api.ts
  • src/preload/api/mobile-bridge.ts
  • src/renderer/src/components/settings/MobilePairingConnectionOptions.test.tsx
  • src/renderer/src/components/settings/MobilePairingConnectionOptions.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/shared/mobile-relay-status.ts

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

@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

  • Self-heal catalog-failure reporting — invalidateIfAssignedCellIsFar hoists its log outcome (defaulting to reason: 'catalog-unavailable') and passes an onCatalogFailure callback into probeCatalog, so a director that cannot list its regions is now reported under relay_region_self_heal before the throw instead of staying silent.
  • probeCatalog cleanup — fetchRelayRegionCatalog is inlined and the now-dead private fetchCatalog wrapper is removed.
  • Reason union + test — the self-heal reason union gains catalog-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).

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

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

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 win

Emit the self-heal event when cache removal fails.

If rmSync throws, control reaches the outer catch before this.logSelfHeal(outcome). The cache remains active, and selfHealedCells prevents another attempt for that cell. Catch the removal error locally and log the outcome with decision: '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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e8586a and 1fe72cf.

📒 Files selected for processing (4)
  • src/main/runtime/relay/relay-region-preference.test.ts
  • src/main/runtime/relay/relay-region-preference.ts
  • src/main/runtime/relay/relay-region-probe-log.test.ts
  • src/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.

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