Skip to content

feat(remote): relay paired desktop and web clients to a server's managed hosts - #35195

Open
jutaz wants to merge 5 commits into
stablyai:mainfrom
jutaz:feat/runtime-client-relay
Open

jutaz wants to merge 5 commits into
stablyai:mainfrom
jutaz:feat/runtime-client-relay

Conversation

@jutaz

@jutaz jutaz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

ELI5

Your phone can already open a workspace on a server that your desktop manages, because the desktop passes the phone's requests through to that server. This PR teaches the desktop (or orca serve) to do the same for a paired desktop or web client, but only when that client asks for it and only after the server says it supports it. No UI changes here. A later PR makes the client use it.

What Changed

Topology: client (desktop/web, paired with runtime scope) → server A → managed server B, which A reaches as runtime:<env>.

  • New capability runtime.client-relay.v1 (src/shared/mobile-desktop-relay-contract.ts, next to mobile.desktop-relay.v1). It is not in RUNTIME_CAPABILITIES. A appends it to status.get only for an encrypted runtime-scope socket on a server that has relay host wiring (setMobileDesktopRelayHosts). That is the desktop; orcad has none. It is added at the same transport boundary that already stamps deviceScope, because the dispatcher has no connection context.

  • Admission (runtime-client-relay-admission.ts, called from runtime-rpc-websocket-dispatch.ts) applies only when A advertises the capability to that connection: an encrypted socket, a request whose authenticated device scope is runtime, and relay host wiring on A. It judges only an executionHost string starting with runtime:. Once a client names a server, the call never silently runs on A instead:

    • route execution-host → relayed through the existing relayMobileRequest path;
    • route paired-desktop → runs on A, the same deliberate rule phones get (settings, accounts, dictation and so on belong to the computer the client paired with);
    • anything else, e.g. files.write, files.delete, projectHostSetup.* and methods added later → forbidden, nothing runs on A. Phones get forbidden for the same input, from the mobile allowlist;
    • a runtime: value that does not parse (runtime:, runtime:a|b) → invalid_argument, as for phones.

    A relayed call must also pass denyRpcMethodForCaller with the client's own scope and grants, using the method's declared permission on A. B only sees a phone child, so this keeps a future execution-host method that needs desktop-control from being relayed by a client that was never granted it. From there it behaves exactly like a phone: unknown or non-relayable env (WSL excluded by the host resolver) → remote_runtime_unavailable with no local fallback; terminal.multiplex → forbidden; hosted browser pages are served locally; transport loss → remote_runtime_unavailable.

  • Everything else from a runtime client is unchanged. Untargeted calls and local/ssh: targets run on A as before. So does everything on unencrypted sockets and on servers without relay wiring, which do not advertise the capability. Old clients never send executionHost, so the new refusals only reach clients that read the capability. The phone path is untouched.

  • Replies stay opaque apart from stream-id renumbering, plus one reverse substitution: any occurrence of the caller's B token in a relayed text frame is replaced with the caller's own token on A. This guards against B echoing its caller, e.g. a driver-changed clientId. The substitution applies to phones as well.

  • Delegated devices on B reuse pairing.delegatedMobileDevice.sync unchanged. A tracks relaying runtime clients per server and adds one to a server's sync list only after hosts.resolve found that server, so a relay to X never mints a child on Y, and pairing alone mints nothing. In each server's list, phones come first so the 32-entry cap never drops a phone. Relaying clients follow: those with a live connection first, then by lastSeenAt, newest first. Web page loads mint ephemeral devices, so stale sessions lose the cap, not the client in use. The key is the client's device id on A and the name is <name> via <computer>. B mints an ordinary delegated child with scope mobile, which gets B's mobile allowlist (covers every execution-host route) and is refused pairing-admin. The token swap and envelope stripping (deviceToken, executionHost) are the existing rewriteRelayedPhoneRequest, so the client never receives B's token.

  • Revocation and pruning: revokeRuntimeAccess on A resyncs the relay when the revoked client had relayed. So does the idle-session sweep when it prunes a relaying ephemeral web device (new onDevicesPruned hook on MobileSocketWiring). The next sync omits the client and B revokes the child it minted (existing syncDelegatedMobileDevices). This runs in the relay's background resync, not in one transaction with A's local revoke. That matches unpairing a phone today.

  • Terminals are not covered yet. Desktop and web terminals use terminal.multiplex, which the relay refuses (forbidden). The relay also does not forward client→server binary frames (terminal input, resize, viewport claims). Until a follow-up adds binary forwarding behind its own capability, a desktop client cannot open an interactive terminal on a relayed host. JSON terminal.subscribe, terminal.send and terminal.list do relay.

