Skip to content

feat(mobile): let the desktop list its servers and their workspaces for the phone - #26442

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

Jinwoo-H merged 30 commits into
mainfrom
feat/mobile-relay-hosts

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​733 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​727
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​417 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​401

ELI5

The desktop can now tell its paired phone which Orca servers it's connected to, how each one is doing,
and which workspaces each one has. It keeps the last list it saw, so the phone can still show a server's
workspaces while that server is down. Nothing calls this yet; the next change makes the phone use it.

Stacked on #26435 (the desktop relay). It also merges #26415 (the shared host-health labels), so
until that lands this diff includes it. Review only this branch's own commits.

What Changed

Before: the phone had no way to learn which remote Orca servers its desktop uses, or what's on them.

After (unused until the phone change): two new phone methods, both answered by the desktop itself.

  • mobileRelay.hosts.list (no params) returns {hosts:[{hostId, label, health, relay}]}.
    • hostId is runtime:<env>; label is the desktop's own label, including renames.
    • health uses the shared host-health words and the desktop sidebar's own mapping
      (buildExecutionHostRegistry) over status the desktop already tracks. No new polling.
    • relay is update-needed when the server lacks the delegated-phone capability, ready when it has
      it and is reachable, otherwise unavailable.
    • A server Orca manages on an SSH host is listed the way the sidebar shows it: once, under the SSH
      host's name. When the desktop reaches that machine through SSH, it isn't listed at all, because the
      phone already gets those workspaces as SSH rows.
    • It only reads; it never contacts a server.
  • mobileRelay.hosts.worktrees {hostId} returns that server's workspace rows, fetched by the desktop
    as itself (worktree.ps, full list), with hostId set to runtime:<env>.
    • While the server is reachable it refreshes, at most one fetch per server at a time, bounded to 5 s.
    • Otherwise it returns the last rows unchanged, marked stale: true with fetchedAt. It never makes up
      idle or stopped states.
    • It returns {worktrees: null} for a server never fetched, or last fetched before a re-pair.
    • Rows still being deleted are left out, matching what the phone gets when it asks a server itself.
    • Saved rows for removed servers are dropped on the next call.

Why

The phone should list every workspace the desktop shows, including when a server is offline or too old
to relay to. The desktop already knows each server's status and can fetch its rows as itself, so the
phone gets one listing path. The relay is used only for what happens after the list: opening a
workspace, terminals and actions. The desktop still never reads relayed replies.

Rejected alternatives:

  • the phone fetching each server's rows through the relay and patching in saved rows for offline
    servers: two listing paths, and nothing to show for old servers;
  • the desktop saving rows out of relayed replies: it would have to interpret replies.

Linked Issue

N/A (maintainer)

Visual Proof

N/A. Nothing calls these methods until the phone change.

Testing

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

  • Integration (mobile-relay-host-catalog.integration.test.ts): a real phone, desktop and two real
    servers. The phone lists both servers and gets live rows from the update-needed one. After the ready
    one stops, it gets that server's last rows unchanged with stale: true.

  • Unit tests cover:

    • health and relay mapping, including a server never reached;
    • managed-server folding and renames;
    • the 10 000-row limit;
    • one fetch per server at a time;
    • the 5 s bound (fake timers: no answer at 4 999 ms, stale rows at 5 000 ms);
    • re-pair during a fetch (no old rows, and the next poll fetches again);
    • a removed server, including a fetch that finishes after removal;
    • a manually disconnected server keeping its last rows;
    • a server with no recorded runtime id;
    • rows being deleted;
    • listing never contacting a server.
  • Each of these was checked by breaking the code on purpose and seeing the test fail.

  • 48 tests pass across the relay and runtime RPC folders. The node typecheck, oxlint, oxfmt and the
    changed-code quality gate are clean.

Notes

  • Wire compatibility: two new methods only. The phone calls them only after the desktop advertises the
    relay capability, so an old desktop is never asked.
  • SSH: servers on SSH hosts follow the desktop sidebar's folding.
  • Folder workspaces: rows pass through unchanged apart from hostId.
  • Memory: one saved list per configured server (up to 10 000 rows each), pruned when servers are
    removed.

Rows on an SSH host the desktop cannot reach looked healthy on the phone. The badge now
adds the desktop sidebar's own word ("devbox · Disconnected"), derived by the same shared
function from the connection status ssh.listTargetSummaries already sends; old desktops keep today's badge.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The desktop card shows SSH status on any host count, so the phone now reads target summaries
whenever a repo is on SSH and badges an unhealthy host alone too. Labels and health share one
target-to-host keying, and a hook-level test pins the reply-to-row wiring.

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

