Skip to content

fix(relay): refuse silent fallback when pairing invite fails - #11528

Merged
AmethystLiang merged 3 commits into
mainfrom
orca-relay-qr-code-confusing
Jul 30, 2026
Merged

AmethystLiang merged 3 commits into
mainfrom
orca-relay-qr-code-confusing

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

When Orca Relay pairing invite minting fails, the system previously silently fell back to a local-only (LAN) code while still labeling it as Relay. This masked the actual limitation from the user. The fix refuses that silent degradation and surfaces structured failure information to the UI, letting the user choose: Use LAN, Retry Relay, or copy diagnostics.

Changes

  • Server-side refusal: createMobilePairingOffer no longer returns a LAN-only QR when Relay provisioning fails under Anywhere mode; returns available: false with structured relayFailure instead
  • Device registry durability: Persist before in-memory swap to prevent state divergence on write failure
  • Relay revoke outbox durability: Persist to disk before adding to memory so failed writes don't leak device credentials
  • Structured failures: New MobileRelayMintFailure type with stage and code for diagnostics (redacts free-form error messages via regex)
  • UI recovery flows: "Use LAN", "Retry Relay" (with rotation), "Copy diagnostics" in pairing flow and settings
  • Concurrent mint coalescing: Multiple simultaneous mints for the same device reuse the same request; newer different-address requests supersede older ones

Screenshots

When Relay succeeds: no visual change.

When Relay fails:

  • Failure notice with icon, title ("Couldn't create a Relay pairing code"), and body text
  • Empty QR frame with explanatory placeholder text
  • Buttons: "Use LAN" (immediately available), "Retry Relay" (disabled while retrying, shows spinner), "Copy diagnostics"
  • All three options work from both mobile and settings panes

Testing

  • ✅ pnpm lint / oxfmt --check
  • ✅ pnpm typecheck
  • ✅ pnpm test — 21 new / updated tests covering:
    • Relay mint failure surfaces structured error
    • Provider unavailable (not installed)
    • Binding persistence throws (revokes and clears)
    • Provider replaced during mint (revokes result)
    • Concurrent mints coalesce for same device
    • Different-address concurrent mints supersede (older fails, newer wins)
    • LAN can supersede pending Relay without waiting
    • Device registry and revoke outbox durability on write failure
    • UI failure notice rendering, retry flow, LAN recovery
    • Focus restoration after recovery succeeds
  • ✅ pnpm build
  • Cross-platform: No shortcuts, paths, or shell behavior changes; uses existing IPC and UI patterns

AI Review Report

Code review completed. Main checks:

  • Durability: Device registry and revoke outbox now persist to disk before memory swap, preventing state divergence if writes fail
  • Concurrency: Mint requests coalesce by device; newer requests with different addresses supersede older ones, with proper cleanup of stale relay credentials
  • Error handling: Relay failures are caught, validated (machine-readable codes extracted via regex), and surfaced with user-friendly guidance
  • Cross-platform: No platform-specific behavior introduced; reuses existing IPC and UI infrastructure
  • Security: Relay codes validated by regex; free-form error messages redacted in structured output; no new injection surfaces

Security Audit

  • Input validation: Relay codes matched against ^relay_[a-z0-9_]{1,74}$ to block free-form error leaks
  • IPC: New fields (relayFailure, reason, guidance) typed and validated in preload/api-types
  • Error handling: Failures logged at warn/error level; no secrets exposed in diagnostics object (included in structured JSON when user explicitly copies)
  • No new auth or credential handling paths