Why

Issue #29396 asks for web/desktop clients to reach a paired server's managed hosts the way phones already can. Reusing the phone relay keeps one forwarding path, one token-rewrite path and one revocation path. The alternative was to have B mint a new child scope (e.g. runtime), which needs a new field or method on B and its own capability gate. That would be a mixed-version wire change on both A and B, and the existing mobile child scope already covers every method this relays. Mixed versions:

Client Server A Outcome
new new + relay wiring sees runtime.client-relay.v1; executionHost: runtime:<env> relays execution-host routes, keeps paired-desktop routes on A, refuses the rest
new old (or orcad) no capability → client must not send executionHost (later client PR gates on it)
old new old clients never send executionHost; behaviour identical
any new, B lacks pairing.delegated-mobile-devices.v1 remote_runtime_unavailable "needs an Orca update", nothing runs on A

Client-side note for the follow-up PR: A advertises the capability per connection, not per server. A client has to re-read status.get after every reconnect and must not cache the capability across connections. A reconnect can land on an unencrypted socket, or on a server whose relay wiring has gone away.

Linked Issue

Part of #29396 (also #26291 and #29593). This is the server side only; the client routing that lets a desktop or web client use it follows separately, so this does not close the issue yet.

Visual Proof

N/A: server-side RPC admission only, with no UI or interaction change. Nothing in the renderer sends executionHost yet.

Testing

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

Extended src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.integration.test.ts (real A and B RPC servers over E2EE WebSockets) by letting the phone helper pair a runtime-scope client:

  • status.get from a runtime client advertises runtime.client-relay.v1; the same call from a phone does not. A targeted terminal.list is answered by B. The child on B has scope mobile and key = client device id, and is minted only after the client relays. terminal.send with client.type: 'desktop' writes on B. A terminal.subscribe data frame streams back from B. B's token never appears in any frame the client receives, streaming frames included.
  • Fail-closed targeting: files.write targeted at the configured server → forbidden, with A's writeFileExplorerFile never called and no server socket opened. Malformed runtime: → invalid_argument. An unknown env → remote_runtime_unavailable with nothing spawned on A and no child minted on B. terminal.multiplex → forbidden.
  • Unchanged behaviour: targeted desktop-owned routes and untargeted/local/ssh: calls run on A with no server socket opened.
  • A desktop without relay wiring neither advertises the capability nor relays.
  • revokeRuntimeAccess on A removes the client's child on B and leaves the phone's.
  • Unit: the admission refuses a relay whose permission the client lacks (desktop-control without the grant) and allows it with the grant. Relaying clients are listed live-first, then by most recent lastSeenAt, and only for the server they relayed to. A B reply echoing the child token reaches the caller with its own token.
  • The existing phone cases all still pass.

Mutation checks: the files.write case fails if unlisted methods fall back to running locally. The no-child-on-unknown-env assertion fails if enrollment happens before hosts.resolve. The echo unit test fails without the reverse substitution. The revocation test fails without the resync hook.

Commands (Linux): pnpm tc:node; pnpm test --maxWorkers=2 on src/main/runtime/mobile-desktop-relay, src/main/runtime/runtime-rpc, the delegated-device, device-revocation, ephemeral-device, caller-scope, dispatcher, mobile-socket-wiring, mobile ACL and runtime-rpc transport suites (47 files, 329 tests); node config/scripts/check-changed-code-quality.mjs upstream/main; oxlint and oxfmt --check on the changed files. The full pnpm check:changed affected-test run timed out locally; CI covers it.

AI Disclosure

Written with Claude (Anthropic) via an agent harness; reviewed by the author.

