Skip to content

Commit 00b483d

Browse files
fix(devices): keep per-host status aligned with consent changes
1 parent 24c0e6f commit 00b483d

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎apps/server/src/device/DeviceMultiHost.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,13 @@ it.effect("keeps hosts independent when serials collide and another host fails",
7474
expect(state.sessions.map((session) => session.hostId)).toEqual(["b"]);
7575
expect(state.hostStatuses.a?.status).toBe("ready");
7676
expect(state.hostStatuses.offline?.status).toBe("failed");
77-
}).pipe(Effect.provide(ServerSettingsService.layerTest({ enableDeviceSupport: true }))),
77+
yield* service.agentReadinessIfSupported("b");
78+
expect((yield* service.state).hostStatuses.b?.status).toBe("ready");
79+
yield* service.configure({ enabled: false });
80+
expect((yield* service.state).hostStatuses).toEqual({});
81+
}).pipe(
82+
Effect.provide(
83+
ServerSettingsService.layerTest({ enableDeviceSupport: true, enableAgentDeviceAccess: true }),
84+
),
85+
),
7886
);

‎apps/server/src/device/DeviceService.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,18 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
246246
const summary = yield* host.summary;
247247
if (!summary.platforms.some((platform) => platform.available)) return null;
248248
const ready = yield* host
249-
.ensureAgentReady((phase) =>
250-
publish((state) => ({ ...state, hostStatus: phase, hostStatusDetail: undefined })).pipe(
251-
Effect.asVoid,
252-
),
253-
)
249+
.ensureAgentReady((phase) => setHostStatus(host.id, { status: phase }).pipe(Effect.asVoid))
254250
.pipe(
255251
Effect.tapError((error) =>
256-
publish((state) => ({
257-
...state,
258-
hostStatus: "failed",
259-
hostStatusDetail: error.message,
260-
})),
252+
setHostStatus(host.id, { status: "failed", detail: error.message }),
261253
),
262254
Effect.mapError(
263255
(error) => new DeviceHostUnavailableError({ hostId: host.id, reason: error.message }),
264256
),
265257
);
266258
const hostSummaries = yield* Effect.forEach(hosts.values(), (candidate) => candidate.summary);
267-
yield* publish((state) => ({ ...state, hosts: hostSummaries, hostStatus: "ready" }));
259+
yield* publish((state) => ({ ...state, hosts: hostSummaries }));
260+
yield* setHostStatus(host.id, { status: "ready" });
268261
return { hostId: host.id, ...ready };
269262
}, lifecycleLock.withPermit);
270263

@@ -354,6 +347,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
354347
return yield* publish((state) => ({
355348
...state,
356349
hosts: hostSummaries,
350+
...(ready.hostId === LOCAL_DEVICE_HOST_ID ? { hostStatusDetail: detail } : {}),
357351
devices: [
358352
...state.devices.filter((device) => device.hostId !== ready.hostId),
359353
...devices,
@@ -421,6 +415,7 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
421415
...state,
422416
hostStatus: nextEnabled ? "idle" : "disabled",
423417
hostStatusDetail: undefined,
418+
hostStatuses: {},
424419
devices: nextEnabled ? state.devices : [],
425420
sessions: nextEnabled ? state.sessions : [],
426421
bootingDevices: nextEnabled ? state.bootingDevices : [],

0 commit comments

Comments
 (0)