Notes

  • Relay mints now take two serial paths: LAN (fast path, no Relay provider call) vs Anywhere (checks provider, calls createPairingRelay, validates binding, persists)
  • When a rotation is requested mid-retry, stale Relay credentials are queued for cloud cleanup
  • Settings and mobile hero flows share the same failure notice component for consistency
  • Focus management: when recovery completes, focus moves to the copy-pairing-code button (or stays on a persistent control if focus wasn't on document.body)

When Orca Relay pairing fails, don't silently degrade to a LAN-only QR under the Relay label. Instead, surface structured failure information so the UI can clearly inform the user and offer recovery options.
@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c88d974c-3062-46b8-9ccb-b29d98b7fb35

📥 Commits

Reviewing files that changed from the base of the PR and between e6eccd8 and 05e3a55.

📒 Files selected for processing (13)
  • src/main/runtime/device-registry.ts
  • src/main/runtime/runtime-rpc.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/renderer/src/assets/mobile-page.css
  • src/renderer/src/components/mobile/MobileHeroPairingStep.tsx
  • src/renderer/src/components/mobile/MobilePage.tsx
  • src/renderer/src/components/settings/MobilePairingQrSection.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/mobile-relay-mint-failure.test.ts

📝 Walkthrough

Walkthrough

The change introduces structured Mobile Relay mint-failure types and propagates them through runtime pairing, IPC, preload, and renderer layers. Relay offer generation now tracks concurrent requests, supersession, cleanup, and persistence failures. Device and revoke-outbox state is persisted before in-memory replacement. The mobile pairing UI adds failure notices, retry and LAN recovery actions, diagnostics copying, QR empty states, focus management, responsive scrolling, updated localization, and expanded integration and unit coverage.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: blocking the silent Relay-to-LAN fallback on pairing invite failure.
Description check ✅ Passed All required sections are present and the PR description covers the fix, testing, security, and notes; the AI review section could be more explicit about macOS/Linux/Windows.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
📝 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: 8

🧹 Nitpick comments (1)
src/shared/mobile-relay-mint-failure.test.ts (1)

4-34: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Consider covering the structured-error-object branch.

Both tests exercise the error instanceof Error path. The implementation also has a distinct branch for 'code' in error && typeof error.code === 'string' (structured error objects) which isn't exercised here. Since this function gates what diagnostic info reaches users/logs, adding a case like { code: 'relay_control_not_active' } (non-Error object) and a non-object error (e.g. null/string) would close the coverage gap on this security-sensitive redaction path.

✅ Suggested additional test cases
+  it('preserves known codes from structured error objects', () => {
+    expect(
+      mobileRelayMintFailureFromUnknown({
+        stage: 'create_pairing_relay',
+        error: { code: 'relay_control_not_active' },
+        fallbackCode: 'relay_mint_failed',
+        fallbackMessage: 'Relay pairing invite request failed'
+      })
+    ).toEqual({
+      code: 'relay_control_not_active',
+      stage: 'create_pairing_relay',
+      message: 'Relay pairing invite request failed'
+    })
+  })
+
+  it('falls back for non-object/non-Error error values', () => {
+    expect(
+      mobileRelayMintFailureFromUnknown({
+        stage: 'create_pairing_relay',
+        error: 'relay_control_not_active',
+        fallbackCode: 'relay_mint_failed',
+        fallbackMessage: 'Relay pairing invite request failed'
+      })
+    ).toEqual({
+      code: 'relay_mint_failed',
+      stage: 'create_pairing_relay',
+      message: 'Relay pairing invite request failed'
+    })
+  })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d7ed165-d110-4398-8949-81d3dd442b02

📥 Commits

Reviewing files that changed from the base of the PR and between d0d8695 and 7876707.

📒 Files selected for processing (30)
  • src/main/ipc/mobile.test.ts
  • src/main/ipc/mobile.ts
  • src/main/runtime/device-registry.ts
  • src/main/runtime/relay/relay-revoke-outbox.test.ts
  • src/main/runtime/relay/relay-revoke-outbox.ts
  • src/main/runtime/runtime-rpc.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/assets/mobile-page.css
  • src/renderer/src/components/mobile/MobileHero.test.tsx
  • src/renderer/src/components/mobile/MobileHero.tsx
  • src/renderer/src/components/mobile/MobileHeroPairingStep.tsx
  • src/renderer/src/components/mobile/MobilePage.test.tsx
  • src/renderer/src/components/mobile/MobilePage.tsx
  • src/renderer/src/components/mobile/MobilePageContent.tsx
  • src/renderer/src/components/mobile/mobile-relay-mint-failure-notice.tsx
  • src/renderer/src/components/mobile/use-mobile-pairing-generation.ts
  • src/renderer/src/components/mobile/use-mobile-pairing-qr-invalidation.ts
  • src/renderer/src/components/settings/MobilePairingConnectionOptions.test.tsx
  • src/renderer/src/components/settings/MobilePairingConnectionOptions.tsx
  • src/renderer/src/components/settings/MobilePairingQrSection.test.tsx
  • src/renderer/src/components/settings/MobilePairingQrSection.tsx
  • src/renderer/src/components/settings/MobilePairingSetupSection.test.tsx
  • src/renderer/src/components/settings/MobilePairingSetupSection.tsx
  • src/renderer/src/components/settings/MobilePane.test.tsx
  • src/renderer/src/components/settings/MobilePane.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/shared/mobile-relay-mint-failure.test.ts
  • src/shared/mobile-relay-mint-failure.ts

Comment thread src/main/runtime/runtime-rpc.ts Resolved
Comment thread src/main/runtime/runtime-rpc.ts Resolved
Comment thread src/main/runtime/runtime-rpc.ts Resolved
Comment thread src/main/runtime/runtime-rpc.ts Resolved
Comment thread src/renderer/src/assets/mobile-page.css Resolved
Comment thread src/main/runtime/runtime-rpc.ts Resolved
Comment thread src/main/runtime/runtime-rpc.ts Resolved
Comment thread src/main/runtime/runtime-rpc.ts Resolved
@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a silent degradation where Orca Relay pairing invite failures were masked by quietly falling back to a LAN-only QR code while still labeling it as Relay. The fix refuses that degradation, surfaces structured MobileRelayMintFailure data to the UI, and provides user-recoverable flows (Use LAN, Retry Relay, Copy diagnostics).

  • Server-side: createMobilePairingOffer now returns available: false with relayFailure instead of a silently downgraded LAN QR; device registry and revoke outbox both adopt persist-before-swap durability; concurrent mint requests are coalesced via a generation-based queue.
  • UI: New MobileRelayMintFailureNotice component shared between the mobile hero flow and the settings pane; MobileHeroPairingStep extracted as a new component; MobilePairingConnectionOptions gains disabled/retrying states.
  • Shared: New MobileRelayMintFailure type and mobileRelayMintFailureFromUnknown helper that validates error codes against a regex and redacts free-form error messages.

Confidence Score: 4/5

Safe to merge after addressing the selectedAddress disclosure in the Settings pane diagnostics payload; all core logic is well-guarded and tested.

The concurrency, durability, and fail-closed relay logic are carefully implemented and covered by 21 new tests. One concrete data inconsistency exists: the settings-pane Copy diagnostics path includes the user LAN IP or Tailscale hostname in the clipboard JSON, while the mobile hero flow deliberately removes it to prevent that disclosure.

Files Needing Attention: src/renderer/src/components/settings/MobilePane.tsx — copyRelayDiagnostics includes selectedAddress

Important Files Changed

Filename Overview
src/main/runtime/runtime-rpc.ts Major rework of createMobilePairingOffer: adds generation-based concurrency queue, fail-closed relay logic, discardPendingMobilePairingDevice, queueOrRetainRelayDeviceRevoke, and queueRelayDeviceRevoke now returns bool
src/main/runtime/device-registry.ts All mutating methods updated to persist-before-swap, addressing the previously flagged updateLastSeen gap; save() now requires explicit argument
src/main/runtime/relay/relay-revoke-outbox.ts enqueue and removeItem both updated to persist-before-swap; save() takes explicit items arg
src/shared/mobile-relay-mint-failure.ts New file; mobileRelayMintFailureFromUnknown correctly validates error codes via regex and redacts free-form messages
src/renderer/src/components/settings/MobilePane.tsx copyRelayDiagnostics includes selectedAddress which the parallel MobilePage.tsx flow explicitly excludes for privacy
src/renderer/src/components/mobile/MobilePage.tsx Replaces encodedConnectionMode with relayMintFailure; copyRelayDiagnostics deliberately excludes selectedAddress with an inline privacy comment
src/renderer/src/components/mobile/mobile-relay-mint-failure-notice.tsx New component; 200ms spinner delay avoids flash; role/aria-live toggled between alert and status based on busy state
src/renderer/src/components/mobile/MobileHeroPairingStep.tsx New component extracted from MobileHero; focus management useEffect correctly initializes pairingWasReadyRef from current props
src/renderer/src/components/settings/MobilePairingConnectionOptions.tsx Adds relayMintFailed/relayMintRetrying props; arrow-key guard and tabIndex shifts correct under disabled state
src/preload/api-types.ts available:false shape extended with optional reason, guidance, and relayFailure fields

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[createMobilePairingOffer] --> B{connectionMode == local-only?}
    B -->|yes| C[Increment generation / Run serial directly]
    B -->|no| D{Matches in-flight coalesce condition?}
    D -->|yes| E[Return existing in-flight request]
    D -->|no| F[Increment generation / Enqueue to serial queue]
    C & F --> G[createMobilePairingOfferSerial]
    G --> H[setMobilePairingConnectionMode]
    H -->|throws/false| I[discardPendingMobilePairingDevice / return device_registry_unavailable]
    H -->|local-only| J[Return LAN offer]
    H -->|automatic| K{relayProvider available?}
    K -->|no| L[refuseAutomaticWithoutRelay]
    K -->|yes| M[createPairingRelay]
    M -->|throws| N[mobileRelayMintFailureFromUnknown / refuseAutomaticWithoutRelay]
    M -->|ok| O{Generation still current? token match?}
    O -->|no| P[queueOrRetainRelayDeviceRevoke / return superseded]
    O -->|yes| Q[setMobileRelayBinding]
    Q -->|throws/false| R[queueOrRetainRelayDeviceRevoke / refuseAutomaticWithoutRelay]
    Q -->|ok| S[Return Relay offer with encoded relay URL]
Loading

Reviews (2): Last reviewed commit: "fix issues" | Re-trigger Greptile

@AmethystLiang
AmethystLiang merged commit 9eede00 into main Jul 30, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…i#11528)

* fix(relay): refuse silent fallback when pairing invite fails

When Orca Relay pairing fails, don't silently degrade to a LAN-only QR under the Relay label. Instead, surface structured failure information so the UI can clearly inform the user and offer recovery options.

* fix issues
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