Repository navigation
fix(relay): attach a phone whose accept straddles a control rebind (desktop side) - #19238
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe relay control protocol now advertises pending connection details and supports optional connection metadata. The control client accepts connection-open messages during draining. Relay control origins retain observed opens, reconstruct pending connections after rebinds, avoid duplicate dials, enforce attach deadlines, and release failed connections. Tests cover handshake capabilities, drain handoff, replay behavior, duplicate prevention, closure, and broker rebinds. Merge Risk: ⚪ Minimal · up to This change preserves phone attachment across desktop control rebinds while avoiding duplicate data connections and cleaning up failed replay attempts. No concrete current-head merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed ELI5, change, rationale, testing, compatibility, security, performance, and dependency information. However, the required Linked Issue section contains N/A, and the required checklist item for lint, typecheck, test, and build status is missing.
✨ 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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the accept-straddles-control-rebind fix across the cell (host-session-registry, relay-server, relay contract) and desktop (relay-control-client, relay-control-origin, protocol, transport, origin pool).
- Cell emits pending
kind/relayDeviceId—host-hello-acknow carries the reservation's pairing kind and device binding, but only when the control socket advertisedpending-conn-details; legacy sockets get the byte-identical old shape, pinned with exact equality. - Desktop replays pending connections on activation —
RelayControlOrigindials eachpendingConnsentry it isn't already serving, sourcingkind/relayDeviceIdfrom the ack or a rememberedconn-open(observedOpens, capped at 16), and skips entries with neither source. conn-openforwarded while draining — the client no longer dropsconn-openin thedrainingstate;markDraining/acceptingConnectionson the origin is removed, with the pool's drain deadline still bounding the origin's lifetime.- Capability negotiated over the upgrade header —
x-orca-host-capabilitiesis advertised on the control WebSocket upgrade and parsed server-side, keeping bothHostHelloSchemaand the legacyPendingConnectionSchemastrict-compatible across all three version mixes.
I traced the ownership lifecycle (onConnectionOwned/onConnectionReleased through basisOrigins), the rebind and migrate drain paths, and the hasConnection/socketsByConnectionId replay guard and found no correctness issue: double-dials are prevented, the drain deadline still closes a draining origin even when it owns a straddling connection, and the per-socket WeakMap decays with the socket. The tests pin exact ack shapes and replayed messages and are capable of failing.
ℹ️ The mirrored attach-deadline literal is not cross-pinned
RELAY_HOST_ATTACH_DEADLINE_MS (src/main/runtime/relay/relay-control-protocol.ts:40) hand-mirrors the cell's RELAY_PROTOCOL_LIMITS.hostAttachDeadlineMs (10_000). The capability header and token are pinned on both sides, but this constant has no desktop-side assertion, so a future cell-side change would silently drift the desktop's observedOpens eviction window and replayed attachDeadlineMs. It is low-stakes today because the replayed deadline is already best-effort, so no change is required — flagging only so the decision to leave it unpinned is a conscious one.
Technical details
# Mirrored deadline literal is unpinned on the desktop side
## Affected sites
- src/main/runtime/relay/relay-control-protocol.ts:40 — `RELAY_HOST_ATTACH_DEADLINE_MS = 10_000` mirrors cloud/packages/relay-contract/src/protocol-limits.ts:16
## Required outcome
- None required; informational only.
## Open questions for the human
- Want the same both-sides-pinned guarantee applied to this constant (a desktop-side value assertion), or is the best-effort framing acceptable?DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
8eb6b7d to
f0639a9
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the two test-only commits added since the prior review: a contract test pinning the capability header/token literals, and a rebind suite proving the ack follows the successor control socket's capability rather than the session.
- Pinned the capability header + token on the cloud side —
contract.test.tsassertsRELAY_HOST_CAPABILITIES_HEADERandRELAY_HOST_CAPABILITY_PENDING_CONN_DETAILSequal the literals the desktop mirrors by hand, closing the drift that would silently disable the feature. - Covered a rebind that changes the host's stated capability —
host-session-registry.test.tsadds downgrade/upgrade cases asserting thependingConnsack follows each socket's own advertisement (legacy shape for a successor that drops the capability, detailed shape when it adds it), and refactors the ack/session fixtures into shared helpers.
The rebind tests exercise acceptControl/activate through the real rebind path and assert exact ack shapes, so a session-latched capability (the mutation the commit message calls out) would fail them. The pin test fails on literal drift on either side. No correctness concerns in the delta; the production code is unchanged from the previously reviewed version.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
f0639a9 to
5ea2d46
Compare
…pability (cell side) (#19266) The cell announces a connection with a single conn-open. When the desktop's control socket dies mid-accept the phone waited out the 10s attach deadline and was closed HOST_OFFLINE, even though the desktop was online. host-hello-ack already restates those connections in pendingConns, but only by connId and connTicket, which is not enough for the desktop to dial: kind and relayDeviceId decide the pairing authority a connection carries and the E2EE device binding, so neither may be guessed. The cell now states kind and relayDeviceId on each pending entry, but only to a host that advertised it can read them: a shipped host parses those entries strictly, so an unannounced key fails the whole ack parse and kills a working control. The advertisement rides the control upgrade as x-orca-host-capabilities, not host-hello, because HostHelloSchema is strict on the cell too and any new hello key is refused by every already-deployed cell. The capability is keyed by socket, not by session: a rebind can land a successor whose decoder is older or newer than the one that opened the session, and the ack must follow the socket that will actually read it. With no capable host in the fleet the emitted ack is byte-identical to today's. The desktop half that consumes the new fields is #19238.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the incremental delta since the prior Pullfrog review: the PR was split into its desktop half (cell + contract changes moved to #19266, base retargeted to relay/pending-conns-replay-cell) and one new test commit.
- Split the PR into the desktop half — the cell/contract changes (
host-session-registry,relay-server, relay contract) moved to #19266. The five desktop production files (relay-control-client,relay-control-origin,relay-control-protocol,relay-origin-pool,relay-transport) are byte-identical to the previously reviewed version, so no production behavior changed. - Pinned
RELAY_HOST_ATTACH_DEADLINE_MSon the desktop side — a new test asserts the mirrored deadline literal is10_000, closing the prior informational note that this mirror was not cross-pinned while the capability header/token were. The pin is a real assertion and fails on desktop-side drift; the cell side is already pinned in the contract suite, so drift in either direction now fails a test.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the incremental delta since the prior Pullfrog review: a single test commit, plus the PR base retarget from the cell branch to main.
- Pinned
RELAY_HOST_ATTACH_DEADLINE_MSon the desktop side — a new test asserts the mirrored deadline literal is10_000, closing the prior informational note that this mirror was not cross-pinned while the capability header/token were. The pin is a real assertion and fails on desktop-side drift; the cell side is already pinned in the contract suite, so drift in either direction now fails a test.
No production code changed in this delta: the five desktop files and the cell-side files are byte-identical to the previously reviewed versions, and the retarget to main only re-lists the cell half (now also in #19266) in the diff without altering it.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
37279d4 to
e909655
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior Pullfrog review: #19266 (the cell + contract half) merged to main, and this branch was rebased onto main, dropping its cell-side commits.
- Cell half landed on
main— #19266 (91d7783f2b) now carrieshost-session-registry/relay-server/relay-contract, so the cell changes are no longer part of this PR's diff againstmain. - Desktop half unchanged — the five production files (
relay-control-client,relay-control-origin,relay-control-protocol,relay-origin-pool,relay-transport) and three test files are byte-identical (verified by blob hash) to the version reviewed and approved in the prior rounds. The rebase only re-hashed the two commits (fff8241c08→66eb1c6c50,37279d4cad→e909655a2f).
The dependency is now satisfied, so the PR is clean and mergeable. No correctness, wire-compat, or rollout concern surfaced in this delta.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…pability (cell side) (stablyai#19266) The cell announces a connection with a single conn-open. When the desktop's control socket dies mid-accept the phone waited out the 10s attach deadline and was closed HOST_OFFLINE, even though the desktop was online. host-hello-ack already restates those connections in pendingConns, but only by connId and connTicket, which is not enough for the desktop to dial: kind and relayDeviceId decide the pairing authority a connection carries and the E2EE device binding, so neither may be guessed. The cell now states kind and relayDeviceId on each pending entry, but only to a host that advertised it can read them: a shipped host parses those entries strictly, so an unannounced key fails the whole ack parse and kills a working control. The advertisement rides the control upgrade as x-orca-host-capabilities, not host-hello, because HostHelloSchema is strict on the cell too and any new hello key is refused by every already-deployed cell. The capability is keyed by socket, not by session: a rebind can land a successor whose decoder is older or newer than the one that opened the session, and the ack must follow the socket that will actually read it. With no capable host in the fleet the emitted ack is byte-identical to today's. The desktop half that consumes the new fields is stablyai#19238.
…esktop side) The cell announces a connection with a single conn-open. When the desktop's control socket dies mid-accept the phone waited out the 10s attach deadline and was closed HOST_OFFLINE, even though the desktop was online. host-hello-ack already restates those connections in pendingConns; the desktop parsed the field and threw it away. Desktop replays pendingConns on activation. It needs kind and relayDeviceId to dial: they decide the pairing authority a connection carries and the E2EE device binding, so neither may be guessed. Two sources, in order: - the ack entry, when the cell states them. This is the case where the desktop never received the conn-open at all, i.e. the headline scenario, and it needs the cell change in #19266. - the conn-open this process already saw, when the frame arrived but the data socket died with the control. Works against every deployed cell. An entry described by neither is skipped with a warning rather than dialed. Entries already spliced or already holding a data socket are skipped, so a rebind never double-dials. The desktop advertises x-orca-host-capabilities: pending-conn-details on the control upgrade so a cell knows the ack entries will be read. The header name and token are duplicated by hand because the desktop cannot import the relay contract; both sides assert the literals so drift fails a test rather than silently disabling the feature. Also stop dropping a conn-open that lands while the control is draining. A drain-only cell refuses new phones, so such a frame predates the drain and only that cell holds the waiting phone.
RELAY_HOST_ATTACH_DEADLINE_MS duplicates RELAY_PROTOCOL_LIMITS.hostAttachDeadlineMs, which the contract suite already pins to 10_000. Now that the cell and desktop halves land as separate PRs the two can drift independently, and drift would silently shorten both the observed-open eviction window and the deadline a replayed dial states, with nothing failing.
e909655 to
adcf659
Compare

ELI5
A phone connecting through the relay is announced to your desktop exactly once. If your desktop's control connection rotates at that moment, the announcement is lost and the phone sits there until it gives up, even though your desktop is online the whole time. The relay already re-lists those waiting connections when the desktop reconnects. Your desktop was reading that list and throwing it away. Now it picks them up.
What Changed
RelayControlOrigindials a data socket for eachpendingConnsentry it is not already serving. Entries already spliced, or already holding a data socket, are skipped, so a rebind never double-dials.kindandrelayDeviceIda dial needs come only from the relay, in this order: the ack entry when the cell states them (needs fix(relay): emit pending-conn details to hosts that advertise the capability (cell side) #19266), otherwise aconn-openthis process already observed.observedOpensis capped at 16, evicted past the attach deadline, and cleared on close. An entry described by neither source is skipped with a warning, never dialed with guessed values, becausekinddecides pairing authority andrelayDeviceIdis the E2EE device binding.conn-openis now forwarded while the control is draining.markDrainingon the origin is removed; the pool's drain deadline still bounds the origin.x-orca-host-capabilities: pending-conn-detailson the control WebSocket upgrade.CloudRelayTransport.hasConnectionexposes the already-open check the replay guard needs.The header name and token are duplicated by hand because the desktop cannot import the relay contract. Both sides assert the literals, so drift fails a test instead of silently disabling the feature. The same is now true of
RELAY_HOST_ATTACH_DEADLINE_MS, which mirrorsRELAY_PROTOCOL_LIMITS.hostAttachDeadlineMs.Why
The cell announces a connection with a single
conn-open. When the desktop's control socket dies mid-accept, the phone waits out the 10s attach deadline and is closedHOST_OFFLINEeven though the desktop is online. Desktop lease rotations happen fleet-wide in roughly 54-minute waves, so this recurs.host-hello-ackalready restates those connections inpendingConns. The desktop parsed the field and never acted on it, and separately dropped aconn-openthat arrived while the control was draining. A draining cell cannot start a new accept, so such a frame predates the drain and only that cell holds the waiting phone.Linked Issue
N/A. Found while investigating relay connection latency, not filed as an issue.
Visual Proof
N/A— transport-layer behavior with no rendered surface. The user-visible effect is a phone that attaches instead of timing out.Testing
pnpm vitest run src/main/runtime/relay src/main/runtime/rpc— 278 files, 2384 passed, 1 skipped.pnpm run check:code-quality:changed— 0 new findings across 7 changed files; type-aware 0; React Doctor 0.Cell-side suites and typecheck are verified on fix(relay): emit pending-conn details to hosts that advertise the capability (cell side) #19266.
Mutation checks: removing the replay kills 5 tests; latching the capability per session instead of per socket fails the rebind-downgrade test on the cell half.
Platforms: the changed code is platform-independent Node in the main process, exercised by the unit suites above. Not separately smoke-tested on Windows or Linux.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Internal contributor.
Review
Independent adversarial review, two rounds plus a nit round. Pullfrog: no new issues, one informational note that
RELAY_HOST_ATTACH_DEADLINE_MSwas not cross-pinned, now fixed with a test in this PR. CodeRabbit: no actionable comments.Agent skill upstream boundary
Notes
conn-open, which works against every deployed cell. New plus new replays from the ack. Deploy the cell first.kindorrelayDeviceId; an entry the relay did not describe is skipped rather than dialed with a guess.observedOpensis bounded at 16 entries with deadline-based eviction and is cleared on origin close.x-orca-host-capabilitiesupgrade header. A stripped header degrades to the observed-conn-openpath rather than failing. Worth one live probe against staging at deploy time.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)