Skip to content

Commit 545b6d4

Browse files
only21milclaude
andcommitted
fix(server): collect host summaries before agent readiness takes the lock
Agent readiness read every host's summary while holding the shared lifecycle lock, so a slow summary on one host held up lifecycle work on the others. Collect the summaries first, as refresh already does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e35f437 commit 545b6d4

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,38 @@ it.effect("starts other hosts while one host is still starting", () =>
197197
}).pipe(Effect.provide(ServerSettings.layerTest({ enableDeviceSupport: true }))),
198198
);
199199

200+
it.effect("reads host summaries outside the lifecycle lock when agent tools start", () =>
201+
Effect.gen(function* () {
202+
const summaryEntered = yield* Deferred.make<void>();
203+
const finishSummary = yield* Deferred.make<void>();
204+
let pauseSummary = false;
205+
const { host: agentHost } = yield* pausedHost("ensureReady", "agent");
206+
const { host: otherHost } = yield* pausedHost("ensureAgentReady", "other");
207+
const summary = Effect.suspend(() =>
208+
pauseSummary
209+
? Deferred.succeed(summaryEntered, undefined).pipe(
210+
Effect.andThen(Deferred.await(finishSummary)),
211+
Effect.andThen(otherHost.summary),
212+
)
213+
: otherHost.summary,
214+
);
215+
const hosts = new Map([agentHost, { ...otherHost, summary }].map((host) => [host.id, host]));
216+
const service = yield* DeviceService.makeWithHosts(hosts).pipe(
217+
Effect.provide(NodeCrypto.layer),
218+
);
219+
pauseSummary = true;
220+
const agent = yield* service.agentReadinessIfSupported("agent").pipe(Effect.forkChild);
221+
yield* Deferred.await(summaryEntered);
222+
expect((yield* service.readiness("other")).hostId).toBe("other");
223+
yield* Deferred.succeed(finishSummary, undefined);
224+
expect((yield* Fiber.join(agent))?.hostId).toBe("agent");
225+
}).pipe(
226+
Effect.provide(
227+
ServerSettings.layerTest({ enableDeviceSupport: true, enableAgentDeviceAccess: true }),
228+
),
229+
),
230+
);
231+
200232
it.effect("stops a start that fails after device support was turned off before it began", () =>
201233
Effect.gen(function* () {
202234
const summaryEntered = yield* Deferred.make<void>();

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,10 @@ export const makeWithHosts = Effect.fn("DeviceService.makeWithHosts")(function*
614614
),
615615
stopIfRevoked(host, true),
616616
);
617+
const hostSummaries = yield* Effect.forEach(hosts.values(), (candidate) => candidate.summary);
617618
return yield* lifecycleLock.withPermit(
618619
Effect.gen(function* () {
619620
if (!(yield* confirmStarted(host, true))) return null;
620-
const hostSummaries = yield* Effect.forEach(
621-
hosts.values(),
622-
(candidate) => candidate.summary,
623-
);
624621
yield* publish((state) => ({ ...state, hosts: hostSummaries }));
625622
yield* setHostStatus(host.id, { status: "ready" });
626623
return { hostId: host.id, ...ready };

0 commit comments

Comments
 (0)