A catalog that no longer spans hosts or holds an SSH repo now clears the health and label maps,
so a host that left cannot keep badging rows. The badge gets a screen-reader label ("devbox,
Disconnected") instead of reading the middle dot.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…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
… tsc passes

Fixtures hoisted into consts widened their health maps to string, which the now-required
hostHealthById rejects under the tests-typecheck ratchet; passing them inline keeps the union.

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
The settled metadata state now carries hostHealthById, and an SSH-only catalog now reads the
target summaries so a lone unhealthy host can be badged. Scoped re-record via rpc-recording.mts.

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
…rkspace rows for the phone

The phone needs the same host list the desktop shows, including servers that are offline or
too old to relay to. mobileRelay.hosts.list/worktrees answer from the desktop's own status and
its own worktree.ps fetches, cached per server and fenced by pairing, never from relayed replies.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… side effect on listing

The phone now always lists a server's rows through mobileRelay.hosts.worktrees, so the
desktop's own fetch is both the live source and the cache, and stamping stays in main.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… forget removed servers

The desktop now asks for the phone's full-catalog limit, answers within 5s with the last rows
when a server hangs, drops a server's rows when it is removed or re-paired, and checks the
server's identity after the fetch so a reply from before a re-pair is never served.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…de rows mid-delete

A server Orca manages on an SSH host now lists once under that host's name, or not at all while
the host is reached over the SSH relay, using the sidebar's own folding. Rows the server is
deleting are left out at reply time, as a phone asking the server itself would see.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
… re-paired server's fetch

Retirement also fires on a manual disconnect or managed-server update, which wrongly emptied
the phone's list; rows are now pruned only once a server is no longer configured. Fetches are
shared per server identity, so a poll after a re-pair asks the new server right away.

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
…s1b-mobile-relay into feat/mobile-relay-hosts

# Conflicts:
#	src/main/runtime/runtime-rpc/runtime-rpc-mobile-method-allowlist.ts
…space lists

The phone reads only the rows, so stale, fetchedAt, totalCount and truncated
were dead wire weight. The desktop still serves a server's last rows while
the server is unreachable.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
@Jinwoo-H
Jinwoo-H changed the base branch from feat/desktop-mobile-relay to main October 11, 2026 07:12
# Conflicts:
#	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/delegated-mobile-device.integration.test.ts
#	src/main/runtime/device-registry.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/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-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/shared/protocol-version.ts
main now requires every runtime RPC namespace in the host-operation ownership table; the relay-hosts methods are served by the desktop the phone is paired to.
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

The change adds a desktop catalog that lists configured runtime hosts and retrieves their worktree rows through mobile RPC methods. The catalog reports host health and relay status, and caches worktree rows using pairing revision and runtime ID checks. Host calls now support timeout and expected-identity options. The change also adds shared relay-host contracts and runtime-status snapshot conversion.


Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 6732e

Workspace listings remain bounded, but a blocked fetch can leave a host showing cached or missing rows until the queued call settles. Address the refresh retry and runtime-identity guard before merging, or accept these bounded risks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 20 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check Passed The description is complete and directly explains the user impact, implementation, rationale, linked-issue exception, visual-proof decision, testing, compatibility, SSH behavior, and performance consi…
Title check Passed The title clearly and concisely describes the main change: allowing the desktop to list its servers and workspaces for the phone.
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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a44309a3-7896-4149-a969-669fce2c9446
📥 Commits

Reviewing files that changed from the base of the PR and between ff5c284 and 6732ec5.

⛔ Files ignored due to path filters (1)
  • src/shared/rpc-contract/rpc-params-catalog.generated.ts is excluded by !**/*.generated.*
📒 Files selected for processing (20)
  • src/main/ipc/runtime-environment-mobile-relay-hosts.test.ts
  • src/main/ipc/runtime-environment-mobile-relay-hosts.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-relay-host-catalog.integration.test.ts
  • src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.test.ts
  • src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/rpc/dispatcher-stream-options.ts
  • src/main/runtime/rpc/methods/index.ts
  • src/main/runtime/rpc/methods/mobile-relay-hosts.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/renderer/src/store/slices/runtime-status-snapshot.ts
  • src/shared/host-operation-ownership.ts
  • src/shared/mobile-relay-hosts-contract.ts
  • src/shared/runtime-host-status.ts

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

Comment on lines +75 to +87
call: (host, method, params, options) =>
callRuntimeEnvironment(
userDataPath,
host.environmentId,
method,
params,
options?.timeoutMs,
options?.expected?.pairingRevision,
undefined,
options?.expected?.runtimeId
? { expectedEnvironmentRuntimeId: options.expected.runtimeId }
: undefined
),

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -A20 'function runtimeEnvironmentRevisionFailure' src/main

Repository: stablyai/orca

Length of output: 2065


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- reviewed file ---'
nl -ba src/main/ipc/runtime-environment-mobile-relay-hosts.ts | sed -n '1,180p'
printf '%s\n' '--- runtime call and option definitions ---'
rg -n -F --glob '*.ts' -- 'expectedEnvironmentRuntimeId' src/main
rg -n -F --glob '*.ts' -- 'runtimeId:' src/main/ipc src/main | head -80
printf '%s\n' '--- relevant catalog and relay symbols ---'
rg -n -F --glob '*.ts' -- 'hosts.worktrees' src/main src
rg -n -F --glob '*.ts' -- 'createRuntimeEnvironmentMobileRelayHosts' src/main src
printf '%s\n' '--- changed diff ---'
git diff --unified=35 ff5c284cc18a8cbebc3abd0b3a8854358fc1dd80 6732ec54616ad1fc63c64f44598ddf1a198a264e -- src/main/ipc/runtime-environment-mobile-relay-hosts.ts src/main/ipc/runtime-environment-revision-guard.ts

Repository: stablyai/orca

Length of output: 26190


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- relay host contract ---'
nl -ba src/main/runtime/mobile-desktop-relay/mobile-desktop-relay-hosts.ts | sed -n '1,220p'
printf '%s\n' '--- worktree catalog implementation ---'
rg -n -F --glob '*.ts' -- 'MOBILE_RELAY_HOST_WORKTREES_METHOD' src/main src/shared
rg -n -F --glob '*.ts' -- 'worktrees' src/main/runtime/mobile-desktop-relay src/main/runtime/runtime-rpc
printf '%s\n' '--- environment type ---'
rg -n -F --glob '*.ts' -- 'interface KnownRuntimeEnvironment' src/shared src/main
rg -n -F --glob '*.ts' -- 'type KnownRuntimeEnvironment' src/shared src/main
printf '%s\n' '--- transport implementation and guard call ---'
nl -ba src/main/ipc/runtime-environment-transport-routing.ts | sed -n '1,130p'
nl -ba src/main/ipc/runtime-environment-revision-guard.ts | sed -n '1,80p'

Repository: stablyai/orca

Length of output: 20870


🏁 Script executed:

set -o pipefail
nl -ba src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.ts | sed -n '55,180p'
printf '%s\n' '--- relay method binding ---'
nl -ba src/main/runtime/rpc/methods/mobile-relay-hosts.ts | sed -n '1,120p'
printf '%s\n' '--- host catalog fence references ---'
rg -n -F --glob '*.ts' -- 'expected:' src/main/runtime/mobile-desktop-relay src/main/runtime/rpc

Repository: stablyai/orca

Length of output: 8099


Preserve a null runtime ID in the mobile relay fence.

fetchAsDesktop() passes host.identity, whose runtimeId can be null. The truthiness check drops that value, so the transport does not reject a call when the runtime changes from null to a new runtime. The later catalog fence prevents stale rows from being returned, but the request still runs against the wrong runtime.

Use an undefined check and allow null through the transport and guard types.

🐛 Suggested fix
diff --git a/src/main/ipc/runtime-environment-mobile-relay-hosts.ts b/src/main/ipc/runtime-environment-mobile-relay-hosts.ts
--- a/src/main/ipc/runtime-environment-mobile-relay-hosts.ts
+++ b/src/main/ipc/runtime-environment-mobile-relay-hosts.ts
@@
-        options?.expected?.runtimeId
+        options?.expected?.runtimeId !== undefined
           ? { expectedEnvironmentRuntimeId: options.expected.runtimeId }
           : undefined
diff --git a/src/main/ipc/runtime-environment-transport-routing.ts b/src/main/ipc/runtime-environment-transport-routing.ts
--- a/src/main/ipc/runtime-environment-transport-routing.ts
+++ b/src/main/ipc/runtime-environment-transport-routing.ts
@@
-  options?: { signal?: AbortSignal; expectedEnvironmentRuntimeId?: string }
+  options?: { signal?: AbortSignal; expectedEnvironmentRuntimeId?: string | null }
diff --git a/src/main/ipc/runtime-environment-revision-guard.ts b/src/main/ipc/runtime-environment-revision-guard.ts
--- a/src/main/ipc/runtime-environment-revision-guard.ts
+++ b/src/main/ipc/runtime-environment-revision-guard.ts
@@
-  expectedRuntimeId?: string
+  expectedRuntimeId?: string | null

Comment on lines +136 to +186
private refresh(host: DescribedHost): Promise<void> {
const key = `${host.environmentId}\0${fenceOf(host.identity)}`
const inFlight = this.refreshing.get(key)
if (inFlight) {
return inFlight
}
const refresh = this.fetchAsDesktop(host).finally(() => this.refreshing.delete(key))
this.refreshing.set(key, refresh)
return refresh
}

private async fetchAsDesktop(host: DescribedHost): Promise<void> {
try {
const response = await this.options.hosts.call(
host,
'worktree.ps',
{ limit: SERVER_WORKTREE_LIMIT, supportsWorktreeVisibilitySourceDefaults: true },
// Why the transport bound too: it ends the hung call, so the next poll fetches afresh instead of joining it.
{ timeoutMs: SERVER_FETCH_TIMEOUT_MS, expected: host.identity }
)
const reply = response.ok ? WorktreePsReplySchema.safeParse(response.result) : null
if (!reply?.success) {
return
}
this.cached.set(host.environmentId, {
// Why the identity taken before the fetch: the call's own check cannot see a re-pair after dispatch.
fence: fenceOf(host.identity),
worktrees: stampServerWorktreeRows(host.environmentId, reply.data.worktrees)
})
} catch {
// An unreachable server keeps its last rows.
}
}
}

function fenceOf(identity: DescribedHost['identity']): string {
return `${identity.pairingRevision}\0${identity.runtimeId}`
}

/** Settles once the bound passes; the call's own timeout starts only after the desktop's per-server queue. */
async function withinFetchBound(refresh: Promise<void>): Promise<void> {
let timer: ReturnType<typeof setTimeout> | undefined
const bound = new Promise<void>((resolve) => {
timer = setTimeout(resolve, SERVER_FETCH_TIMEOUT_MS)
})
try {
return await Promise.race([refresh, bound])
} finally {
clearTimeout(timer)
}
}

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:

sed -n '65,95p;130,190p' src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.ts
sed -n '355,400p' src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.test.ts
rg -n 'function callRuntimeEnvironment|const callRuntimeEnvironment|timeoutMs|inFlight' src/main/ipc/runtime-environment-transport-routing.ts src/main/ipc/runtime-environment-mobile-relay-hosts.ts src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.ts

Repository: stablyai/orca

Length of output: 6698


🏁 Script executed:

sed -n '1,250p' src/main/ipc/runtime-environment-mobile-relay-hosts.ts
sed -n '1,250p' src/main/ipc/runtime-environment-transport-routing.ts
rg -n -F --glob '*.ts' -- 'MobileDesktopRelayHosts' src/main
rg -n -F --glob '*.ts' -- 'options.hosts.call' src/main
rg -n -F --glob '*.ts' -- 'callRuntimeEnvironment(' src/main

Repository: stablyai/orca

Length of output: 20306


🏁 Script executed:

sed -n '1,260p' src/main/ipc/runtime-environment-call-queue.ts
rg -n -F --glob '*.ts' -- 'enqueueRuntimeCall' src/main/ipc src/main/runtime
rg -n -i --glob '*.test.ts' -- 'call.queue|queued|queue|enqueueRuntimeCall' src/main/ipc/runtime-environment-call-queue.test.ts src/main/ipc

Repository: stablyai/orca

Length of output: 41078


🏁 Script executed:

sed -n '1,320p' src/shared/runtime-rpc-call-queue.ts
rg -n -F --glob '*.ts' -- 'RuntimeRpcCallQueuePool' src/shared src/main
rg -n -i --glob '*.test.ts' -- 'RuntimeRpcCallQueuePool|runtime rpc call queue|runtime_rpc_queue' src/shared src/main

Repository: stablyai/orca

Length of output: 13651


🏁 Script executed:

rg -n -F --glob '*.ts' -- 'function sendRemoteRuntimeRequestAbortable' src/main src/shared
rg -n -F --glob '*.ts' -- 'function sendRemoteRuntimeConnectionRequestAbortable' src/main src/shared
rg -n -F --glob '*.ts' -- 'function resolveManagedRuntimeEnvironment' src/main src/shared
sed -n '1,280p' src/main/ipc/runtime-environment-abortable-requests.ts
sed -n '1,220p' src/main/ipc/runtime-environment-managed-tunnel.ts

Repository: stablyai/orca

Length of output: 7667


Bound the promise stored in refreshing.

worktrees() only bounds its wait. refresh() stores the unbounded fetchAsDesktop() promise. The host adapter queues that call before applying timeoutMs, and the queue has no admission timeout or cancellation signal on this path. If the call remains queued, refreshing is not cleared when the five-second fallback returns. Later requests for the same identity reuse that promise and can keep returning cached or null rows until the queued call settles.

Suggested fix
-      await withinFetchBound(this.refresh(host))
+      await this.refresh(host)
...
-    const refresh = this.fetchAsDesktop(host).finally(() => this.refreshing.delete(key))
+    const refresh = withinFetchBound(this.fetchAsDesktop(host)).finally(() =>
+      this.refreshing.delete(key)
+    )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private refresh(host: DescribedHost): Promise<void> {
const key = `${host.environmentId}\0${fenceOf(host.identity)}`
const inFlight = this.refreshing.get(key)
if (inFlight) {
return inFlight
}
const refresh = this.fetchAsDesktop(host).finally(() => this.refreshing.delete(key))
this.refreshing.set(key, refresh)
return refresh
}
private async fetchAsDesktop(host: DescribedHost): Promise<void> {
try {
const response = await this.options.hosts.call(
host,
'worktree.ps',
{ limit: SERVER_WORKTREE_LIMIT, supportsWorktreeVisibilitySourceDefaults: true },
// Why the transport bound too: it ends the hung call, so the next poll fetches afresh instead of joining it.
{ timeoutMs: SERVER_FETCH_TIMEOUT_MS, expected: host.identity }
)
const reply = response.ok ? WorktreePsReplySchema.safeParse(response.result) : null
if (!reply?.success) {
return
}
this.cached.set(host.environmentId, {
// Why the identity taken before the fetch: the call's own check cannot see a re-pair after dispatch.
fence: fenceOf(host.identity),
worktrees: stampServerWorktreeRows(host.environmentId, reply.data.worktrees)
})
} catch {
// An unreachable server keeps its last rows.
}
}
}
function fenceOf(identity: DescribedHost['identity']): string {
return `${identity.pairingRevision}\0${identity.runtimeId}`
}
/** Settles once the bound passes; the call's own timeout starts only after the desktop's per-server queue. */
async function withinFetchBound(refresh: Promise<void>): Promise<void> {
let timer: ReturnType<typeof setTimeout> | undefined
const bound = new Promise<void>((resolve) => {
timer = setTimeout(resolve, SERVER_FETCH_TIMEOUT_MS)
})
try {
return await Promise.race([refresh, bound])
} finally {
clearTimeout(timer)
}
}
private refresh(host: DescribedHost): Promise<void> {
const key = `${host.environmentId}\0${fenceOf(host.identity)}`
const inFlight = this.refreshing.get(key)
if (inFlight) {
return inFlight
}
const refresh = withinFetchBound(this.fetchAsDesktop(host)).finally(() =>
this.refreshing.delete(key)
)
this.refreshing.set(key, refresh)
return refresh
}
private async fetchAsDesktop(host: DescribedHost): Promise<void> {
try {
const response = await this.options.hosts.call(
host,
'worktree.ps',
{ limit: SERVER_WORKTREE_LIMIT, supportsWorktreeVisibilitySourceDefaults: true },
// Why the transport bound too: it ends the hung call, so the next poll fetches afresh instead of joining it.
{ timeoutMs: SERVER_FETCH_TIMEOUT_MS, expected: host.identity }
)
const reply = response.ok ? WorktreePsReplySchema.safeParse(response.result) : null
if (!reply?.success) {
return
}
this.cached.set(host.environmentId, {
// Why the identity taken before the fetch: the call's own check cannot see a re-pair after dispatch.
fence: fenceOf(host.identity),
worktrees: stampServerWorktreeRows(host.environmentId, reply.data.worktrees)
})
} catch {
// An unreachable server keeps its last rows.
}
}
}
function fenceOf(identity: DescribedHost['identity']): string {
return `${identity.pairingRevision}\0${identity.runtimeId}`
}
/** Settles once the bound passes; the call's own timeout starts only after the desktop's per-server queue. */
async function withinFetchBound(refresh: Promise<void>): Promise<void> {
let timer: ReturnType<typeof setTimeout> | undefined
const bound = new Promise<void>((resolve) => {
timer = setTimeout(resolve, SERVER_FETCH_TIMEOUT_MS)
})
try {
return await Promise.race([refresh, bound])
} finally {
clearTimeout(timer)
}
}

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