You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(relay): wait through a scheduled reconnect and name why Relay is not ready - #27141
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).
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.
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)
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 | 3 | 2
❌ Failed checks (2 warnings)
Check name
Status
Explanation
Resolution
Linked Issues check
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
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
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
The title clearly identifies the main changes: waiting through scheduled Relay reconnects and reporting why Relay is unavailable.
Description check
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
relay_control_not_active.After:
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'sprovisionRelay/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 directorRetry-After(a retry past the budget returns at once with the cause).RelayUnavailableErrorwhose code isrelay_<reason>. The existing mint-failure path already forwards anyrelay_*code, so the desktop notice and diagnostics now carry the real cause.relay_signed_out, a plan message forrelay_not_entitled(both without a futile Retry), and "Relay is busy, wait a minute" forrelay_rate_limited.Mechanism:
RelayRetrySchedule(shared since #27139) now exposes when its retry is due and asettled()promise that resolves when the retry runs or is cancelled.RelayReadinessWaitersraces each wait against the caller's deadline and a fence signal, and disposes its timer on every exit. The error classifier lives inrelay-readiness.ts; it readsRelayHttpError, undici'scausechain for certificate and timeout codes, and the existingrelay_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
nullfixes 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; onorigin/mainthe first five fail; the deadline and fence-after-retry cases were added after review and fail on this PR's first revision (main rejects withrelay_control_not_active, returns it for signed out and director 503, and has no classifier):RelayHttpError(503), the retry a second later succeeds:createPairingRelayresolves.Retry-After60 s): mint coderelay_director_assignment_503, returned without waiting.relay_signed_out; unentitled:relay_not_entitled.causechain →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.AI Disclosure
Review
Agent skill upstream boundary
Notes
relayFailure.codewas 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.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)