Review

  • Security: a runtime client can only reach execution-host methods (already open to phones) on envs A has configured, as a mobile-scoped child that cannot do pairing-admin on B. Each relayed call must first pass A's own permission check for that client's scope and grants. ssh.connect is host-admin, which runtime-paired clients already hold on A, and it is in B's mobile allowlist, so there is no new privilege. A call that names a server never falls back to running on A. B's token never leaves A, and replies echoing it are rewritten to the caller's own token. Revoking on A, or pruning an idle web session, cascades to B on the next resync.
  • Remote/SSH: transport loss stays remote_runtime_unavailable and never surfaces as "exited". WSL envs are still excluded by the host resolver.
  • Mobile: phone admission, allowlist and sync order are unchanged. Phones are always listed before runtime clients in the sync.
  • Cross-platform / performance: no platform-specific code. A runtime-client request costs one prefix check, one route-table lookup and one registry lookup. A sync sorts only that server's relaying clients.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Open questions for maintainers:

  1. Child scope on B: is a mobile child acceptable long term for a desktop client? It means B applies mobile payload dieting (clientKind: 'mobile') to relayed desktop calls, e.g. native-chat block sanitising and session-tab projection, and counts the client as a phone in device lists and push. A follow-up could add a capability-gated kind on the sync params so B mints a runtime child.
  2. projectHostSetup.* left out: the creating methods restamp runtime: host ids to local on the server, so nested results look correct. But these routes are not in the route table, and the mobile child on B is refused them by B's mobile allowlist. A targeted call is therefore refused on A (forbidden) instead of running there. Adding them needs the child-scope change above.
  3. Relaying set is in memory: after A restarts, a client's B child stays until that client relays again or a phone change triggers a resync. Phones have the same "revocation lasts until the next sync" property; persisting the set would close it.
  4. Idle web sessions: the sweep now resyncs when it prunes a relaying ephemeral device, so its B child goes away on the next sync. A device pruned while A cannot reach B keeps its child until a later sync succeeds, as with phones.
  5. Terminal binary forwarding: interactive desktop/web terminals on a relayed host need terminal.multiplex and client→server binary frames forwarded through A. Is a separate capability (e.g. runtime.client-relay.binary.v1) the shape you want for that follow-up?
  6. Revocation after A restarts leaves a dead row on B: the relaying set is empty after a restart, so revoking a client on A does not resync. The phonesChanged resync only walks servers with a cached grant entry, and there are none. B keeps the child until something else syncs that server. The cheap fix is to resync every configured env on a runtime-client revoke, at the cost of one status.get + sync per configured server per revoke. Is that wanted, or is persisting the set preferred?
  7. Ordering signal: liveness comes from A's authenticated sockets and recency from lastSeenAt. A client that disconnects briefly can drop below the cap behind newer sessions until it reconnects and relays again. Acceptable?
  8. Mobile-scoped child means degraded desktop data from B: B treats the relayed desktop client as a phone. status.get relayed to B reports deviceScope: 'mobile', session tabs come back mobile-shaped (the mobile tab projection, not the full desktop shape), and folderWorkspace.create is forbidden because it is outside B's mobile allowlist. The client PR can work around the first two; the third needs the child-scope change in question 1. Is shipping with these gaps acceptable for the first step?

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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)

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
Walkthrough

Runtime-scoped desktop clients can relay eligible RPC requests to configured servers. The runtime tracks relayed clients by server environment and includes them in delegated-device listings. Eligible runtime sockets advertise the relay capability. Text relay responses replace the server grant token with the caller’s device token. Grant sync retries when a pending result did not ask about a requested phone key, and marks only sent phone keys as asked. Device pruning and access revocation remove client enrollment.

Merge Risk: Moderate · previous review 638b5

When 32 phones precede a runtime client, requests through that client can remain stuck in repeated grant syncs. Return a terminal cap error before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: relaying paired desktop and web clients to managed hosts.
Description check Passed The description is complete and relevant. It covers the user-facing behavior, implementation, rationale, linked issues, testing, security, compatibility, limitations, AI disclosure, and checklist stat…
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.
Full details: Description check

Explanation

The description is complete and relevant. It covers the user-facing behavior, implementation, rationale, linked issues, testing, security, compatibility, limitations, AI disclosure, and checklist status. It also explains that full affected-test validation timed out locally and that CI covers it.

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 20 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • 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

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b14fa4e9-64c2-4c49-a5c2-0c1f41ae8d16
Commits

Reviewing files that changed from the base of the PR and between 045f8c8 and fb78e6d.

