Repository navigation
fix(relay): desktop control lifecycle — truthful registration, silence watchdog, named-check host proof - #12076
Conversation
- RelayControlOrigin.activate rejects controls whose socket closed before activation (hello-ack and close in one ws parser turn previously published a dead control with no recovery path) - RelayControlClient gains a 75s inbound-silence watchdog mirroring the relay's ping contract, so dead or server-side-unindexed sockets terminate and trigger origin recovery - RelayAuthCoordinator only republishes 'registered' when the owned broker proves a live control, and logs reconcile failures instead of swallowing them; the origin pool logs recovery-attempt failures - Host-proof validation reports the failing check by name (never values), keeping main's 30s skew bounds - isLive() plumbed client -> origin -> pool -> broker
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
📝 WalkthroughWalkthroughThe relay control client now validates control URLs, reports named host-proof failures, and monitors inbound silence with a watchdog. Relay origins and session brokers expose live-control state and reject controls that close before activation. The authentication coordinator detects non-live registered brokers, replaces them, and logs reconciliation failures. Tests cover handshake closure, challenge validation, silence timeouts, ping activity, activation failure, and dead-broker replacement. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
Greptile SummaryThis PR fixes three interconnected relay reliability bugs that caused a sustained HOST_OFFLINE incident on 2026-08-01: (1) a race where
Confidence Score: 4/5Safe to merge. All three incident-root-cause paths are directly addressed with targeted, well-scoped changes and red-before/green-after test coverage at every seam. The activation fence, silence watchdog, and isLive chain are all correctly implemented. The optional isLive field on CoordinatedRelayBroker defaults to 'live' for unknown implementations, which won't cause a regression but does leave the dead-broker replacement path silently disabled for any future broker that omits the method. The watchdog start() has no double-call guard. Both are style concerns with no current failure path, but they are worth addressing before the pattern proliferates. Files Needing Attention: relay-auth-coordinator.ts (optional isLive contract) and relay-control-silence-watchdog.ts (unguarded start()) would benefit from a follow-up tightening.
|
| Filename | Overview |
|---|---|
| src/main/runtime/relay/relay-control-origin.ts | Adds activation guard that rejects controls removed from the live set by a same-turn close event, and a hasLiveControl() delegation method. The fix is correct: the guard fires on !controls.has(control) (deleted by close handler) before activeControl is ever set, and the thrown error flows cleanly into existing retry paths. |
| src/main/runtime/relay/relay-control-silence-watchdog.ts | New file implementing a 75 s inbound-silence watchdog with 15 s check cadence. start()/stop() are correctly idempotent-safe; the timer is unref'd; onSilence calls terminate() which flows through handleClose into the standard recovery path. |
| src/main/runtime/relay/relay-control-client.ts | Integrates silence watchdog (start on activation, stop on close/closeNow), adds isLive() method, and enriches the challenge failure message with the named failing check. The watchdog stop in both closeNow() and handleClose() is intentional and idempotent; the double onClose() via deferred terminate() is pre-existing behaviour unchanged by this PR. |
| src/main/runtime/relay/relay-auth-coordinator.ts | Adds isLive? liveness gate before re-emitting registered, and adds console.warn on broker-reconcile failures. The optional isLive with ?? true default is safe (this.ownership.broker is never null when this.ownership is set), but the optional field makes the contract implicit. |
| src/main/runtime/relay/relay-host-proof.ts | Refactors the transcript validation from a short-circuit boolean chain to a named-check array that collects all failing checks. Semantically equivalent: null-guards on issuedAt are preserved per-check, the field count (16) pre-check is unchanged, and the named check strings include only relative time deltas, not absolute field values. |
| src/main/runtime/relay/relay-session-broker.ts | Adds isLive() delegating to pool.hasLiveControl(). Simple one-liner; correctly guards with !this.closed first. |
| src/main/runtime/relay/relay-control-url.ts | Pure extraction of controlWebSocketUrl from relay-control-client.ts into its own file. Zero logic changes. |
| src/main/runtime/relay/relay-control-client.test.ts | Adds a scripted-socket test suite covering close-before-activation, watchdog termination, clock-skew tolerance, and ping keep-alive with accurate fake-timer modelling. |
| src/main/runtime/relay/relay-session-broker.test.ts | Adds mock isLive and a test verifying close-before-activation propagates the correct error, never emits registered, emits offline, and stops the transport. |
| src/main/runtime/relay/relay-auth-coordinator.test.ts | Adds test verifying dead-broker replacement on reconcile rather than re-emitting registered. |
Reviews (1): Last reviewed commit: "fix(relay): make desktop control lifecyc..." | Re-trigger Greptile
| this.ownership.identityKey === nextIdentityKey && | ||
| // Why: registered must be provable; a broker whose control died without | ||
| // recovering falls through and is replaced instead of republished. | ||
| (this.ownership.broker?.isLive?.() ?? true) |
There was a problem hiding this comment.
isLive is optional but effectively required for correct behaviour
broker?.isLive?.() ?? true silently treats any broker that omits isLive as live, so the dead-broker replacement path is never triggered for those implementations. This is safe for RelaySessionBroker (which always defines isLive), but it means a future CoordinatedRelayBroker implementor who forgets the method will see registered emitted indefinitely with no visible failure. Upgrading isLive to a required field on CoordinatedRelayBroker would make the contract explicit and catch omissions at compile time.
| start(): void { | ||
| this.lastInboundAt = Date.now() | ||
| this.timer = setInterval(() => { | ||
| if (Date.now() - this.lastInboundAt > this.limitMs) { | ||
| this.stop() | ||
| this.onSilence() | ||
| } | ||
| }, CHECK_INTERVAL_MS) | ||
| this.timer.unref?.() |
There was a problem hiding this comment.
start() does not guard against double-calls
If start() were called a second time (e.g. via a future code path that forgets state-machine invariants), it would silently overwrite this.timer and orphan the previous interval, causing two concurrent watchdog timers. The current state machine in RelayControlClient makes this unreachable today, but a one-line guard would be cheap insurance: if (this.timer) return.
| const checks: [string, boolean][] = [ | ||
| ['issuedAt-readable', issuedAt !== null], | ||
| [ | ||
| `issuedAt-not-future(d=${issuedAt === null ? 'n/a' : issuedAt - now}ms)`, | ||
| issuedAt === null || issuedAt - RELAY_HOST_PROOF_CLOCK_SKEW_MS <= now | ||
| ], | ||
| [ | ||
| `not-expired(d=${challenge.expiresAt - now}ms)`, | ||
| now - RELAY_HOST_PROOF_CLOCK_SKEW_MS <= challenge.expiresAt | ||
| ], | ||
| ['issuedAt-before-expiry', issuedAt === null || issuedAt <= challenge.expiresAt], | ||
| [ | ||
| `window(w=${issuedAt === null ? 'n/a' : challenge.expiresAt - issuedAt}ms)`, | ||
| issuedAt === null || challenge.expiresAt - issuedAt <= MAX_HOST_PROOF_CHALLENGE_WINDOW_MS | ||
| ], |
There was a problem hiding this comment.
Check-name deltas are embedded in the WS close-frame reason
failProtocol(...) passes the reason string to socket.close(code, reason), which sends it to the relay server in the WebSocket close frame. Strings like issuedAt-not-future(d=1500ms) and not-expired(d=75000ms) therefore reach the server. This is intentional for incident diagnostics as documented in the PR, but it's worth confirming the relay server does not log or forward these reasons to any client-visible surface — if it does, the relative delta could help an attacker infer the server's clock.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…tablyai#12076) - RelayControlOrigin.activate rejects controls whose socket closed before activation (hello-ack and close in one ws parser turn previously published a dead control with no recovery path) - RelayControlClient gains a 75s inbound-silence watchdog mirroring the relay's ping contract, so dead or server-side-unindexed sockets terminate and trigger origin recovery - RelayAuthCoordinator only republishes 'registered' when the owned broker proves a live control, and logs reconcile failures instead of swallowing them; the origin pool logs recovery-attempt failures - Host-proof validation reports the failing check by name (never values), keeping main's 30s skew bounds - isLive() plumbed client -> origin -> pool -> broker Co-authored-by: OrcaWin <[email protected]>
Clean, relay-only replacement for #12060 (that branch's inherited history reverted unrelated main files; this branch is cut from main and contains exactly the relay changes).
Fixes the desktop half of the 2026-08-01 sustained Relay-only HOST_OFFLINE incident:
onClosebeforeactivate(); the dead control was promoted with no recovery path.RelayControlOrigin.activatenow rejects controls that closed before activation; failures flow into existing retry paths.RelayAuthCoordinatorrequiresbroker.isLive()(plumbed client → origin → pool → broker) before republishingregistered; dead brokers are replaced.Evidence: red-before/green-after tests at each seam; 66 relay tests pass; live Relay-only iOS repro went from a sustained
relay_outer_4404loop with a lyingregisteredbadge (zero sockets) to truthful status, autonomous recovery, and sustained real terminal round-trips. Cloud counterparts: orca-cloud#207/#208/#209 (activation fence + fleet image), #210 (clock-skew monitor), #211 (activation hardening).