Skip to content

fix(relay): emit pending-conn details to hosts that advertise the capability (cell side) - #19266

Merged
Jinwoo-H merged 1 commit into
mainfrom
relay/pending-conns-replay-cell
Sep 7, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
relay/pending-conns-replay-cell

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

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: added RELAY_HOST_CAPABILITIES_HEADER (x-orca-host-capabilities) and the pending-conn-details token, plus parseRelayHostCapabilities to read the header off a control upgrade. PendingConnectionSchema gains optional kind and relayDeviceId and stays .strict() otherwise.
  • relay-server: parses the upgrade header and passes the capability set to acceptControl.
  • host-session-registry: remembers the capability set in a WeakMap keyed by the control socket, and includes kind/relayDeviceId on each pendingConns entry of host-hello-ack only 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 closed HOST_OFFLINE even though the desktop is online. Desktop lease rotations happen fleet-wide in roughly 54-minute waves, so this recurs.

host-hello-ack already restates the mid-accept connections in pendingConns, but only by connId and connTicket. That is not enough for a desktop to dial. kind decides the pairing authority a connection carries and relayDeviceId is the E2EE device binding, so neither may be guessed.

Why a capability rather than just adding the fields: a shipped host parses pendingConns entries strictly, so an unannounced key fails the whole ack parse and kills a control that was working. Why an upgrade header rather than host-hello: HostHelloSchema is 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 typecheck clean in both packages.
  • CI test, build, terraform, Secret scan all 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:

legacy: {"connId":"c","connTicket":"t"}
now   : {"connId":"c","connTicket":"t"}

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.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

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_000 in contract.test.ts. CodeRabbit: no actionable comments, merge risk minimal.

Agent skill upstream boundary

  • Not applicable.

Notes

  • Security: the capability header only widens what the cell tells a host about that host's own pending connections. Tokens are trimmed, capped at 64 chars and 16 entries, so a hostile header cannot grow the set without bound.
  • Backwards compatibility: covered above. All three version mixes are safe. Old desktop plus new cell gets the legacy ack. New desktop plus old cell gets the legacy ack and falls back to the conn-open it observed. New plus new replays from the ack.
  • Cross-platform / SSH / mobile: cell-side only, no platform-dependent code.
  • Performance: one WeakMap write per control accept, decays with the socket.
  • Not proven from the repo: that the production external load balancer forwards the x-orca-host-capabilities upgrade 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

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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.
@coderabbitai

coderabbitai Bot commented Sep 7, 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: Team

Run ID: 52c2740c-155a-4c9f-bae4-d2c82d0ed0d9

📥 Commits

Reviewing files that changed from the base of the PR and between e068947 and cf441ef.

📒 Files selected for processing (5)
  • cloud/apps/relay/src/host-session-registry.test.ts
  • cloud/apps/relay/src/host-session-registry.ts
  • cloud/apps/relay/src/relay-server.ts
  • cloud/packages/relay-contract/src/contract.test.ts
  • cloud/packages/relay-contract/src/control-messages.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The 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 cf441

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise, specific, and accurately describes the main relay capability change.
Description check ✅ Passed The description is detailed and covers the change, rationale, compatibility, testing, and scope. The Linked Issue section is marked N/A even though the template requires an issue, but the rest of the …
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@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 AGENTS.md sets the opposite policy under Style / Concise-Brief Non-obvious Comments ONLY:

  • DO NOT: be verbose, explain the obvious, walk through the code ("WHY not HOW")
  • BE CONCISE. 1 LINE if possible

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:

  • control-messages.ts: why the capability rides the upgrade header instead of host-hello (HostHelloSchema is strict, so a new hello key is refused by every deployed cell), and why kind/relayDeviceId are optional.
  • host-session-registry.ts: why the capability is keyed by socket rather than by session (a rebind's successor may decode differently than the socket that opened the session), and why the ack withholds the fields from a host that did not advertise.

No change made for this check.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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


@Jinwoo-H The description fix is acknowledged.

I withdraw the docstring-coverage finding. The repository-root AGENTS.md requires concise comments for non-obvious rationale and prohibits explanations of obvious code. The existing comments document the relevant compatibility and socket-scoping decisions.

🐇


✏️ Learnings added
Learnt from: Jinwoo-H
URL: https://github.com/stablyai/orca/pull/19266

Timestamp: 2026-09-07T09:01:30.518Z
Learning: The repository-root `AGENTS.md` requires concise comments only for non-obvious rationale. Reviews should not require broad docstring coverage that restates clear function signatures; comments should explain relevant reasons rather than obvious implementation details.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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-capabilities header is parsed from the control upgrade and stored in a per-socket WeakMap, so the capability follows the socket rather than the session (correct across rebinds).
  • Gated ack emission — sendHelloAck spreads kind/relayDeviceId into each pendingConns entry only when the receiving socket advertised pending-conn-details; otherwise the entry is byte-identical to today's.
  • Backward-compatible contract — PendingConnectionSchema gains 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

identity,
controlUpgrade?.inclusionWatermark
controlUpgrade?.inclusionWatermark,
parseRelayHostCapabilities(request.headers[RELAY_HOST_CAPABILITIES_HEADER])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: pendingConns is [{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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 passed
  • npx vitest run in apps/relay — 54 files, 535 passed, 95 skipped
  • pnpm typecheck clean

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.

@Jinwoo-H
Jinwoo-H merged commit 91d7783 into main Sep 7, 2026
26 checks passed
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
…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.
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
…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.
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 7, 2026
…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.
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
…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.
Jinwoo-H added a commit that referenced this pull request Sep 7, 2026
…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.
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.

1 participant