Files selected for processing: 17
  • src/main/runtime/mobile-desktop-relay/delegated-phone-grant-cache.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/rpc/dispatcher.ts
  • src/main/runtime/rpc/mobile-socket-wiring.ts
  • src/main/runtime/runtime-rpc/relayed-runtime-clients.test.ts
  • src/main/runtime/runtime-rpc/relayed-runtime-clients.ts
  • src/main/runtime/runtime-rpc/runtime-client-relay-admission.test.ts
  • src/main/runtime/runtime-rpc/runtime-client-relay-admission.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-lifecycle.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-status-connection-stamp.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
  • src/shared/mobile-desktop-relay-contract.ts

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

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c113972f-da09-43af-94ac-a011c91f1b22
Commits

Reviewing files that changed from the base of the PR and between fb78e6d and 55f024d.

Files selected for processing: 2
  • src/main/runtime/mobile-desktop-relay/delegated-phone-grant-cache.test.ts
  • src/main/runtime/mobile-desktop-relay/delegated-phone-grant-cache.ts
Files skipped from review as they are similar to previous changes: 1
  • src/main/runtime/mobile-desktop-relay/delegated-phone-grant-cache.ts

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

@jutaz

jutaz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up plan for the client side, so it's visible before I write it. Two questions at the end that decide its shape.

The desktop client can't just send executionHost from its existing environment code: the sidebar's catalog calls (worktree.detectedList/worktree.list, project.list, projectHostSetup.list) aren't execution-host routes, so this PR refuses them through the relay. What I'd do, in order:

  1. Listing only. Main polls mobileRelay.hosts.list / .worktrees on a paired server that advertises runtime.client-relay.v1, and the sidebar shows those workspaces read-only under the server they belong to. No new wire fields.
  2. Routing. A virtual environment id (relay:<server>/<host on server>) that main resolves to the server's connection plus executionHost, so the renderer's fences and caches keep working unchanged. Needs executionHost carried through the call, shared-control and subscription paths, a status.get special case, and a guard so the host's _meta.runtimeId doesn't overwrite the server's.
  3. Actions: git, agent.launch, worktree.*, hiding what the relay refuses.
  4. Terminals: forwarding client binary frames, behind its own capability.

Questions:

  • Should worktree.detectedList/worktree.list and the file mutations (files.write/delete/rename/createDir, files.watch, files.listAll/search) become execution-host routes? That would make the full sidebar and editor work, but it also widens what a phone can do on the host.
  • Is a mobile-scoped child on the host OK for desktop clients, or would you rather have a capability-gated runtime child kind?

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge within its stated server-side scope.

Summary

Adds server-side relay support for paired desktop and web clients targeting managed runtimes.

  • Paired desktop clients can send selected calls through to managed servers.
  • Managed servers get a device for each client that relays to them.
  • Revoked and idle web clients are removed from managed servers.
  • Relayed replies replace the server token with the caller’s token.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  C[Paired desktop or web client] --> A[Server A checks authenticated scope and permissions]
  A --> R{Method route}
  R -->|Execution host| B[Managed server B using delegated mobile device]
  R -->|Paired desktop| L[Run on A]
  R -->|Not listed| E[Refuse request]
  B --> T[Swap caller token and renumber stream IDs]
  T --> C
Loading

Reviews (5) · Last reviewed commit: "fix(remote): refuse a device past the re..." · Reviewed by Greptile

@jutaz

jutaz commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Local CI for 638b57a (on main 5748d11), since Actions waits on approval here. I ran it at the top of the stack (#35478), so it also covers #35242:

  • Typecheck (node, web, cli), changed-code quality, oxlint, oxfmt and both localization checks: all pass.
  • Tests: src/main/runtime/mobile-desktop-relay, src/main/runtime/runtime-rpc, src/main/ipc/runtime-environments, src/shared/remote-runtime and the renderer relayed-host suites. 113 files, 697 passed, 1 skipped. That run was before 638b57a; the relay suites (9 files) pass again on it.

@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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f242412d-9adc-4da9-9ed4-1c333122b7c1
Commits

Reviewing files that changed from the base of the PR and between 0020300 and 638b57a.

Files selected for processing: 2
  • src/main/runtime/mobile-desktop-relay/delegated-phone-grants.test.ts
  • src/main/runtime/mobile-desktop-relay/delegated-phone-grants.ts

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

jutaz added 5 commits November 7, 2026 03:21
…ged hosts

A server with relay host wiring advertises runtime.client-relay.v1 to
runtime-scope sockets and relays their execution-host calls that name a
runtime:<env> target, reusing the phone relay and its delegated devices.
Every other runtime-client request keeps ignoring executionHost.

This branch has not been deployed

No deployments
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