Skip to content

Commit 67e3a53

Browse files
only21milclaude
andcommitted
fix(server): agent readiness no longer brings back a host removed while summaries ran
Agent readiness reads host summaries before it takes the lifecycle lock. If a host was removed or replaced in that window, publishing that snapshot put the old host back in the list. Publish it only when the hosts are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 95da7ce commit 67e3a53

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@ it.effect("reads host summaries outside the lifecycle lock when agent tools star
220220
const agent = yield* service.agentReadinessIfSupported("agent").pipe(Effect.forkChild);
221221
yield* Deferred.await(summaryEntered);
222222
expect((yield* service.readiness("other")).hostId).toBe("other");
223+
yield* service.withLifecycleLock(
224+
Effect.sync(() => hosts.delete("other")).pipe(Effect.andThen(service.refreshHosts)),
225+
);
223226
yield* Deferred.succeed(finishSummary, undefined);
224227
expect((yield* Fiber.join(agent))?.hostId).toBe("agent");
228+
expect((yield* service.state).hosts.map((summary) => summary.id)).toEqual(["agent"]);
225229
}).pipe(
226230
Effect.provide(
227231
ServerSettings.layerTest({ enableDeviceSupport: true, enableAgentDeviceAccess: true }),

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,17 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
623623
),
624624
stopIfRevoked(host, true),
625625
);
626-
const hostSummaries = yield* Effect.forEach(hosts.values(), (candidate) => candidate.summary);
626+
const summarized = [...hosts.values()];
627+
const hostSummaries = yield* Effect.forEach(summarized, (candidate) => candidate.summary);
627628
return yield* lifecycleLock.withPermit(
628629
Effect.gen(function* () {
629630
if (!(yield* confirmStarted(host, true))) return null;
630-
yield* publish((state) => ({ ...state, hosts: hostSummaries }));
631+
// A reconcile while the summaries ran has already published the newer host list.
632+
if (
633+
summarized.length === hosts.size &&
634+
summarized.every((candidate) => hosts.get(candidate.id) === candidate)
635+
)
636+
yield* publish((state) => ({ ...state, hosts: hostSummaries }));
631637
yield* setHostStatus(host.id, { status: "ready" });
632638
return { hostId: host.id, ...ready };
633639
}),

0 commit comments

Comments
 (0)