Skip to content

fix(relay): wait through a scheduled reconnect and name why Relay is not ready - #27141

Merged
OrcaWin merged 2 commits into
mainfrom
np/p395-relay-readiness-1a
Oct 10, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
np/p395-relay-readiness-1a

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​211 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​211
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​250 $\color{#cf222e}{\Huge{\mathbf{−}}}$​44 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​206

ELI5

When you ask the desktop for an "Anywhere" (Orca Relay) pairing code and Relay is not connected yet, Orca used to give up after one try and always show the same unhelpful code, relay_control_not_active, whatever actually went wrong. Now it waits a few seconds for the reconnect it already scheduled, and when it still cannot connect it says why: signed out, plan does not include Relay, rate limited, untrusted network certificate, director error, and so on.

What Changed

Before:

  • Opening the pairing page right after launch or wake often failed: the first broker connect hit a cold-start error, the coordinator scheduled a retry about a second later, but the mint request had already returned relay_control_not_active.
  • Signed out, not entitled, director 5xx, a 429, a TLS-inspecting proxy and a dead control socket all produced that same code, so the notice and copied diagnostics could not tell them apart.

After:

  • The relay auth coordinator records why its latest reconcile left no live broker (signed_out, not_entitled, rate_limited, director_assignment_503, tls_untrusted, connect_timeout, control_connect_timeout, ...). readiness() returns either the live broker or that reason plus when the scheduled retry is due.
  • waitForReadiness(waitMs) waits through a scheduled retry when it falls inside the caller's budget: 20 s for a desktop mint, 10 s for the phone's provisionRelay / getEndpoints (the phone gives these requests 30 s). The budget bounds every wait, including a retry that is still opening when time runs out, and a sign-out fence or service stop releases waiters at once; the shared reconnect keeps running for other callers. It never waits for signed out or not entitled (no retry is scheduled for them), and never shortens a director Retry-After (a retry past the budget returns at once with the cause).
  • The relay service throws RelayUnavailableError whose code is relay_<reason>. The existing mint-failure path already forwards any relay_* code, so the desktop notice and diagnostics now carry the real cause.
  • The notice shows "session expired / sign in" for relay_signed_out, a plan message for relay_not_entitled (both without a futile Retry), and "Relay is busy, wait a minute" for relay_rate_limited.

Mechanism: RelayRetrySchedule (shared since #27139) now exposes when its retry is due and a settled() promise that resolves when the retry runs or is cancelled. RelayReadinessWaiters races each wait against the caller's deadline and a fence signal, and disposes its timer on every exit. The error classifier lives in relay-readiness.ts; it reads RelayHttpError, undici's cause chain for certificate and timeout codes, and the existing relay_control_* error messages. Raw error text never reaches the code.

Why

The coordinator already knew both the cause and that a retry was seconds away; callers just could not see it. Making readiness an outcome instead of null fixes the cold-start race and the "every cause is one code" family in one place, instead of adding a retry loop to each caller (the approach of the open community PRs below, which this supersedes; thanks to their authors for the reports and test shapes).

Linked Issue

Fixes #19345
Fixes #19410

Part of #11714 (umbrella for relay_control_not_active; left open until the network fixes land) and #21187 (the provision timeout half; the stuck-journal half is a separate mobile fix).
Supersedes #19436, #22122 and #19659.

Visual Proof

The only UI change is copy in the existing Relay mint-failure notice for three new codes; covered by MobileHero.test.tsx. No layout change.

Testing

New relay-auth-coordinator-readiness.test.ts; on origin/main the first five fail; the deadline and fence-after-retry cases were added after review and fail on this PR's first revision (main rejects with relay_control_not_active, returns it for signed out and director 503, and has no classifier):

  • First broker open throws RelayHttpError(503), the retry a second later succeeds: createPairingRelay resolves.
  • Retry due after the wait budget (director Retry-After 60 s): mint code relay_director_assignment_503, returned without waiting.
  • No cloud session: relay_signed_out; unentitled: relay_not_entitled.
  • A fence while waiting resolves the waiter at once, both before the retry fires and (fence or stop) while the followed retry is still opening.
  • A retry that starts inside the budget but never finishes opening: the waiter returns at its deadline with the cause.
  • Classifier: certificate error in undici's cause chain → tls_untrusted; 429 and control close 4429 → rate_limited.

pnpm test src/main/runtime/relay src/main/runtime/runtime-rpc src/renderer/src/components/mobile src/renderer/src/components/settings/MobilePane.test.tsx (53 files), pnpm tc, oxlint, pnpm run check:code-quality:changed.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Builds on the refactor(relay): share one retry schedule and identity key #27139 refactor (merged).
  • Wire compatibility: no wire change. relayFailure.code was already free-form and regex-validated (/^relay_[a-z0-9_]{1,74}$/); every new reason fits it, and older renderers fall back to the generic notice.
  • SSH / folder workspaces / Windows: N/A, this is the desktop-to-cloud relay path.
  • A failing mint can now take up to 20 s instead of returning at once, only when a retry is actually scheduled inside that window; the UI already shows its generating state.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 788b606b-8618-4fc0-8479-9520c694737c






📥 Commits

Reviewing files that changed from the base of the PR and between a95006d and 53fe24b2832b8e23a5b65310074f0f6044afefa9.







📒 Files selected for processing (18)
  • src/main/runtime/relay/desktop-relay-service.test.ts
  • src/main/runtime/relay/desktop-relay-service.ts
  • src/main/runtime/relay/relay-auth-context.ts
  • src/main/runtime/relay/relay-auth-coordinator-readiness.test.ts
  • src/main/runtime/relay/relay-auth-coordinator-recovery.test.ts
  • src/main/runtime/relay/relay-auth-coordinator.test.ts
  • src/main/runtime/relay/relay-auth-coordinator.ts
  • src/main/runtime/relay/relay-auth-host-close-reason.test.ts
  • src/main/runtime/relay/relay-auth-identity.ts
  • src/main/runtime/relay/relay-drain-retry-schedule.ts
  • src/main/runtime/relay/relay-origin-pool.ts
  • src/main/runtime/relay/relay-pairing-authorization.ts
  • src/main/runtime/relay/relay-readiness.ts
  • src/main/runtime/relay/relay-retry-schedule.ts
  • src/main/runtime/relay/relay-session-broker.test.ts
  • src/main/runtime/relay/relay-session-broker.ts
  • src/renderer/src/components/mobile/MobileHero.test.tsx
  • src/renderer/src/components/mobile/mobile-relay-mint-failure-notice.tsx






💤 Files with no reviewable changes (1)
  • src/main/runtime/relay/relay-drain-retry-schedule.ts






Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.








📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The relay coordinator now tracks unavailable reasons and can wait for scheduled retries. The desktop relay service uses bounded readiness waits and returns classified failures. Shared relay identity and retry utilities replace duplicated implementations. The mobile relay notice displays distinct signed-out, not-entitled, and rate-limited messages, with tests for readiness and notice behavior.

















Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 53fe2

Relay pairing now waits through a scheduled reconnect and reports why Relay is not ready. No merge-blocking risk was identified in the supplied change.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check Warning For [#19345], DesktopRelayService.createPairingRelay() now waits up to 20 seconds through waitForReadiness(). Phone provisionRelay() and getEndpoints() wait up to 10 seconds. This addresses th… Add live Relay status and app version to the copied diagnostics payload required by [#19410]. Add automated coverage that verifies both fields are included with cause-specific mint failures.
Docstring Coverage Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check Passed The changes stay within the linked Relay pairing scope. The retry-schedule extraction, shared identity key, pairing-authorization move, readiness classifier, coordinator tests, and notice tests suppor…
Title check Passed The title clearly identifies the main changes: waiting through scheduled Relay reconnects and reporting why Relay is unavailable.
Description check Passed The description is mostly complete. It includes the ELI5 summary, user-visible changes, implementation details, rationale, linked issues, visual-proof explanation, testing details, compatibility notes…

Full details: Linked Issues check

Explanation

For [#19345], DesktopRelayService.createPairingRelay() now waits up to 20 seconds through waitForReadiness(). Phone provisionRelay() and getEndpoints() wait up to 10 seconds. This addresses the cold-start retry race. For [#19410], RelayUnavailableError and mobileRelayMintFailureFromUnknown() now preserve cause-specific relay_* codes, and the notice covers signed-out, not-entitled, and rate-limited cases. The copied diagnostics payload still has only code, stage, and message in MobileRelayMintFailure; this PR does not add live Relay status or app version.


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR






🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR











  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant