Repository navigation
fix(relay): emit pending-conn details to hosts that advertise the capability (cell side) - #19266
Conversation
…pability (cell 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, 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.
|
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 (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe relay contract adds host capability constants, header parsing, and optional pending-connection detail fields. The relay server passes parsed capabilities into control-session acceptance. The host session registry stores capabilities per socket and emits detailed pending-connection entries only for capable hosts. Tests cover schema validation, header parsing, legacy behavior, detailed behavior, and capability changes across control rebinds. Merge Risk: ⚪ Minimal · up to Capable relay hosts now receive pairing and device-binding details for pending connections, while hosts without the capability retain the existing acknowledgement format. The change is covered across the contract, upgrade, and session-rebind paths and is ready to merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
@coderabbitai the description-check finding was correct and is fixed: the body now follows the repo template in full. Rebutting the docstring-coverage warning rather than acting on it. This repository's
An 80% docstring threshold on the 8 functions this diff touches would mean restating signatures that already read clearly, which is the exact thing that rule forbids. The non-obvious parts here do carry comments, and each one states a reason rather than a description:
No change made for this check. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
fd -HI '^AGENTS\.md$' . -x sh -c '
echo "===== $1 ====="
rg -n -i -C 4 "Concise-Brief Non-obvious Comments ONLY|docstring|DO NOT: be verbose|BE CONCISE" "$1" || true
' sh {}Length of output: 1307
I withdraw the docstring-coverage finding. The repository-root 🐇 ✏️ Learnings added
You are interacting with an AI system. |
There was a problem hiding this comment.
ℹ️ No critical issues — one minor coverage observation inline.
Reviewed changes
The cell-side half of the pending-connection replay fix: the hello ack can now restate kind and relayDeviceId for a pending connection, but only to a host that advertised it can parse them.
- Capability advertisement — a new
x-orca-host-capabilitiesheader is parsed from the control upgrade and stored in a per-socketWeakMap, so the capability follows the socket rather than the session (correct across rebinds). - Gated ack emission —
sendHelloAckspreadskind/relayDeviceIdinto eachpendingConnsentry only when the receiving socket advertisedpending-conn-details; otherwise the entry is byte-identical to today's. - Backward-compatible contract —
PendingConnectionSchemagains two optional fields while staying.strict(), so a pre-details host still rejects an unannounced key but a post-details host accepts both shapes. - Tests — unit + contract coverage for the gating, the downgrade/upgrade across a rebind in both directions, strict-parse rejection of unannounced keys, and header literal pinning.
Verified locally: relay-contract 23 passed, relay 531 passed, both packages typecheck clean.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| identity, | ||
| controlUpgrade?.inclusionWatermark | ||
| controlUpgrade?.inclusionWatermark, | ||
| parseRelayHostCapabilities(request.headers[RELAY_HOST_CAPABILITIES_HEADER]) |
There was a problem hiding this comment.
The header → acceptControl wiring here is the one link with no test: parseRelayHostCapabilities is unit-tested, acceptControl/sendHelloAck gating is unit-tested, and the header/constant literals are pinned, but nothing asserts that a real control upgrade carrying x-orca-host-capabilities yields a detailed ack. A typo here (e.g. indexing a differently-spelled header) would pass the whole suite. Consider extending a relay.blackbox.test.ts control-upgrade case to send the header and assert the ack carries kind/relayDeviceId.
There was a problem hiding this comment.
Good catch, and correct: this was the one untested link. Fixed in 15ed777 rather than rebutted.
relay.blackbox.test.ts now drives a real control upgrade carrying x-orca-host-capabilities, creates an invite, connects a phone without ever attaching a data socket so the connection stays pending, then rebinds the control and asserts the ack. It rebinds twice: once with the header, once without.
- with the header:
pendingConnsis[{connId, connTicket, kind: 'invite', relayDeviceId: 'capability-device'}] - without it:
[{connId, connTicket}]
That covers the exact typo you described. Mutation-checked by renaming the header the server reads to x-orca-host-capability:
- "kind": "invite",
- "relayDeviceId": "capability-device",
Test Files 1 failed (1)
Tests 1 failed | 28 passed (29)
Reverted, and the full relay suite is green: 54 files, 532 passed, 95 skipped. pnpm typecheck clean.
There was a problem hiding this comment.
Correction to my previous reply: this PR merged at cf441ef, which is one commit before the test I described. The blackbox coverage is not on main.
Moved to #19274, which is test-only and based on current main. Same content, re-verified there:
npx vitest run src/relay.blackbox.test.ts— 29 passednpx vitest runinapps/relay— 54 files, 535 passed, 95 skippedpnpm typecheckclean
The mutation check still holds: renaming the header the server reads fails the new case and nothing else.
Nothing shipped in this PR is affected. The gap you identified is a silent one, so it is worth landing #19274 before the desktop half in #19238 goes out. Until then a mistyped header would leave the relay seeing no host as capable, always emitting the legacy ack, with no test failing.
…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.
…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.
…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.
…esktop side) (#19238) * fix(relay): attach a phone whose accept straddles a control rebind (desktop 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. * test(relay): pin the attach deadline the desktop mirrors by hand 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.

ELI5
A phone connecting through the relay is announced to your desktop exactly once. If your desktop's control connection happens to rotate at that moment, the announcement is lost and the phone sits there until it gives up. The relay already re-lists those waiting connections when the desktop reconnects, but it only says "connection 5, here's a ticket", which is not enough to actually pick it up. This teaches the relay to also say what kind of connection it is and which device it belongs to, but only to a desktop that first said it can understand those extra words.
What Changed
relay-contract: addedRELAY_HOST_CAPABILITIES_HEADER(x-orca-host-capabilities) and thepending-conn-detailstoken, plusparseRelayHostCapabilitiesto read the header off a control upgrade.PendingConnectionSchemagains optionalkindandrelayDeviceIdand stays.strict()otherwise.relay-server: parses the upgrade header and passes the capability set toacceptControl.host-session-registry: remembers the capability set in aWeakMapkeyed by the control socket, and includeskind/relayDeviceIdon eachpendingConnsentry ofhost-hello-ackonly when that socket advertised the capability.Keyed by socket, not by session, on purpose: a rebind can land a successor control whose decoder is older or newer than the one that opened the session, so the ack must follow the socket that will actually read it.
Split note: this is the cell half of #19238. The owner asked for the cloud change to land now and the desktop change to be reviewed separately. Deploy order is cell first anyway, so this PR is correct and mergeable on its own with no capable desktop in the fleet.
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 the mid-accept connections inpendingConns, but only byconnIdandconnTicket. That is not enough for a desktop to dial.kinddecides the pairing authority a connection carries andrelayDeviceIdis the E2EE device binding, so neither may be guessed.Why a capability rather than just adding the fields: a shipped host parses
pendingConnsentries strictly, so an unannounced key fails the whole ack parse and kills a control that was working. Why an upgrade header rather thanhost-hello:HostHelloSchemais strict on the cell too, so any new hello key is refused by every already-deployed cell.Linked Issue
N/A. Found while investigating relay connection latency, not filed as an issue.
Visual Proof
N/A— server-side wire behavior with no user-visible surface in this PR.Testing
Ran in
cloud/:apps/relay:npx vitest run src/host-session-registry.test.ts src/host-session-client-accept.test.ts— 2 files, 40 passed.packages/relay-contract:npx vitest run— 2 files, 23 passed.pnpm typecheckclean in both packages.test,build,terraform,Secret scanall pass on this branch.Backwards compatibility is the load-bearing claim and is tested directly. With no host advertising the capability the emitted entry is byte-identical to today's, because the optional keys are spread from an empty object, so key order and content are unchanged:
Four registry tests pin it: detailed shape to a capable socket, legacy shape to a socket that never advertised, and both directions of a rebind that changes the successor's advertisement. Latching the capability per session instead of per socket fails the last two.
AI Disclosure
Internal contributor.
Review
Reviewed by Pullfrog on the combined branch: no new issues. Its one informational note, that the desktop's hand-mirrored attach-deadline constant was not cross-pinned, is addressed on the desktop half; the cloud side already pins
hostAttachDeadlineMs: 10_000incontract.test.ts. CodeRabbit: no actionable comments, merge risk minimal.Agent skill upstream boundary
Notes
conn-openit observed. New plus new replays from the ack.WeakMapwrite per control accept, decays with the socket.x-orca-host-capabilitiesupgrade header. A stripped header degrades to the legacy path, so this PR is still safe, but it is worth one live probe against staging at deploy time before the desktop half ships.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)