Repository navigation
fix(relay): desktop control lifecycle — truthful registration, skew tolerance, silence watchdog - #12060
fix(relay): desktop control lifecycle — truthful registration, skew tolerance, silence watchdog#12060Jinwoo-H wants to merge 5 commits into
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; dead brokers are replaced instead - isLive() plumbed client -> origin -> pool -> broker
- Host-challenge freshness gets a 2s leeway on both edges: a cell whose clock ran ~100ms ahead deterministically failed every control activation under the zero-tolerance issuedAt check (challenges stay single-use and nonce-bound, so replay protection is intact) - answerRelayHostChallenge reports the failing check by name (never values) and the control client includes it plus the cell origin in the close reason - RelayAuthCoordinator warns on broker reconcile failures instead of swallowing them; silent failures made a dead relay look like standby
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe relay runtime adds control URL validation, silence monitoring, liveness reporting, and detailed host-proof failure reasons. It adds bounded HTTP 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
⚔️ Resolve 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/main/runtime/relay/relay-control-silence-watchdog.ts (1)
1-37: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winGuard
start()against a double start.
start()overwritesthis.timerwithout clearing an existing interval. The current client callsstart()once per socket, so no leak occurs today. A future second call would orphan a timer that later terminates a live socket.♻️ Proposed guard
start(): void { + this.stop() this.lastInboundAt = Date.now()src/main/runtime/relay/relay-drain-retry-schedule.ts (1)
14-29: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winAdd a minimum delay floor to the jitter.
jitterMsisfloor(random() * (capMs + 1)), so the delay can be 0 when the server sends noRetry-After. On the first attempts the cap is small (1s, 2s, 4s), so a low random value produces near-immediate retries against the director. Apply a floor, for example half the cap or a fixed minimum.♻️ Proposed change
- const jitterMs = Math.floor(this.random() * (capMs + 1)) + // Full jitter with a floor keeps early retries from hammering the director. + const jitterMs = Math.floor(capMs / 2 + this.random() * (capMs / 2 + 1))
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c0c4c087-9fe1-4cb7-9be4-f2d9c6565eb5
📒 Files selected for processing (16)
config/reliability-gates.jsoncsrc/main/runtime/relay/relay-auth-coordinator-recovery.test.tssrc/main/runtime/relay/relay-auth-coordinator.test.tssrc/main/runtime/relay/relay-auth-coordinator.tssrc/main/runtime/relay/relay-control-client.test.tssrc/main/runtime/relay/relay-control-client.tssrc/main/runtime/relay/relay-control-origin.tssrc/main/runtime/relay/relay-control-silence-watchdog.tssrc/main/runtime/relay/relay-control-url.tssrc/main/runtime/relay/relay-drain-retry-schedule.tssrc/main/runtime/relay/relay-host-proof.tssrc/main/runtime/relay/relay-http-client.test.tssrc/main/runtime/relay/relay-http-client.tssrc/main/runtime/relay/relay-origin-pool.tssrc/main/runtime/relay/relay-session-broker.test.tssrc/main/runtime/relay/relay-session-broker.ts
| /** Reports the failing check by name only; never receives field values. */ | ||
| onInvalid?: (reason: string) => void |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Align the onInvalid contract text with the emitted reasons.
The doc comment states the callback never receives field values. The reason strings embed computed values: d=<delta>ms and w=<window>ms. These are relative offsets, not absolute timestamps, so the privacy risk is low. Update the doc comment so the contract matches the emitted content, because relay-control-client.ts logs the reason verbatim in failProtocol.
♻️ Proposed doc change
- /** Reports the failing check by name only; never receives field values. */
+ /** Reports failing check names plus relative time offsets; never absolute timestamps or field values. */
onInvalid?: (reason: string) => voidAlso applies to: 111-125
Greptile SummaryThis PR fixes a sustained
Confidence Score: 5/5Safe to merge — the three concurrency defects are each fixed with tight, well-tested guards and no new error paths are left unhandled. All three named defects are addressed with before/after tests at each seam. The D1 guard correctly feeds into the existing retry loop, the silence watchdog start/stop is correctly paired with state transitions and unref'd, and the isLive chain threads cleanly from client to coordinator with optional-chaining backward compatibility. No correctness issues were found. Files Needing Attention: No files require special attention. The relay-host-proof.ts early-exit path still omits onInvalid for key/nonce decode failures (flagged in a prior review comment) but that is a pre-existing diagnostic gap, not a correctness regression from this PR.
|
| Filename | Overview |
|---|---|
| src/main/runtime/relay/relay-control-origin.ts | Adds hasLiveControl() delegation and the D1 guard in activate() that throws when the control closed before promotion; resource cleanup via this.controls and close() is correct for all error paths. |
| src/main/runtime/relay/relay-control-client.ts | Adds isLive(), wires the silence watchdog into connect/close lifecycle, and improves challenge-failure logging with onInvalid; watchdog start/stop is correctly paired with state transitions. |
| src/main/runtime/relay/relay-auth-coordinator.ts | D3 fix gates registered on broker.isLive?.() ?? true; optional chaining preserves backward compatibility with brokers that don't implement isLive; retry logging added for silent failures. |
| src/main/runtime/relay/relay-control-silence-watchdog.ts | New 75s watchdog mirrors relay's ping contract; unref() called on the interval so it doesn't block the Node process; stop() is idempotent and safe to call multiple times. |
| src/main/runtime/relay/relay-host-proof.ts | Replaces single boolean AND with named-check array for better diagnostics; onInvalid is called for transcript-structure, each named failing field, and challenge-box-open; early-exit path for decode failures still lacks onInvalid (pre-existing, covered in prior review comment). |
| src/main/runtime/relay/relay-session-broker.ts | Adds isLive() delegating through originPool.hasLiveControl(); included in CoordinatedRelayBroker contract via the coordinator type. |
| src/main/runtime/relay/relay-origin-pool.ts | Adds hasLiveControl() passthrough and a console.warn for silent retry-loop failures discovered during incident triage. |
| src/main/runtime/relay/relay-control-url.ts | Pure extraction of controlWebSocketUrl into its own module; logic is unchanged from original location in relay-control-client.ts. |
| src/main/runtime/relay/relay-control-client.test.ts | New scripted-socket test suite covers D1 (close-in-ack-turn), clock skew tolerance, silence watchdog timeout, and watchdog keepalive via pings; good coverage of the new lifecycle paths. |
| src/main/runtime/relay/relay-session-broker.test.ts | Adds isLive mock and a test confirming relay_control_closed_before_activation propagates correctly to the broker layer with the expected status sequence. |
| src/main/runtime/relay/relay-auth-coordinator.test.ts | New test verifies that a dead broker triggers replacement rather than a repeated registered emission, and that two connecting transitions are emitted during the swap. |
| src/main/ssh/ssh-connection.ts | Formatting-only change: reformatted a multi-line conditional to fit on a single line; no behavioral change. |
| src/relay/git-handler.ts | Two indentation/comment-alignment fixes only; no logic changes. |
Sequence Diagram
sequenceDiagram
participant Coord as RelayAuthCoordinator
participant Broker as RelaySessionBroker
participant Pool as RelayOriginPool
participant Origin as RelayControlOrigin
participant Client as RelayControlClient
participant WD as SilenceWatchdog
participant WS as WebSocket
Coord->>Broker: openBroker()
Broker->>Pool: openInitial()
Pool->>Origin: open()
Origin->>Client: connect()
Client->>WS: createSocket()
WS-->>Client: open
Client->>WS: send host-hello
WS-->>Client: host-challenge
Client->>WS: send host-challenge-ack
WS-->>Client: host-hello-ack + (maybe close, same parser turn)
Note over Client: state → active, WD.start()
Client-->>Origin: connectResolve(ack)
alt D1: close fired in same parser turn
WS-->>Client: close(1006)
Note over Client: state → closed, WD.stop()
Client->>Origin: onClose(1006)
Origin->>Origin: activate() throws relay_control_closed_before_activation
Origin-->>Pool: throw
Pool-->>Broker: throw
Broker-->>Coord: throw
Coord->>Coord: scheduleRetry()
else Normal activation
Origin->>Origin: activate() sets activeControl
Origin-->>Pool: open() resolves
Pool-->>Broker: openInitial() resolves
Broker-->>Coord: registered
loop D2: every 15s watchdog check
WD->>WD: "Date.now() - lastInboundAt > 75s?"
alt Silent for 75s
WD->>WS: terminate()
WS-->>Client: close(1006)
Client->>Origin: onClose
Origin->>Pool: onClose
Pool->>Pool: handleDrain recovery
else Ping received
WS-->>Client: ping message
Client->>WD: noteInbound()
end
end
Note over Coord: D3: on next reconcile
Coord->>Broker: isLive()?
Broker->>Pool: hasLiveControl()
Pool->>Origin: hasLiveControl()
Origin->>Client: isLive()
Client-->>Coord: true/false
alt broker not live
Coord->>Broker: closeNow()
Coord->>Coord: open new broker
else broker live
Coord->>Coord: emit registered
end
end
Reviews (3): Last reviewed commit: "Merge origin/main: adopt 30s host-proof ..." | Re-trigger Greptile
The pool's drain-retry loop ran silently during the 2026-08 incident while Director 503 throttling stretched recovery to minutes.
|
Superseded by the clean relay-only branch (see the replacement PR): this branch's inherited history deleted/reverted ~1.8k lines of unrelated main files, and merging it would have reverted that work. The relay changes are identical in the replacement. |
Fixes the desktop half of the sustained Relay-only HOST_OFFLINE incident.
Defects fixed
onClosebeforeactivate(); the dead control was then promoted toactiveControlwith no recovery path.RelayControlOrigin.activatenow rejects controls that closed before activation; open/rebind fail into existing retry paths.RelayAuthCoordinatorrepublishedregisteredfrom ownership validity alone on every reconcile. It now requiresbroker.isLive()(plumbed client → origin → pool → broker) and replaces dead brokers.Evidence
relay_outer_4404loop + desktop claimingregisteredwith zero sockets, to truthfulregisteredwith a live control and real terminal round-trips over the relay.Cloud-side counterpart: stablyai/orca-cloud#207 (activation fence, merged) + #208 (C9 canary image).