blob: 05e03686b7ad89c31f51d5ce6c42ad2960aa496d [file]
import {
resolveExistingStorageRoot,
tryAcquireInteractiveRootOwner,
} from '@maka/storage/root-authority';
import { RuntimeHostKernel } from './host-kernel.js';
export interface RuntimeHostCandidateOptions {
rootPath: string;
expectedRootId: string;
legacyConfigurationRoot?: string;
idleGraceMs?: number;
handshakeTimeoutMs?: number;
}
export type RuntimeHostCandidateResult =
| { kind: 'loser' }
| { kind: 'winner'; host: RuntimeHostKernel };
export async function startRuntimeHostCandidate(
options: RuntimeHostCandidateOptions,
): Promise<RuntimeHostCandidateResult> {
const capability = await resolveExistingStorageRoot({
path: options.rootPath,
kind: 'interactive',
expectedRootId: options.expectedRootId,
});
const owner = await tryAcquireInteractiveRootOwner(capability);
if (!owner) return { kind: 'loser' };
const host = await RuntimeHostKernel.start({
owner,
idleGraceMs: options.idleGraceMs,
handshakeTimeoutMs: options.handshakeTimeoutMs,
});
return { kind: 'winner', host };
}