Skip to content

feat(remote): read a relayed host through the paired server - #35478

Draft
jutaz wants to merge 7 commits into
stablyai:mainfrom
jutaz:feat/runtime-client-relay-reads
Draft

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

Conversation

@jutaz

@jutaz jutaz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

ELI5

#35242 lists the servers that a paired server manages, but you can't open them. This PR adds the part that runs inside the app (main process): a way to read from one of those servers through the server it's paired with, safely. Nothing on screen changes yet. Opening a workspace in the sidebar needs a larger renderer change, which comes in the next PR.

What Changed

Topology: laptop → paired server A (advertises runtime.client-relay.v1, #35195) → managed server B, which A reaches as runtime:<id on A>.

  • Virtual environment id (src/shared/relayed-runtime-environment.ts): relay:<A id>/<A pairing revision>/<runtime:B-id-on-A>. The A id and the host are URI-encoded. It is owner-qualified, because two paired servers may each call a different machine runtime:vm-1. It is also revision-qualified, so an id minted before a re-pair of A can never reach the new pairing. To the renderer it is an ordinary environmentId. It is never added to runtimeEnvironments.list(), so settings, pairing and WSL code don't see it.
  • Main choke points:
    • runtimeEnvironments:call and :getStatus (runtime-environment-connectivity-handlers.ts) check for a relay: selector before resolveEnvironment, the manual-disconnect check, the WSL move fence and the account steps.
    • runtimeEnvironments:subscribe refuses a relay: selector, so it never resolves it to A (see Deferred).
  • Admitted shared-control send (runtime-environment-shared-control-admission.ts): the existing runtime-pinned send (sendRemoteRuntimeSharedControlRequestOnRuntime) is generalized. It now takes an admission predicate over the socket's own status.get and an envelope. It sends only if that status passed, and only while the same socket is current: beforeSend refuses the send if the socket changed since the status. The runtime-pinned caller passes runtimeId === expected and behaves as before: it gets null on refusal, failed status or a socket swap, and one timeout per request. An optional per-connection cache keeps an ok status until that socket is replaced and evicts a failed one. getSharedControlConnection stays private.
  • Relayed transport (runtime-environment-relayed-transport.ts) is a separate path. It does not reuse callRuntimeEnvironment, for these reasons:
    • Gate. The admission is "A's status lists runtime.client-relay.v1", cached per socket generation, so the check runs again after every reconnect, re-pair or restart of A. If the socket is swapped between the check and the send, the call checks once more. A second swap fails as remote_runtime_unavailable ("kept changing; nothing was sent"). Without the capability, the call fails closed with remote_runtime_unavailable ("update Orca on ") and nothing is sent. An old A would answer the call from its own disk, which reads from the wrong machine. If A's own status fails (e.g. runtime_busy), the caller gets that error code. Nothing is cached, so the next call checks again.
    • Read from A's own socket, not the status owner. The capability is read from A's untargeted status on the connection that will carry the call. The relayed server's own status is never consulted for it.
    • Shared control only. There is no one-shot fallback: a one-shot socket costs a second handshake on every call, and the gate on the shared socket would not cover it.
    • One deadline. The caller's timeoutMs (default 15 s) is a single deadline across managed-tunnel repair, the gate probe and the read, over both attempts.
    • Envelope. executionHost?: runtime:${string} is added to RuntimeOrchestrationEnvelope, and serializeRemoteRuntimeRpcRequest copies it. That serializer only writes the fields it lists. No existing call site sets the new field.
    • Pairing pin. A's pairing revision comes from the id itself. It is checked before and after resolveManagedRuntimeEnvironment (which can repair a managed tunnel), and against the caller's expectedEnvironmentPairingRevision. If A has been unpaired, the call returns runtime_environment_changed, not an exception.
    • runtimeId. Nothing on this path calls markEnvironmentUsed, recordRuntimeEnvironmentUsage or the status owner. B's _meta.runtimeId can never overwrite A's stored runtimeId, which A's revision guards depend on. Every failure this path returns, including a manually disconnected A, carries _meta.runtimeId: null, never A's id.
    • status.get is relayed to B and checked with zod (runtimeId, capabilities). It is never answered with A's status. Features of B's workspaces are then gated on B's protocol and capabilities.
    • Read-only allowlist (RELAYED_RUNTIME_READ_METHODS, data): status.get, files.list/read/readChunk/readDir/readPreview/searchPaths/stat, git.status/diff/history/branchDiff, session.tabs.list, terminal.agentStatus, worktree.show/ps. Each is an execution-host route on A. Anything else returns forbidden before any socket is touched.
    • A caller that pins expectedEnvironmentRuntimeId is refused with forbidden ("A runtime can't be pinned through a relay"). It does not get runtime_environment_changed, because a refresh-and-retry would be refused the same way. B's runtime can't be proven before the send, and only mutation callers pin it today.
  • Renderer: getRuntimeEnvironmentRevision returns the owner revision a relay: id carries, and only while that is still A's current revision. Calls therefore pin A's pairing through the existing captureRuntimeEnvironmentRequestRevision. Main refuses an id minted for an older pairing because the revision is in the id itself. The pin adds the caller's own view of A's pairing on top of that.

Why

Issue #29396. The renderer has about 360 kind === 'environment' branches. A virtual environment id resolved in main reaches B through all of them without a new RuntimeClientTarget kind. Fences, caches and runtime: host ids key on the id unchanged.

I gave relayed calls their own transport instead of threading executionHost through callRuntimeEnvironment, for two concrete reasons:

  • shouldUseSharedControlEnvelope (runtime-environment-support-routing.ts:299) passes an envelope on only for non-mutating orchestration.* methods and drops every other envelope. A files.readDir with executionHost would lose the field and run on A itself. That is the same "field dropped, A runs locally" bug the gate exists to prevent.
  • Every send branch there marks A as used from the reply's _meta.runtimeId (markEnvironmentUsedFromResponse, the support-routing markUsed). That includes the one-shot fallback, the cached request connection and support routing. Through a relay, that id is B's.

So the plan's choke points (2) and (3) are covered by not using those branches, not by teaching each one about relays. The shared part, "send only on the socket whose own status admits it", is generalized from the existing runtime-pinned send rather than copied. If the maintainers widen the route table or add a runtime child kind on B, only data changes: the allowlist set here and the method table on A.

Alternatives considered:

  • Feeding relayed rows into the workspace catalog and opening them with the existing workspace view: that needs a repo or worktree identity in resolveOwner, worktree-operation-route, getKnownWorktreeById and activation. Activation also seeds a terminal, and terminal.multiplex is refused through the relay. It is well over this PR's budget, so it is the next PR.
  • Gating on the status owner's snapshot of A: that snapshot can lag a reconnect. The per-socket check here is the same connection the call uses.

Mixed versions:

Laptop Server A Outcome
new new, relay wiring reads reach B; status is B's
new old, orcad, or no relay wiring remote_runtime_unavailable, nothing sent to A beyond status.get
new A reconnects to an older build the next call checks again and fails closed
new A re-paired runtime_environment_changed; the old id is dead
old any unchanged; nothing builds a relay: id

Linked Issue

Part of #29396.

Stacked on #35242 (which is stacked on #35195), so this diff includes their commits until they merge. Review only the last commit, feat(remote): read a relayed host through the paired server.

Visual Proof

N/A: main-process transport plus the renderer's revision pin for relay: ids. Nothing builds such an id yet, so there is no UI or interaction change.

Testing

  • I manually tested these changes locally

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

  • runtime-environment-relayed-transport.test.ts, against a real encrypted shared-control test server standing in for A:

    • the read carries executionHost and is answered as B;
    • one socket serves both the gate and the read;
    • A's stored runtimeId equals its value before the call (a test that marks A used from the relayed reply fails it);
    • status.get returns B's runtimeId;
    • no capability → the read is never sent;
    • a reconnect to a downgraded A → the next read is refused (the first read went through);
    • A's status fails with runtime_busy → the read returns runtime_busy; the next read checks again and goes through (caching the failure fails it);
    • A's socket drops after the gate's status reply and before the read, and comes back as an older build → remote_runtime_unavailable, the read is never sent (removing the beforeSend socket check fails it);
    • an id minted before a re-pair → refused, nothing sent;
    • files.write, terminal.create, git.commit and browser.goto → forbidden with no connection opened.
  • mobile-desktop-relay.integration.test.ts (feat(remote): relay paired desktop and web clients to a server's managed hosts #35195 harness, real A and B RPC servers over E2EE WebSockets): a laptop profile pairs with A as runtime scope. Through getRelayedRuntimeEnvironmentStatus it gets B's runtimeId, and terminal.agentStatus on B's terminal answers with _meta.runtimeId = B. The laptop's stored A runtimeId is not B's.

  • relayed-runtime-environment-revision.test.ts: callRuntimeRpc on a relay: id reaches runtimeEnvironments.call with that selector and A's pairing revision.

  • Mutation checks: dropping executionHost from the serializer fails 2 transport tests. Removing the capability gate fails the no-capability and downgrade tests. Removing the beforeSend socket check fails the socket-swap test. Caching a failed status fails the runtime_busy test. Marking A used from the relayed reply fails the first test.

Commands (Linux): corepack pnpm tc; corepack pnpm test --maxWorkers=2 on src/main/ipc/runtime-environments, src/shared/remote-runtime, src/main/runtime/mobile-desktop-relay, src/shared/relayed*, and the renderer relayed* and runtime-environment-revision* suites (80 files, 507 passed, 1 skipped); node config/scripts/check-changed-code-quality.mjs upstream/main (0 new findings in every pass); oxlint and oxfmt --check on changed files. No strings changed, so the localization checks don't apply. The full pnpm check:changed was not run locally; CI covers it.

AI Disclosure

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

Review

  • Security: the laptop calls methods on A it could already call (feat(remote): relay paired desktop and web clients to a server's managed hosts #35195 admits only execution-host routes for a runtime client and refuses the rest). This client further limits them to reads. Every call is gated on A's capability for the current socket and pinned to A's pairing. A relay: id is parsed strictly: three parts, a numeric revision, and a host that parses as runtime:. Malformed ids return invalid_argument and never reach resolveEnvironment.
  • Remote/SSH: managed-tunnel repair still runs through resolveManagedRuntimeEnvironment, and the revision is checked again after it. A WSL distro is never used as A. A manually disconnected A is never called.
  • Mobile: unchanged. The phone relay path and allowlist are untouched.
  • Performance: one status.get per A socket, cached until that socket changes. A failed status isn't cached. Calls queue per relayed id on the existing runtime call queue, and each call is bounded by one deadline, the caller's timeout.
  • Cross-platform: no platform-specific code.

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

Deferred to the next PR(s):

  • Renderer target for a listed host (relayedRuntimeTarget, readRelayedWorkspaceDirectory): removed from this PR because nothing calls them. They come back with the sidebar change that uses them.
  • Opening a workspace from the 3a list. The rows need a worktree identity that resolveOwner/worktree-operation-route and activation accept. Activation must not seed a terminal. Edit, terminal, browser and git-mutation actions must be hidden. I found no existing read-only workspace flag; editor readOnly is per file.
  • Subscriptions and abortable calls: runtimeEnvironments:subscribe refuses relay: ids. That covers session.tabs.subscribe, files.watch, and callRuntimeRpc with a signal (those go through a one-shot subscription; today that's only the file-search clients). Carrying them needs executionHost on the subscription request channels (remote-runtime-subscription-transport.ts, -request-channel.ts, shared-control subscribe).
  • Gate in status snapshots: the renderer doesn't see a relayed id's status in runtimeStatusByEnvironmentId, so capability-gated UI reads (e.g. paged files.readDir) fall back to their legacy path.

Open questions for maintainers (in addition to the two on #35195):

  1. Is a separate relayed transport acceptable, or would you rather callRuntimeEnvironment take an executionHost option with the identity recording made conditional?
  2. B's replies arrive as a phone child (deviceScope: 'mobile'). This PR only reads, but session.tabs.list returns the mobile projection. Acceptable for view-only, or wait for the runtime child kind?

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)

@jutaz

jutaz commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Local CI for b3408f0 (top of the #35195 → #35242 stack): typecheck, changed-code quality, lint, format and both localization checks pass. The relay, runtime-rpc, runtime-environments, shared remote-runtime and renderer relayed suites pass: 116 files, 711 tests, 1 skipped. That includes the real-socket shared-control tests for the relayed transport.

jutaz added 7 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.
A desktop paired to a server that relays (runtime.client-relay.v1) now
shows, read-only below the workspace list, the managed servers that
server can relay to and their workspaces. The renderer reads them with
mobileRelay.hosts.list/worktrees through the existing runtime call
path, only while that server is in contact and advertises the
capability for the current pairing. Polling pauses in hidden windows.
The rows stay out of the workspace catalog, whose actions the relay
would refuse.
A relay:<server>/<pairing>/<runtime:host> environment id now reaches a
server's managed host from this computer. Main answers it on the paired
server's shared control socket with executionHost set, and only after
that socket's own status advertised runtime.client-relay.v1. A
reconnect proves it again; an old server is never sent the call. Only
read methods pass. status.get is the managed host's own, and its
runtime id is never recorded as the paired server's. Subscriptions and
opening these workspaces in the sidebar come next.
@BTForIT

BTForIT commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for this series. We run #35195, #35242, #35478 and #35631 together on a headless orca serve. A desktop paired only to that server now lists the server's managed host and its workspaces.

The next step your notes describe is opening one of those workspaces from the desktop. That means routing activation, subscriptions and terminal.multiplex per relayed host, plus a worktree identity the renderer accepts. We're starting on it now as a PR stacked on this series, roughly: each relayed host becomes an ordinary paired environment over a host-tagged connection to the server, so the existing paired-server renderer paths run unchanged.

If you already have this in progress, say so and we'll review and test yours instead of opening a second one.

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.

2 participants