Skip to content

fix(relay): revive a dead relay broker without user interaction - #12432

Merged
Jinwoo-H merged 1 commit into
mainfrom
fix/desktop-relay-liveness-reconcile
Aug 4, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
fix/desktop-relay-liveness-reconcile

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Follow-up from the relay incident handoff: "the desktop still gives up permanently after its launch burst (no periodic broker retry — needs an orca-repo fix)".

The gap

The coordinator retries open failures (transient HTTP/network, honoring Retry-After, 5min-capped jitter — #10147/#12076) and the origin pool retries drain/close recovery indefinitely. But two death paths end with broker.closeNow() and no timer:

  1. refreshAuthorization() failing past expiry + 60s — the normal outcome of a laptop sleeping through relay-token expiry (relay-session-broker.ts).
  2. refreshAccessToken() returning null on a transient auth-context read.

After that, only an external event (auth mutation, demand change, user Retry) ever calls reconcile() — a desktop that slept overnight stays offline until poked. This is the D7 follow-up from the incident review.

The fix

  • RelayAuthCoordinator.ensureLive(): a guarded reconcile that no-ops when there is a live broker (isLive?.() ?? true), a scheduled retry timer, or an open in flight — so it can never disturb the existing retry machinery or add Director load while recovery is already running. It reconciles with resetRetry=false, preserving backoff escalation.
  • DesktopRelayService: 5-minute setInterval liveness tick (cleared on stop()), plus a public ensureLive().
  • index.ts: powerMonitor.on('resume', …) — sleep is the common trigger, so resume gets an immediate check instead of waiting up to 5 minutes.

Load: when registered, the tick costs one isLive() call (no I/O). When dead, one reconcile per 5 minutes worst case, still gated by the coordinator's own Retry-After handling — negligible next to the current retry cohort behavior.

Tests

  • ensureLive reopens a broker that died with no pending retry (closes the dead broker, activates the replacement)
  • ensureLive no-ops against: a scheduled Retry-After timer, an open in flight, and a live broker
  • all pre-existing coordinator/service tests unchanged and green (29 total)

Broker deaths that end with closeNow() — an auth refresh failing past
token expiry (laptop sleep) or a transient context read at open — left
no retry timer, so Relay stayed offline until the user clicked Retry or
auth state changed. Adds a dead-man's switch:

- RelayAuthCoordinator.ensureLive(): reconciles only when there is no
  live broker, no scheduled retry, and no open in flight
- DesktopRelayService arms a 5-minute liveness interval and exposes
  ensureLive() for wake signals
- powerMonitor 'resume' triggers ensureLive (sleep is the common cause)
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 27bdf06e-c93c-4eb7-a11b-3c3453dbc3df

📥 Commits

Reviewing files that changed from the base of the PR and between e43bd6c and 021377b.

📒 Files selected for processing (4)
  • src/main/index.ts
  • src/main/runtime/relay/desktop-relay-service.ts
  • src/main/runtime/relay/relay-auth-coordinator-recovery.test.ts
  • src/main/runtime/relay/relay-auth-coordinator.ts

📝 Walkthrough

Walkthrough

The relay coordinator now exposes ensureLive() to recover missing or dead brokers without disrupting active recovery state. DesktopRelayService runs this check every five minutes and clears the timer during shutdown. Electron system-resume events also trigger the service check. Tests cover dead broker replacement and behavior during scheduled retries, in-flight openings, and live broker ownership.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and tests, but it omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add all required template sections, including visual-change status, completed test checks, AI review findings with cross-platform confirmation, security audit results, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: automatic recovery of dead relay brokers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 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.

@Jinwoo-H
Jinwoo-H merged commit 665b850 into main Aug 4, 2026
43 checks passed
@Jinwoo-H
Jinwoo-H deleted the fix/desktop-relay-liveness-reconcile branch August 4, 2026 06:23
Jinwoo-H added a commit that referenced this pull request Aug 4, 2026
The 5-minute liveness tick from #12432 survived fenceAndCloseNow(), so a
tick landing between the pre-sign-out fence and the profile wipe could
briefly resurrect a broker (benign but soft — the entitlement check
bails afterward). The fence now clears the interval; the next auth
mutation re-arms it via refreshDemand, and the safety net otherwise
behaves identically. Found in release review of the #12432 cherry-pick.

Co-authored-by: OrcaWin <[email protected]>
AmethystLiang pushed a commit that referenced this pull request Aug 4, 2026
Broker deaths that end with closeNow() — an auth refresh failing past
token expiry (laptop sleep) or a transient context read at open — left
no retry timer, so Relay stayed offline until the user clicked Retry or
auth state changed. Adds a dead-man's switch:

- RelayAuthCoordinator.ensureLive(): reconciles only when there is no
  live broker, no scheduled retry, and no open in flight
- DesktopRelayService arms a 5-minute liveness interval and exposes
  ensureLive() for wake signals
- powerMonitor 'resume' triggers ensureLive (sleep is the common cause)

Co-authored-by: OrcaWin <[email protected]>
AmethystLiang pushed a commit that referenced this pull request Aug 4, 2026
The 5-minute liveness tick from #12432 survived fenceAndCloseNow(), so a
tick landing between the pre-sign-out fence and the profile wipe could
briefly resurrect a broker (benign but soft — the entitlement check
bails afterward). The fence now clears the interval; the next auth
mutation re-arms it via refreshDemand, and the safety net otherwise
behaves identically. Found in release review of the #12432 cherry-pick.

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…lyai#12432)

Broker deaths that end with closeNow() — an auth refresh failing past
token expiry (laptop sleep) or a transient context read at open — left
no retry timer, so Relay stayed offline until the user clicked Retry or
auth state changed. Adds a dead-man's switch:

- RelayAuthCoordinator.ensureLive(): reconciles only when there is no
  live broker, no scheduled retry, and no open in flight
- DesktopRelayService arms a 5-minute liveness interval and exposes
  ensureLive() for wake signals
- powerMonitor 'resume' triggers ensureLive (sleep is the common cause)

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#12482)

The 5-minute liveness tick from stablyai#12432 survived fenceAndCloseNow(), so a
tick landing between the pre-sign-out fence and the profile wipe could
briefly resurrect a broker (benign but soft — the entitlement check
bails afterward). The fence now clears the interval; the next auth
mutation re-arms it via refreshDemand, and the safety net otherwise
behaves identically. Found in release review of the stablyai#12432 cherry-pick.

Co-authored-by: OrcaWin <[email protected]>
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.

2 participants