Files
orca/src/shared/execution-host/execution-host-vm-lifecycle.ts
T
Neil 6018fca4de refactor: group shared settings, profiles and execution hosts (#43047)
* refactor: place shared settings profiles and host contracts with owners

* fix: retire stale cleanup validation contacts

* refactor: consolidate imports from concrete owners

* refactor: bind new card fixture to profile defaults owner

* style: format rebased concrete host import

* refactor: consolidate project header color owner imports

* fix: load released phone readers after folder moves

* fix: preserve released chat readers and current owner imports
2026-11-16 04:03:33 -08:00

50 lines
1.9 KiB
TypeScript

import {
getEphemeralVmHostState,
getExecutionHostVmStateHealth,
type EphemeralVmHostLifecycle
} from './execution-host-health'
import { normalizeHostPart, toRuntimeExecutionHostId, type ExecutionHostId } from './execution-host'
import type {
ExecutionHostRegistryEntry,
RuntimeStatusByEnvironmentId
} from './execution-host-registry-entry'
/**
* A suspended VM's server is unreachable by design, so its transport reads disconnected or
* error; the VM record says why. Only hosts already in the registry, and not answering, are
* annotated.
*/
export function applyEphemeralVmHostLifecycles(
hosts: Map<ExecutionHostId, ExecutionHostRegistryEntry>,
lifecycles: readonly EphemeralVmHostLifecycle[] | undefined,
statusByEnvironmentId: RuntimeStatusByEnvironmentId | undefined
): void {
for (const lifecycle of lifecycles ?? []) {
const environmentId = normalizeHostPart(lifecycle.runtimeEnvironmentId)
if (!environmentId) {
continue
}
const hostId = toRuntimeExecutionHostId(environmentId)
const host = hosts.get(hostId)
const vmState = getEphemeralVmHostState(lifecycle.status, lifecycle.waking)
// A server that answers (even one that refuses us) is up whatever the record says: resumed
// outside Orca, or a suspend step that exited 0 without suspending. Only an unreachable
// server takes the VM's state.
const answering =
host?.health === 'available' ||
(host?.health === 'blocked' &&
statusByEnvironmentId?.get(environmentId)?.snapshot?.transport === 'ready')
if (!host || !vmState || answering) {
continue
}
// A blocked reason kept from before the VM slept describes a server that is not there now.
const next: ExecutionHostRegistryEntry = {
...host,
health: getExecutionHostVmStateHealth(vmState),
vmState
}
delete next.blockedReason
hosts.set(hostId, next)
}
}