mirror of
https://github.com/stablyai/orca.git
synced 2026-11-01 01:27:35 +00:00
* feat(wsl): persist WSL host deployments in their own store and type orcad deployment links by kind * chore(wsl): drop an unused link type export * feat(wsl): add, persist and connect WSL distro hosts behind an experimental flag (WSL-via-orcad C7a) Main-process wiring for WSL hosts: list registered WSL 2 distros, add one (C4 deploy and launch through C6 liveness, then persist the paired environment and its C2 record), keep a relaunch's new device token, connect a host only for the user or an open project or terminal, adopt holders at startup, and remove a host (release its holder, drop both records). Refuses a distro whose orcad this desktop already reaches as another server (R25). * fix(wsl): read distro registrations through one reader that returns the canonical unbraced GUID C4's registry reader returned the braced GUID while the C2 record only accepts it unbraced, and C7 parsed the same output a second time. The one reader now yields lowercase unbraced ids and each registration's WSL version; the host distro list uses it. * fix(wsl): refuse to connect a WSL host while the experiment is off Adding, connecting and background connects all stop while Experimental → WSL distros as hosts is off; removing still works. The pre-deploy refusals move to their own module. * fix(wsl): stop a connected WSL host's server when the host is removed Remove ended the bridge and released the distro's holder but left orcad to exit with the distro. A connected server is now ended right away, only in a distro already running. * fix(wsl): import the orcad host errors from their new orcad/ home * fix(wsl): refuse WSL hosts in a build without the orcad template, and say so up front A build shipped without the orcad deployment template let the add dialog run and fail after seconds with a raw internal error. Main now checks the template as SSH hosts do, refuses add and connect (and skips lazy connects and holder adoption) before any deploy work, and exposes the capability so the UI can show it. * test(wsl): let the e2e WSL fake re-read its distro list, to register one mid-run * fix(wsl): end a removed host's terminals and daemon, and stop WSL hosts when the experiment is off Remove now ends the host's terminals through orcad's terminal RPC, waits for the terminal census to prove none remain, closes the bridge, and runs the managed decommission SSH hosts use, which stops orcad and retires its idle terminal daemon. What it could not end is reported back. Turning Experimental → WSL distros as hosts off closes every connection and liveness watch, releases the holders so distros can idle-stop, and keeps liveness from relaunching for visible work; turning it on resumes only the hosts open work needs. * fix(wsl): keep WSL hosts out of the servers a phone reaches through this desktop They are this desktop's own distros, connected only for work open here; a phone listing or routing to one would wake it behind the user's back. * fix(wsl): end a removed host's terminals through its own route, and never respawn it Removal reached orcad with the bridge's raw pairing offer rather than the routed environment and saved pairing the app already uses for the host; on a real orcad ending terminals failed fast and left them, the daemon and orcad running. It now calls by environment id through the same transport as every other call to the host, and the e2e fake runs these real steps against a headless server. Removal also stops tracking the host first (open work, connects, runtime calls), so nothing reconnects it while it stops, and a spawn guard in the connector refuses any holder, deploy or bridge for a distro whose host is gone (the respawn loop after removal). A WSL host that isn't connected answers runtime calls with why, instead of failing as an unreachable network server. * fix(wsl): suggest reconnecting a WSL host, not Tailscale, when it can't be reached Unreachable-server hints are chosen by the owner host's kind: a WSL host is a distro on this computer, so it points at its reconnect instead of the Tailscale advice for network servers. * test(wsl): parse the terminal list removal reads, and log the e2e fake's connects to a file * fix(wsl): close a removed host's terminals by handle and report stopped only on proof Removal stopped terminals per workspace, so one orphan whose project was gone threw selector_not_found and aborted before orcad was stopped. It now closes each terminal by handle, keeps going past failures and names them, and still asks orcad to stop. It reports stopped only when the census shows no session left, the daemon retired, and the orcad the distro records as active is the one this computer was connected to; a re-add that adopted an orcad the record does not name is reported instead of claimed stopped. * feat(wsl): close WSL hosts behind an internal-only gate in every build WSL distros as hosts must not be reachable by users until moving a project between hosts is lossless and the feature matches today's WSL support. ORCA_INTERNAL_WSL_HOSTS=1 opens the gate; otherwise main creates no WSL host service (no holder adoption, wsl.exe spawn or reconnect), refuses add, connect, remove and every runtime call to a WSL host, keeps persisted WSL hosts out of the server list, startup status probes and AI vault scans while leaving them on disk, and the preload exposes no WSL host API. * fix(wsl): keep SSH and paired servers listed whatever the WSL deployment file holds An unreadable WSL record no longer hides an SSH-linked server, and with the internal gate closed a corrupt WSL file is warned about instead of failing the whole registry. * fix(wsl): let an unreadable WSL record hide only a loopback pairing A WSL host always pairs over a loopback endpoint, so a stale record can no longer remove a remote paired server from the list. * fix(wsl): ignore unreadable WSL deployment state while the internal gate is closed A newer or stale record could otherwise hide a re-paired loopback server for users who never open the gate.
136 lines
4.9 KiB
TypeScript
136 lines
4.9 KiB
TypeScript
/**
|
|
* An SSH host and the managed Orca server Orca runs on it are one machine to the user. The registry
|
|
* keeps both ids, since workspaces, setups and folders are owned by one or the other; pickers show
|
|
* one row for the pair and expand a choice of that row to both ids.
|
|
*/
|
|
import {
|
|
toRuntimeExecutionHostId,
|
|
toSshExecutionHostId,
|
|
type ExecutionHostId
|
|
} from './execution-host'
|
|
import type { ExecutionHostRegistryEntry } from './execution-host-registry'
|
|
import type { SshConnectionState } from './ssh-types'
|
|
|
|
/** The deployment fields host pairing reads; a WSL distro has no SSH host row to merge with. */
|
|
export type ManagedOrcadDeploymentSummary = { kind?: 'ssh'; sshTargetId: string } | { kind: 'wsl' }
|
|
|
|
export type ManagedOrcadEnvironmentSummary = {
|
|
id: string
|
|
orcadDeployment?: ManagedOrcadDeploymentSummary | null
|
|
}
|
|
|
|
/** The merge fields a host row carries; picker option types extend it. */
|
|
export type MergedExecutionHost = {
|
|
id: ExecutionHostId
|
|
/** On the row pickers show: the merged-away id it also stands for. */
|
|
aliasHostIds?: readonly ExecutionHostId[]
|
|
/** On the merged-away entry: the row that stands for it. */
|
|
mergedIntoHostId?: ExecutionHostId
|
|
}
|
|
|
|
/** The SSH target this environment is the managed Orca server for; null for any other server. */
|
|
export function getManagedOrcadSshTargetId(
|
|
environment: ManagedOrcadEnvironmentSummary
|
|
): string | null {
|
|
const deployment = environment.orcadDeployment
|
|
return (deployment?.kind !== 'wsl' && deployment?.sshTargetId.trim()) || null
|
|
}
|
|
|
|
/**
|
|
* Pairs each listed SSH host with its managed server, in place. The row pickers show is keyed by
|
|
* the route serving the host now: the server, unless main reports the host on its relay.
|
|
*/
|
|
export function annotateManagedOrcadExecutionHosts(args: {
|
|
hosts: Map<ExecutionHostId, ExecutionHostRegistryEntry>
|
|
runtimeEnvironments: readonly ManagedOrcadEnvironmentSummary[]
|
|
sshConnectionStates?: ReadonlyMap<string, Pick<SshConnectionState, 'managedServer'>>
|
|
}): void {
|
|
for (const environment of args.runtimeEnvironments) {
|
|
const targetId = getManagedOrcadSshTargetId(environment)
|
|
if (!targetId) {
|
|
continue
|
|
}
|
|
const sshHostId = toSshExecutionHostId(targetId)
|
|
const runtimeHostId = toRuntimeExecutionHostId(environment.id.trim())
|
|
const sshHost = args.hosts.get(sshHostId)
|
|
const runtimeHost = args.hosts.get(runtimeHostId)
|
|
// Why: an orphaned server (its SSH host removed) is the only row left for that machine.
|
|
if (!sshHost || !runtimeHost) {
|
|
continue
|
|
}
|
|
const onRelay = args.sshConnectionStates?.get(targetId)?.managedServer?.kind === 'relay'
|
|
const shown = onRelay ? sshHost : runtimeHost
|
|
const mergedAway = onRelay ? runtimeHost : sshHost
|
|
// Why the SSH host's name and detail: that is the identity the user configured.
|
|
args.hosts.set(shown.id, {
|
|
...shown,
|
|
label: sshHost.label,
|
|
detail: sshHost.detail,
|
|
aliasHostIds: [mergedAway.id]
|
|
})
|
|
args.hosts.set(mergedAway.id, {
|
|
...mergedAway,
|
|
label: sshHost.label,
|
|
mergedIntoHostId: shown.id
|
|
})
|
|
}
|
|
}
|
|
|
|
export function isMergedAwayExecutionHost(host: MergedExecutionHost): boolean {
|
|
return host.mergedIntoHostId !== undefined
|
|
}
|
|
|
|
/** The rows a picker shows: one per machine. */
|
|
export function pickerExecutionHosts<T extends MergedExecutionHost>(hosts: readonly T[]): T[] {
|
|
return hosts.filter((host) => !isMergedAwayExecutionHost(host))
|
|
}
|
|
|
|
/** Indexes hosts by id, with a merged-away id resolving to the row that stands for it. */
|
|
export function indexExecutionHostsById<T extends MergedExecutionHost>(
|
|
hosts: readonly T[]
|
|
): Map<ExecutionHostId, T> {
|
|
const byId = new Map<ExecutionHostId, T>(hosts.map((host) => [host.id, host]))
|
|
for (const host of hosts) {
|
|
const shown = host.mergedIntoHostId ? byId.get(host.mergedIntoHostId) : undefined
|
|
if (shown) {
|
|
byId.set(host.id, shown)
|
|
}
|
|
}
|
|
return byId
|
|
}
|
|
|
|
/** Every id the given ids stand for, so a choice of a merged row matches both owners. */
|
|
export function expandEquivalentExecutionHostIds(
|
|
hosts: readonly MergedExecutionHost[],
|
|
hostIds: Iterable<ExecutionHostId>
|
|
): ExecutionHostId[] {
|
|
const byId = indexExecutionHostsById(hosts)
|
|
const expanded = new Set<ExecutionHostId>()
|
|
for (const hostId of hostIds) {
|
|
expanded.add(hostId)
|
|
const shown = byId.get(hostId)
|
|
if (shown) {
|
|
expanded.add(shown.id)
|
|
for (const aliasHostId of shown.aliasHostIds ?? []) {
|
|
expanded.add(aliasHostId)
|
|
}
|
|
}
|
|
}
|
|
return [...expanded]
|
|
}
|
|
|
|
/**
|
|
* A saved host list widened to every id its merged rows stand for, or null when it already is.
|
|
* Lists saved by an older build, or before a route flip, may hold only one of a pair.
|
|
*/
|
|
export function widenSavedExecutionHostIds(
|
|
hosts: readonly MergedExecutionHost[],
|
|
hostIds: readonly ExecutionHostId[] | null
|
|
): ExecutionHostId[] | null {
|
|
if (!hostIds) {
|
|
return null
|
|
}
|
|
const widened = expandEquivalentExecutionHostIds(hosts, hostIds)
|
|
return widened.length === new Set(hostIds).size ? null : widened
|
|
}
|