Skip to content

feat(mobile): relay a paired phone's server-workspace requests through the desktop (hidden) - #26435

Merged
Jinwoo-H merged 14 commits into
mainfrom
feat/desktop-mobile-relay
Oct 11, 2026
Merged

Jinwoo-H merged 14 commits into
mainfrom
feat/desktop-mobile-relay

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1093 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1093
Prod 24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1248 $\color{#cf222e}{\Huge{\mathbf{−}}}$​287 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​961

ELI5

The desktop can now pass a phone's requests through to an Orca server the desktop is connected to,
signed in on that server as the phone itself. Nothing turns this on yet: phones don't send these
requests until the next change, which lets the phone show the server's workspaces.

Stacked on #26427, which lets the desktop register its phones on a server. Review only this
branch's own commits.

What Changed

Before: a phone paired with a desktop could only reach the desktop's own and SSH workspaces. The
remote Orca servers the desktop connects to as a client were out of reach.

After (hidden):

  • Routing. A phone request may name a target, executionHost: "runtime:<env>". The desktop checks
    the phone and its method allowlist as today, finds that configured server by exact id, and forwards the
    request.
    • With no target, or local / ssh:…, the request runs on the desktop exactly as before.
    • An unknown or unreachable server returns an error and never runs locally.
    • A targeted method that belongs to the desktop runs on the desktop, as if untargeted, so the routing table is read only here.
  • The routing table. MOBILE_RPC_METHOD_ROUTES tags every phone method execution-host or
    paired-desktop. A census test fails on any method that's untagged or stale.
  • Signed in as the phone. The first time a phone needs a server, the desktop calls
    pairing.delegatedMobileDevice.sync (feat(runtime): let a paired desktop register its phones as phone devices #26427) and keeps the returned tokens in memory only.
    • It syncs again when a phone is unpaired.
    • A server without that capability counts as "update needed", checked again on each new connection.
    • A token the server has revoked isn't retried until the next sync.
  • One connection per phone per server (src/shared/remote-runtime-passthrough-socket.ts).
    • It reuses the existing handshake, encryption, liveness and outbound-queue code, plus the shared
      opener, which now also takes binary frames.
    • It signs in with exactly the phone's capabilities, never the desktop's.
    • It closes when the phone disconnects or when the server is re-paired, removed or disconnected. Open
      requests get an error and are never replayed.
  • Generic frame handling.
    • Upstream, the phone's desktop token is replaced by its server token anywhere in the text frame.
    • Downstream, only terminal stream ids are renumbered (result.streamId and the binary terminal
      header), using the desktop's own counter so relayed streams never collide with local ones.
    • Everything else passes through untouched; the desktop never interprets replies. A census lists every
      stream-id carrier.
  • Shared opener frame cap. The shared remote-runtime WebSocket opener now caps incoming frames at
    8 MiB + 64 bytes for every caller. Two existing callers lacked it before.
  • Hidden. The relay capability isn't added to RUNTIME_CAPABILITIES, so phones never send a target.
    The next change turns it on with that one line.

Why

Each phone is an ordinary phone device on the server (#26427), so the server applies its existing phone
behaviour: terminal seats, query replies, clipboard ownership, chat limits and cleanup. The desktop
stays a dumb pipe. The token swap and stream-id renumbering are generic, so new server methods and fields
need no relay work.

Rejected alternatives:

  • rewriting ids inside replies, which would grow with every new server field;
  • relaying as the desktop itself, which collapses two phones into one client and loses phone behaviour.

Linked Issue

N/A (maintainer)

Visual Proof

N/A. Nothing user-visible until the next change.

Testing

  • Automated tests added/updated, or explained why not below

Integration (mobile-desktop-relay.integration.test.ts) runs a real server and a real desktop with
an encrypted phone client. It covers:

  • terminal subscribe with a binary snapshot, typing, and a query reply;
  • two phones on one server terminal;
  • cleanup when a phone disconnects;
  • unpairing a phone, which removes its server device;
  • a server revoke, then stop, then recovery on the next sync;
  • targeted desktop-only methods answered by the desktop exactly as untargeted;
  • an unknown target refused, with no local run;
  • local / ssh: targets running on the desktop;
  • update-needed, then recovery when the server gains the capability in place;
  • renumbering, checked against the server's raw stream ids.

Unit tests cover the frame rewrite, the stream-carrier and routing censuses, and the server lookup
adapter. Races: two phones racing the first sync run one sync; a server retired while its socket opens;
a phone leaving mid-sync. Also: a phone the server gives no token, oversized frames closing the socket,
and a failed capability forward ending the link.

Each protection was checked by breaking it on purpose, and its test fails. 48 tests pass across 9 files
on the reviewer's run; the lane's wider run over src/main/{ipc,runtime,startup} and src/shared had
29,701 pass, with one fish-shell test failing on that machine only.

Notes

  • Wire compatibility: an old phone sends no target and is unaffected. An old server lacks the sync
    capability and is reported as update-needed for relay. There's no new stream opcode.
  • Memory: bounded by phone connections × servers. Frames are capped at 8 MiB, and the phone socket's
    outbound queue closes the link on overflow.
  • Revokes: a server-side revoke of a relayed phone holds until the desktop's next sync.

…mobile devices

A desktop paired to this runtime can now call pairing.delegatedMobileDevice.sync to make each of
its phones an ordinary mobile-scope device it owns, so the phone mirrors that host through the
desktop. Children are never pending, inherit the parent's reach, and die with the parent's grant.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…atch

Dispatch binds the caller-bound delegated-device context, so the revoke path it needs now lives in
a layer under it as a pure move; this drops the abstract method seam. No behaviour change.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…oked

A failed child cleanup now leaves the parent in place so a retry can still find the children, and
revokeRuntimeAccess lives beside the revoke it cascades to. Adds restart, rename and bounds coverage,
shares credential minting, and drops the timing-dependent census.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…oked

Matches the parent revoke: a child whose cleanup could not be saved is kept and the sync errors
before minting anything, so the desktop retries instead of believing the server matches its list.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…h the desktop

A phone mirrors its desktop, including workspaces on the desktop's configured servers. The desktop
now forwards a request that names `executionHost: runtime:<env>` to that server over one socket per
(phone, server), signed in as the phone's delegated device; replies pass through untouched except
stream ids. Hidden until the phone client ships: the relay capability is not advertised yet.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…p-mobile-relay

Takes S1a's contract file verbatim (plural capability name) and moves the unpair re-sync into its
RuntimeRpcMobileDevices; the relay integration test now syncs against the real server.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
main dropped docs/reference, so the relay's contract lives beside the code. Also pins that a
server whose delegated sync fails (e.g. delegated_device_revoke_failed) is unavailable until a
later request syncs it again.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The production hosts adapter was only typechecked; this pins that it resolves configured servers
by exact id only (never a name or a removed server), fences by pairing revision and runtime
identity, and stops reporting retirements once unsubscribed.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Reuses the shared E2EE socket opener, folds relay state into fewer fields, never sends a request
whose link ended while opening, passes failure codes through, relays only this desktop's own
phones, and drops the unused host-state reader until S2 needs one.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Restores the 8 MiB frame cap on every remote runtime socket, re-checks an update-needed server on
each new link so an in-place upgrade relays, answers a phone the server just declined without
syncing again, and ends a link whose mirrored capability update cannot be queued.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The phone tags every call on a workspace screen with its execution host, so a
paired-desktop method carrying `runtime:<env>` now runs locally instead of
failing 'forbidden'. The Mac stays the only reader of the routing table.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
Under the bun vitest project, `ws` resolves to Bun's built-in client, which
ignores maxPayload, so the frame-cap test hung. The opener only ships on
Node/Electron, so run its test in the Node runtime project like its siblings.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…able

Adding a phone method now takes one edit (its route). A server-targeted call on a
legacy non-E2EE socket is refused instead of running locally, and only
execution-host methods enter the relay.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@Jinwoo-H
Jinwoo-H changed the base branch from feat/runtime-delegated-mobile-devices to main October 11, 2026 06:54
…elay

# Conflicts:
#	src/main/ipc/runtime-environments.ts
#	src/main/runtime/delegated-mobile-device.integration.test.ts
#	src/main/runtime/device-registry.ts
#	src/main/runtime/rpc/core.ts
#	src/main/runtime/rpc/dispatcher-stream-options.ts
#	src/main/runtime/rpc/methods/pairing.ts
#	src/main/runtime/rpc/rpc-streaming-dispatcher.ts
#	src/main/runtime/runtime-rpc/runtime-rpc-mobile-devices.ts
#	src/main/runtime/runtime-rpc/runtime-rpc-pairing.ts
#	src/main/runtime/runtime-rpc/runtime-rpc-state.ts
#	src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
#	src/shared/delegated-mobile-device-contract.ts
#	src/shared/protocol-version.ts
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

The change adds routing for mobile RPC requests to configured runtime environments through a desktop relay. The relay synchronizes delegated phone grants, opens authenticated encrypted connections, rewrites requests, and forwards text and binary replies with stream ID translation. Runtime setup, phone revocation, environment retirement, and connection closure are wired to relay cleanup. New tests cover routing, host resolution, transport limits, grant synchronization, and relay behavior.


Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 7b5f9

Phones can now have their requests to a configured server relayed through the desktop, but the feature stays hidden until phones are told the relay exists. One follow-up remains: under heavy concurrent traffic, such as large image uploads, the relay connection can drop because its send queue is sized for subscriptions. This is safe to merge, but the queue limits should be fixed before the relay is enabled for phones.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 32.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 33 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: relaying paired-phone server-workspace requests through the desktop.
Description check Passed The description is detailed and covers the user impact, routing behavior, design rationale, testing, compatibility, security, and visual-proof requirements. It omits the template's Review, Agent skill…
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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f5ee851-af2d-41c7-8de2-7b15b90f21f2
📥 Commits

Reviewing files that changed from the base of the PR and between 08c8d30 and 7b5f9dd.

📒 Files selected for processing (33)
  • config/scripts/vitest-node-runtime-files.mjs
  • src/main/ipc/runtime-environment-mobile-relay-hosts.test.ts
  • src/main/ipc/runtime-environment-mobile-relay-hosts.ts
  • src/main/ipc/runtime-environments.ts
  • src/main/runtime/mobile-desktop-relay/delegated-phone-grants.ts
  • src/main/runtime/mobile-desktop-relay/mobile-desktop-relay-hosts.ts
  • src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.integration.test.ts
  • src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.test.ts
  • src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.ts
  • src/main/runtime/mobile-desktop-relay/relayed-phone-frames.test.ts
  • src/main/runtime/mobile-desktop-relay/relayed-phone-frames.ts
  • src/main/runtime/mobile-desktop-relay/relayed-stream-carriers.test.ts
  • src/main/runtime/mobile-desktop-relay/relayed-stream-carriers.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/runtime-rpc-mobile-legacy-socket-relay-refusal.test.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-lifecycle.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-agent-session-methods.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-devices.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-allowlist.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.test.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-mobile-paired-desktop-methods.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-pairing.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-state.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
  • src/main/startup/main-process-runtime-launch-activation.test.ts
  • src/main/startup/main-process-runtime-launch.ts
  • src/shared/delegated-mobile-device-contract.ts
  • src/shared/mobile-desktop-relay-contract.ts
  • src/shared/remote-runtime-passthrough-socket.ts
  • src/shared/remote-runtime-request-websocket.test.ts
  • src/shared/remote-runtime-request-websocket.ts
  • src/shared/terminal-stream-protocol.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +167 to +170
send: (plaintext) =>
state === 'ready' && ws.readyState === WebSocket.OPEN
? outbound.enqueueRequest(ws, encrypt(plaintext, sharedKey))
: false,

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP 'SUBSCRIPTION_REQUEST_(SOFT_CAP_BYTES|MAX_QUEUED_BYTES|MAX_QUEUED_FRAMES)\s*=' -C2
rg -nP 'CHUNK_(BYTES|SIZE)|MAX_.*CHUNK' --type=ts -g '*clipboard*' -C2

Repository: stablyai/orca

Length of output: 706


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- passthrough socket send path ---'
nl -ba src/shared/remote-runtime-passthrough-socket.ts | sed -n '145,180p'
printf '%s\n' '--- outbound queue implementation ---'
nl -ba src/shared/remote-runtime-subscription-outbound.ts | sed -n '1,220p'
printf '%s\n' '--- relay and request-size references ---'
rg -n -F --glob '*.ts' -- 'openRemoteRuntimePassthroughSocket' src
rg -n -F --glob '*.ts' -- 'enqueueRequest' src
rg -n -F --glob '*.ts' -- 'clipboard.appendImageUploadChunk' src || true
rg -n -F --glob '*.ts' -- 'terminal.send' src || true
rg -n -i --glob '*.ts' -- 'chunk' src/shared src/main src/mobile | head -200 || true

Repository: stablyai/orca

Length of output: 41543


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- passthrough socket setup ---'
nl -ba src/shared/remote-runtime-passthrough-socket.ts | sed -n '1,190p'
printf '%s\n' '--- queue behavior ---'
nl -ba src/shared/ws-outbound-backpressure-queue.ts | sed -n '1,280p'
printf '%s\n' '--- relay call site and lifecycle ---'
nl -ba src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.ts | sed -n '180,255p'
printf '%s\n' '--- request schemas and relay allowlist ---'
nl -ba src/shared/rpc-contract/clipboard-params.ts | sed -n '1,90p'
nl -ba src/shared/rpc-contract/terminal-params.ts | sed -n '1,180p' 2>/dev/null || true
nl -ba src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-routing.ts | sed -n '1,80p'
printf '%s\n' '--- focused relay tests ---'
rg -n -F --glob '*mobile-desktop-relay*' -- 'overflow' src/main/runtime/mobile-desktop-relay src || true
rg -n -F --glob '*mobile-desktop-relay*' -- 'appendImageUploadChunk' src/main/runtime/mobile-desktop-relay src || true

Repository: stablyai/orca

Length of output: 27915


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- remaining queue enqueue logic ---'
nl -ba src/shared/ws-outbound-backpressure-queue.ts | sed -n '268,390p'
printf '%s\n' '--- relay link forwarding ---'
rg -n -F --glob '*.ts' -- 'class RelayLink' src/main/runtime/mobile-desktop-relay
rg -n -F --glob '*.ts' -- 'socket.send' src/main/runtime/mobile-desktop-relay
nl -ba src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.ts | sed -n '1,190p'
printf '%s\n' '--- clipboard upload producer ---'
nl -ba src/main/window/clipboard-runtime-image-upload.ts | sed -n '1,180p'
printf '%s\n' '--- serialization and encryption sizes ---'
nl -ba src/shared/remote-runtime-memory-limits.ts | sed -n '1,180p'
nl -ba src/shared/e2ee-crypto.ts | sed -n '1,180p'

Repository: stablyai/orca

Length of output: 23067


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- relay callers and target guards ---'
rg -n -F --glob '*.ts' -- 'relay.forward' src/main src/shared
rg -n -F --glob '*.ts' -- 'forward(phone' src/main
rg -n -i --glob '*.ts' -- 'executionHost' src/main/runtime src/main | head -120 || true
printf '%s\n' '--- relay capability advertisement ---'
rg -n -F --glob '*.ts' -- 'MOBILE_DESKTOP_RELAY_RUNTIME_CAPABILITY' src
rg -n -F --glob '*.ts' -- 'RUNTIME_CAPABILITIES' src/main src/shared
printf '%s\n' '--- runtime request bounds ---'
rg -n -F --glob '*.ts' -- 'REMOTE_RUNTIME_MAX_PENDING_REQUESTS' src
rg -n -F --glob '*.ts' -- 'REMOTE_RUNTIME_MAX_PENDING_RPC_BYTES' src

Repository: stablyai/orca

Length of output: 33543


Use relay-specific outbound queue limits.

When the host socket is backpressured, RelayLink.forward queues every relayed request in the subscription request queue. A valid clipboard.appendImageUploadChunk request can contain 512 KiB of base64 data. After E2EE base64 encoding, 24 such queued frames exceed the 16 MiB limit. Queue overflow ends the relay with remote_runtime_unavailable.

Configure the passthrough socket with limits derived from the supported relayed RPC and frame budgets instead of the subscription queue limits. The relay capability is currently hidden, but this path can fail when concurrent phone requests are enabled.

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