Skip to content

Commit b39e8d3

Browse files
authored
fix(runtime-host): preserve legacy handoff operator (#4696)
Refs #4657 Generated-by: OpenAI Codex
1 parent 1068916 commit b39e8d3

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

apps/desktop/src/main/__tests__/runtime-host-local-remote-access.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ test('replaces a conflicting supervised Host with the requested active-work poli
404404
resolveManagedDeploymentAuthority: async () => ({
405405
kind: 'active',
406406
lifecycleMode: 'supervised',
407+
deploymentRoot: join(base, 'deployment'),
407408
target: {
408409
schemaVersion: 2,
409410
serviceId: rootId,
@@ -513,14 +514,14 @@ test('does not persist recoverable setup authority before Desktop ownership comm
513514
assert.equal(setupCalls, 0);
514515
});
515516

516-
test('adopts committed managed authority from a released handoff without replaying setup', async (t) => {
517+
test('adopts a released handoff through its existing legacy operator', async (t) => {
517518
const base = await mkdtemp(join(tmpdir(), 'maka-local-remote-access-prestart-'));
518519
t.after(() => rm(base, { recursive: true, force: true }));
519520
const clientDataRoot = join(base, 'client');
520521
const rootPath = join(clientDataRoot, 'workspaces', 'default');
521522
const rootId = 'a'.repeat(64);
522523
const deploymentId = '22222222-2222-4222-8222-222222222222';
523-
const installedOperator = testOperator(join(base, 'installed', 'operator.mjs'));
524+
const deploymentRoot = join(base, 'installed');
524525
await mkdir(rootPath, { recursive: true });
525526
await writeFile(
526527
join(clientDataRoot, 'runtime-host-local-service.json'),
@@ -543,10 +544,11 @@ test('adopts committed managed authority from a released handoff without replayi
543544
resolveManagedDeploymentAuthority: async () => ({
544545
kind: 'active',
545546
lifecycleMode: 'supervised',
547+
deploymentRoot,
546548
target: {
547549
schemaVersion: 2,
548550
serviceId: rootId,
549-
operator: installedOperator,
551+
operator: testOperator(join(deploymentRoot, 'operator.mjs')),
550552
rootPath,
551553
rootId,
552554
deploymentId,
@@ -570,7 +572,10 @@ test('adopts committed managed authority from a released handoff without replayi
570572
schemaVersion: 2,
571573
state: 'managed',
572574
serviceId: rootId,
573-
operator: installedOperator,
575+
operator: {
576+
kind: 'legacy_posix_executable',
577+
executablePath: join(deploymentRoot, 'operator'),
578+
},
574579
rootPath,
575580
rootId,
576581
deploymentId,

apps/desktop/src/main/runtime-host-local-remote-access.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type LocalManagedDeploymentAuthority =
9292
| {
9393
readonly kind: 'active';
9494
readonly lifecycleMode: 'on_demand' | 'supervised';
95+
readonly deploymentRoot: string;
9596
readonly target: LocalServiceTarget;
9697
}
9798
| { readonly kind: 'transition' };
@@ -205,6 +206,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
205206
return {
206207
kind: 'active',
207208
lifecycleMode: authority.record.lifecycle.mode,
209+
deploymentRoot: authority.record.deploymentRoot,
208210
target: requireServiceTarget(
209211
{
210212
schemaVersion: 2,
@@ -223,15 +225,24 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
223225
});
224226

225227
const adoptCommittedSetup = async (
226-
setup: LocalServiceSetupPending,
228+
setup: LocalServiceSetupPending | LocalServiceLegacyHandoff,
227229
): Promise<
228230
| { readonly kind: 'absent' | 'transition' }
229231
| { readonly kind: 'managed'; readonly managed: LocalServiceManaged }
230232
> => {
231233
const authority = await resolveManagedDeploymentAuthority(setup.rootId);
232234
if (!authority) return { kind: 'absent' };
233235
if (authority.kind === 'transition') return authority;
234-
const managed = managedLifecycle(authority.target);
236+
const target =
237+
setup.schemaVersion === 1
238+
? {
239+
...authority.target,
240+
operator: createRuntimeHostLegacyPosixOperatorCommand(
241+
join(authority.deploymentRoot, 'operator'),
242+
),
243+
}
244+
: authority.target;
245+
const managed = managedLifecycle(target);
235246
await writeDocument(lifecyclePath, managed);
236247
return { kind: 'managed', managed };
237248
};
@@ -472,7 +483,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
472483
| { readonly kind: 'complete'; readonly managed: LocalServiceManaged }
473484
> => {
474485
const pending = pendingSetup(legacy);
475-
const authority = await adoptCommittedSetup(pending);
486+
const authority = await adoptCommittedSetup(legacy);
476487
if (authority.kind === 'managed') {
477488
return { kind: 'complete', managed: authority.managed };
478489
}
@@ -487,7 +498,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
487498
);
488499
if (retirement.kind === 'active_tasks') return { kind: 'active_tasks' };
489500
if (retirement.kind === 'not_owned') {
490-
const raced = await adoptCommittedSetup(pending);
501+
const raced = await adoptCommittedSetup(legacy);
491502
if (raced.kind === 'managed') {
492503
return { kind: 'complete', managed: raced.managed };
493504
}
@@ -857,7 +868,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
857868
const pending = await readLifecycle(lifecyclePath, input.rootPath, input.rootId);
858869
if (pending?.state !== 'setupPending' && pending?.state !== 'handoff') return false;
859870
const current = pendingSetup(pending);
860-
const authority = await adoptCommittedSetup(current);
871+
const authority = await adoptCommittedSetup(pending);
861872
if (authority.kind === 'absent') return false;
862873
if (authority.kind === 'managed') return true;
863874
if (pending.state === 'handoff') await writeDocument(lifecyclePath, current);
@@ -882,7 +893,7 @@ export function createDesktopLocalRuntimeHostRemoteAccess(input: {
882893
return;
883894
}
884895
if (lifecycle.state === 'handoff' || lifecycle.state === 'setupPending') {
885-
const committed = await adoptCommittedSetup(pendingSetup(lifecycle));
896+
const committed = await adoptCommittedSetup(lifecycle);
886897
if (committed.kind === 'managed') return;
887898
if (!supported(input.directPeerAvailable)) return;
888899
if (lifecycle.state === 'handoff') await recoverLegacyHandoff(lifecycle);

0 commit comments

Comments
 (0)