The best way to control Claude Code, Codex and more from any computer or phone
fix(client-runtime): server updates stop waiting 32 minutes when the host returns without this update's outcome (#27275)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 04:37 UTC
a74ee4cc7c0ee9729f58dfff6cc2a118692cf8ea
3 files changed
+378
-39
packages/client-runtime/src/rpc/client.ts
+19
-12
@@ -136,7 +136,7 @@ export type EnvironmentRpcStreamFailure<TTag extends EnvironmentStreamRpcTag> =
136
? E
137
: never;
138
139
-const currentSession = Effect.fn("EnvironmentRpc.currentSession")(function* () {
139
+export const currentSession = Effect.fn("EnvironmentRpc.currentSession")(function* () {
140
const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
141
return yield* SubscriptionRef.get(supervisor.session).pipe(
142
Effect.flatMap(
@@ -194,7 +194,7 @@ const authorizeRequest = Effect.fn("EnvironmentRpc.authorize")(function* (
194
yield* guard.authorize(supervisor.target.environmentId, method, input);
195
});
196
197
-const requestInSession = Effect.fn("EnvironmentRpc.request")(function* <
197
+export const requestInSession = Effect.fn("EnvironmentRpc.request")(function* <
198
TTag extends EnvironmentUnaryRpcTag,
199
>(session: RpcSession, tag: TTag, input: EnvironmentRpcInput<TTag>) {
200
const supervisor = yield* EnvironmentSupervisor.EnvironmentSupervisor;
@@ -234,16 +234,23 @@ export function runStreamGuarded<TTag extends EnvironmentStreamCommandRpcTag>(
234
EnvironmentSupervisor.EnvironmentSupervisor
235
> {
236
return Stream.unwrap(
237
- authorizeRequest(tag, input).pipe(
238
- Effect.andThen(currentSession()),
239
- Effect.map((session) => {
240
- const method = session.client[tag] as (
241
- input: EnvironmentRpcInput<TTag>,
242
- ) => Stream.Stream<EnvironmentRpcStreamValue<TTag>, EnvironmentRpcStreamFailure<TTag>>;
243
- return method(input);
244
- }),
245
- ),
246
- ).pipe(
237
+ currentSession().pipe(Effect.map((session) => runStreamInSession(session, tag, input))),
238
+ );
239
+}
240
+
241
+export function runStreamInSession<TTag extends EnvironmentStreamCommandRpcTag>(
242
+ session: RpcSession,
243
+ tag: TTag,
244
+ input: EnvironmentRpcInput<TTag>,
245
+): Stream.Stream<
246
+ EnvironmentRpcStreamValue<TTag>,
247
+ EnvironmentRpcStreamFailure<TTag> | EnvironmentAuthorizationError,
248
+ EnvironmentSupervisor.EnvironmentSupervisor
249
+> {
250
+ const method = session.client[tag] as (
251
+ input: EnvironmentRpcInput<TTag>,
252
+ ) => Stream.Stream<EnvironmentRpcStreamValue<TTag>, EnvironmentRpcStreamFailure<TTag>>;
253
+ return Stream.unwrap(authorizeRequest(tag, input).pipe(Effect.map(() => method(input)))).pipe(
254
Stream.withSpan("EnvironmentRpc.runStream", {
255
attributes: { "rpc.method": tag },
256
}),
packages/client-runtime/src/state/server.test.ts
+290
-20
@@ -10,12 +10,15 @@ import {
10
UsageLimitSourceId,
11
type ServerConfig,
12
type ServerConfigStreamEvent,
13
+ type ServerLifecycleStreamEvent,
14
type ServerLifecycleWelcomePayload,
15
+ type ServerSelfUpdateOutcome,
16
WS_METHODS,
17
} from "@t3tools/contracts";
18
import { describe, expect, it } from "@effect/vitest";
19
import { vi } from "vite-plus/test";
20
import * as Cause from "effect/Cause";
21
+import * as Clock from "effect/Clock";
22
import * as Deferred from "effect/Deferred";
23
import * as Duration from "effect/Duration";
24
import * as Effect from "effect/Effect";
@@ -25,6 +28,7 @@ import * as Layer from "effect/Layer";
28
import * as Option from "effect/Option";
29
import * as Queue from "effect/Queue";
30
import * as Ref from "effect/Ref";
31
+import * as Scheduler from "effect/Scheduler";
32
import * as Schema from "effect/Schema";
33
import * as Stream from "effect/Stream";
34
import * as SubscriptionRef from "effect/SubscriptionRef";
@@ -48,7 +52,6 @@ import type { RpcSession } from "../rpc/session.ts";
52
import {
53
applyServerWelcomeEvent,
54
createServerEnvironmentAtoms,
51
- serverUpdateStateAtom,
55
makeEnvironmentServerWelcomeState,
56
makeEnvironmentServerConfigState,
57
isLegacyUpdateHandoffLoss,
@@ -61,6 +64,7 @@ import {
64
resolveServerWelcomeState,
65
resolveServerUpdateProgressResult,
66
serverUpdateStateForProgressEvent,
67
+ serverUpdateStateAtom,
68
serverUpdateStateForServerVersion,
69
validateServerUpdateReadyEvent,
70
waitForNextEnvironmentReconnect,
@@ -254,22 +258,37 @@ describe("accepted server update recovery", () => {
258
capabilities: { serverSelfUpdate: method, serverSelfUpdateProgress: true },
259
},
260
} as ServerConfig;
261
+ const ready = (serverVersion: string) =>
262
+ ({
263
+ version: 1,
264
+ sequence: 1,
265
+ type: "ready",
266
+ payload: { at: "2026-09-01T00:00:00.000Z", environment: { serverVersion } },
267
+ }) as Parameters<typeof matchesServerUpdateReadyEvent>[1];
268
+ let requested = false;
269
const client = {
270
[WS_METHODS.subscribeServerConfig]: () => Stream.never,
271
+ // Before the request, a boot-service update reads the accepting server's ready.
272
[WS_METHODS.subscribeServerLifecycle]: () =>
260
- Stream.fromEffect(Deferred.succeed(observing, undefined)).pipe(
261
- Stream.drain,
262
- Stream.concat(Stream.fromQueue(readyEvents)),
263
- Stream.tap((event) =>
264
- event.payload.environment.serverVersion === "0.0.30"
265
- ? Deferred.succeed(oldReadyObserved, undefined)
266
- : Effect.void,
267
- ),
268
- ),
273
+ requested
274
+ ? Stream.fromEffect(Deferred.succeed(observing, undefined)).pipe(
275
+ Stream.drain,
276
+ Stream.concat(Stream.fromQueue(readyEvents)),
277
+ Stream.tap((event) =>
278
+ event.payload.environment.serverVersion === "0.0.30"
279
+ ? Deferred.succeed(oldReadyObserved, undefined)
280
+ : Effect.void,
281
+ ),
282
+ )
283
+ : Stream.make(ready("0.0.30")).pipe(Stream.concat(Stream.never)),
284
[WS_METHODS.serverUpdateServerWithProgress]: () =>
270
- (loss === "no_progress"
271
- ? Stream.empty
272
- : Stream.make({ type: "progress" as const, stage: "downloading" as const })
285
+ Stream.unwrap(
286
+ Effect.sync(() => {
287
+ requested = true;
288
+ return loss === "no_progress"
289
+ ? Stream.empty
290
+ : Stream.make({ type: "progress" as const, stage: "downloading" as const });
291
+ }),
292
).pipe(
293
Stream.concat(
294
Stream.fromEffect(
@@ -363,13 +382,6 @@ describe("accepted server update recovery", () => {
382
status: "running",
383
stage: "resuming",
384
});
366
- const ready = (serverVersion: string) =>
367
- ({
368
- version: 1,
369
- sequence: 1,
370
- type: "ready",
371
- payload: { at: "2026-09-01T00:00:00.000Z", environment: { serverVersion } },
372
- }) as Parameters<typeof matchesServerUpdateReadyEvent>[1];
385
yield* Queue.offer(readyEvents, ready("0.0.30"));
386
yield* Deferred.await(oldReadyObserved);
387
expect(registry.get(serverUpdateStateAtom(TARGET.environmentId))).toMatchObject({
@@ -778,6 +790,20 @@ describe("server state projection", () => {
790
validateServerUpdateReadyEvent(result, ready("rolled-back")),
791
);
792
expect(rollback.message).toBe("prepared-timeout");
793
+ const foreign = ready("rolled-back");
794
+ const foreignRollback = yield* Effect.flip(
795
+ validateServerUpdateReadyEvent(result, {
796
+ ...foreign,
797
+ payload: {
798
+ ...foreign.payload,
799
+ updateOutcome: { ...foreign.payload.updateOutcome!, id: "manual-1" },
800
+ },
801
+ }),
802
+ );
803
+ expect(foreignRollback).toMatchObject({
804
+ status: "failed",
805
+ reason: "The service launcher resumed without committing the requested server version.",
806
+ });
807
}),
808
);
809
@@ -1315,6 +1341,250 @@ describe("server state projection", () => {
1341
);
1342
});
1343
1344
+describe("launcher update resume", () => {
1345
+ const UPDATE_CONFIG = {
1346
+ ...CONFIG,
1347
+ environment: {
1348
+ serverVersion: "0.0.30",
1349
+ capabilities: { serverSelfUpdate: "boot-service", serverSelfUpdateProgress: true },
1350
+ },
1351
+ } as unknown as ServerConfig;
1352
+
1353
+ const ready = (at: string, serverVersion: string, updateOutcome?: ServerSelfUpdateOutcome) =>
1354
+ ({
1355
+ version: 1,
1356
+ sequence: 1,
1357
+ type: "ready",
1358
+ payload: { at, environment: { serverVersion }, ...(updateOutcome ? { updateOutcome } : {}) },
1359
+ }) as ServerLifecycleStreamEvent;
1360
+ const after = (delay: Duration.Input, event: ServerLifecycleStreamEvent) =>
1361
+ Stream.fromEffect(Effect.as(Effect.sleep(delay), event));
1362
+ const committed = (id: string, fromVersion: string, targetVersion: string) => ({
1363
+ id,
1364
+ fromVersion,
1365
+ targetVersion,
1366
+ status: "committed" as const,
1367
+ });
1368
+ const ACCEPTING = ready("2026-08-01T00:00:00.000Z", "0.0.30");
1369
+ const REPLACEMENT = ready("2026-08-01T00:05:00.000Z", "0.0.31");
1370
+
1371
+ // Lifecycle subscriptions opened before the update is acknowledged reach the accepting
1372
+ // process; later ones reach whatever the host has become.
1373
+ const launchUpdate = Effect.fn("ServerUpdateTest.launchUpdate")(function* (host: {
1374
+ readonly accepting: Stream.Stream<ServerLifecycleStreamEvent>;
1375
+ readonly resumed: Stream.Stream<ServerLifecycleStreamEvent>;
1376
+ readonly reconnectAfterBaseline?: boolean;
1377
+ }) {
1378
+ const started = yield* Deferred.make<void>();
1379
+ const resumeSubscribed = yield* Deferred.make<void>();
1380
+ let acknowledged = false;
1381
+ const client = {
1382
+ [WS_METHODS.subscribeServerConfig]: () => Stream.never,
1383
+ [WS_METHODS.serverUpdateServerWithProgress]: () =>
1384
+ Stream.fromEffect(
1385
+ Deferred.succeed(started, undefined).pipe(
1386
+ Effect.andThen(
1387
+ Effect.sync(() => {
1388
+ acknowledged = true;
1389
+ return {
1390
+ type: "complete" as const,
1391
+ result: {
1392
+ targetVersion: "0.0.31",
1393
+ method: "boot-service" as const,
1394
+ updateId: "update-1",
1395
+ },
1396
+ };
1397
+ }),
1398
+ ),
1399
+ ),
1400
+ ),
1401
+ [WS_METHODS.subscribeServerLifecycle]: () => {
1402
+ const events = acknowledged
1403
+ ? Deferred.succeed(resumeSubscribed, undefined).pipe(Effect.as(host.resumed))
1404
+ : Effect.succeed(host.accepting);
1405
+ const reconnect =
1406
+ !acknowledged && host.reconnectAfterBaseline === true
1407
+ ? SubscriptionRef.set(supervisor.session, Option.some(updateSession()))
1408
+ : Effect.void;
1409
+ return Stream.unwrap(
1410
+ Deferred.succeed(started, undefined).pipe(Effect.andThen(events)),
1411
+ ).pipe(Stream.concat(Stream.never), Stream.ensuring(reconnect));
1412
+ },
1413
+ } as unknown as WsRpcProtocolClient;
1414
+ const updateSession = (): RpcSession => ({
1415
+ ...session(client),
1416
+ initialConfig: Effect.succeed(UPDATE_CONFIG),
1417
+ });
1418
+ const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
1419
+ target: TARGET,
1420
+ state: yield* SubscriptionRef.make(AVAILABLE_CONNECTION_STATE),
1421
+ session: yield* SubscriptionRef.make(Option.some(updateSession())),
1422
+ prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
1423
+ connect: Effect.void,
1424
+ disconnect: Effect.void,
1425
+ retryNow: Effect.void,
1426
+ } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
1427
+ type Environments = EnvironmentRegistry.EnvironmentRegistry["Service"];
1428
+ const run: Environments["run"] = (_environmentId, effect) =>
1429
+ Effect.provideService(effect, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
1430
+ const runStream: Environments["runStream"] = (_environmentId, stream) =>
1431
+ Stream.provideService(stream, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
1432
+ const environments = EnvironmentRegistry.EnvironmentRegistry.of({
1433
+ run,
1434
+ runStream,
1435
+ followStream: runStream,
1436
+ stateChanges: () => Stream.never,
1437
+ retryNow: () => Effect.void,
1438
+ } as unknown as Environments);
1439
+ const cache = Persistence.EnvironmentCacheStore.of({
1440
+ loadShell: () => Effect.succeedNone,
1441
+ saveShell: () => Effect.void,
1442
+ loadThread: () => Effect.succeedNone,
1443
+ saveThread: () => Effect.void,
1444
+ removeThread: () => Effect.void,
1445
+ loadServerConfig: () => Effect.succeedNone,
1446
+ saveServerConfig: () => Effect.void,
1447
+ loadVcsRefs: () => Effect.succeedNone,
1448
+ saveVcsRefs: () => Effect.void,
1449
+ removeVcsRefs: () => Effect.void,
1450
+ clearVcsRefs: () => Effect.void,
1451
+ clear: () => Effect.void,
1452
+ });
1453
+ // Share the test clock so the command's timers and the host's restart run on TestClock.
1454
+ const runtime = Atom.runtime(
1455
+ Layer.mergeAll(
1456
+ Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environments),
1457
+ Layer.succeed(Persistence.EnvironmentCacheStore, cache),
1458
+ Layer.succeed(Clock.Clock, yield* Clock.Clock),
1459
+ Layer.succeed(Scheduler.Scheduler, yield* Scheduler.Scheduler),
1460
+ ),
1461
+ );
1462
+ const initialConfigValueAtom = Atom.make(UPDATE_CONFIG);
1463
+ const atoms = createServerEnvironmentAtoms(runtime, {
1464
+ initialConfigValueAtom: () => initialConfigValueAtom,
1465
+ });
1466
+ const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) =>
1467
+ Effect.sync(() => registry.dispose()),
1468
+ );
1469
+ const updateStateAtom = serverUpdateStateAtom(TARGET.environmentId);
1470
+ yield* AtomRegistry.mount(registry, updateStateAtom);
1471
+
1472
+ yield* Effect.promise(() =>
1473
+ atoms.updateServer.run(registry, {
1474
+ environmentId: TARGET.environmentId,
1475
+ input: { targetVersion: "0.0.31" },
1476
+ }),
1477
+ ).pipe(Effect.forkScoped);
1478
+ return {
1479
+ // The host saw its first call: the update request or a lifecycle subscription.
1480
+ started: Deferred.await(started),
1481
+ resumeSubscribed: Deferred.await(resumeSubscribed),
1482
+ state: () => registry.get(updateStateAtom),
1483
+ };
1484
+ });
1485
+
1486
+ const UNCOMMITTED_RESUME = {
1487
+ status: "failed",
1488
+ stage: "resuming",
1489
+ fromVersion: "0.0.30",
1490
+ targetVersion: "0.0.31",
1491
+ message: "The service launcher resumed without committing the requested server version.",
1492
+ };
1493
+
1494
+ it.effect("fails promptly when a server the launcher did not start comes back", () =>
1495
+ Effect.scoped(
1496
+ Effect.gen(function* () {
1497
+ const update = yield* launchUpdate({
1498
+ accepting: Stream.make(ACCEPTING),
1499
+ resumed: after("1 second", ACCEPTING).pipe(Stream.concat(after("1 minute", REPLACEMENT))),
1500
+ });
1501
+ yield* update.resumeSubscribed;
1502
+
1503
+ yield* TestClock.adjust("1 second");
1504
+ expect(update.state()).toMatchObject({ status: "running", stage: "resuming" });
1505
+ yield* TestClock.adjust("1 minute");
1506
+ expect(update.state()).toEqual(UNCOMMITTED_RESUME);
1507
+ }),
1508
+ ),
1509
+ );
1510
+
1511
+ it.effect(
1512
+ "fails promptly when the accepting server's replay arrives after a quick acknowledgement",
1513
+ () =>
1514
+ Effect.scoped(
1515
+ Effect.gen(function* () {
1516
+ const update = yield* launchUpdate({
1517
+ accepting: after("3 seconds", ACCEPTING),
1518
+ resumed: after("1 second", REPLACEMENT),
1519
+ });
1520
+ yield* update.started;
1521
+ yield* TestClock.adjust("3 seconds");
1522
+ yield* update.resumeSubscribed;
1523
+
1524
+ yield* TestClock.adjust("1 minute");
1525
+ expect(update.state()).toEqual(UNCOMMITTED_RESUME);
1526
+ }),
1527
+ ),
1528
+ );
1529
+
1530
+ it.effect(
1531
+ "waits for this update's outcome when a reconnect lands between the baseline and the request",
1532
+ () =>
1533
+ Effect.scoped(
1534
+ Effect.gen(function* () {
1535
+ const update = yield* launchUpdate({
1536
+ reconnectAfterBaseline: true,
1537
+ accepting: Stream.make(ACCEPTING),
1538
+ // The process that accepted the update over the new session replays its own ready first.
1539
+ resumed: after("1 second", ready("2026-08-01T00:01:00.000Z", "0.0.30")).pipe(
1540
+ Stream.concat(
1541
+ after(
1542
+ "1 minute",
1543
+ ready(
1544
+ "2026-08-01T00:05:00.000Z",
1545
+ "0.0.31",
1546
+ committed("update-1", "0.0.30", "0.0.31"),
1547
+ ),
1548
+ ),
1549
+ ),
1550
+ ),
1551
+ });
1552
+ yield* update.resumeSubscribed;
1553
+
1554
+ yield* TestClock.adjust("1 second");
1555
+ expect(update.state()).toMatchObject({ status: "running", stage: "resuming" });
1556
+ yield* TestClock.adjust("1 minute");
1557
+ expect(update.state()).toMatchObject({ status: "idle" });
1558
+ }),
1559
+ ),
1560
+ );
1561
+
1562
+ it.effect(
1563
+ "sends the update without a baseline when the accepting server never replays ready",
1564
+ () =>
1565
+ Effect.scoped(
1566
+ Effect.gen(function* () {
1567
+ const update = yield* launchUpdate({
1568
+ accepting: Stream.never,
1569
+ resumed: after(
1570
+ "1 second",
1571
+ ready(
1572
+ "2026-08-01T00:05:00.000Z",
1573
+ "0.0.31",
1574
+ committed("update-1", "0.0.30", "0.0.31"),
1575
+ ),
1576
+ ),
1577
+ });
1578
+ yield* update.started;
1579
+
1580
+ yield* TestClock.adjust("5 seconds");
1581
+ yield* TestClock.adjust("1 second");
1582
+ expect(update.state()).toMatchObject({ status: "idle" });
1583
+ }),
1584
+ ),
1585
+ );
1586
+});
1587
+
1588
describe("provider setup commands", () => {
1589
it.effect("starts installs for two instances in one environment separately", () =>
1590
Effect.gen(function* () {
packages/client-runtime/src/state/server.ts
+69
-7
@@ -43,10 +43,13 @@ import { safeErrorLogAttributes } from "../errors/safeLog.ts";
43
import * as Persistence from "../platform/persistence.ts";
44
import { runCachePersistence } from "./cachePersistence.ts";
45
import {
46
+ currentSession,
47
isRpcClientError,
48
request,
49
requestGuarded,
50
+ requestInSession,
51
runStream,
52
+ runStreamInSession,
53
subscribe,
54
subscribeDynamicWithSession,
55
type EnvironmentRpcInput,
@@ -134,6 +137,8 @@ export class ServerUpdateTerminalError extends Schema.TaggedError<ServerUpdateTe
137
// Covers the service launcher's 30-minute trial deadline (PREPARED_TIMEOUT_MS)
138
// and a final restart of the previous version when the trial rolls back.
139
const SERVER_UPDATE_RESUME_TIMEOUT = Duration.minutes(32);
140
+// A live host replays its ready on subscribe within a round trip; past this, update without a baseline.
141
+const SERVER_UPDATE_ACCEPTING_READY_TIMEOUT = Duration.seconds(5);
142
143
export function matchesServerUpdateReadyEvent(
144
result: ServerSelfUpdateResult,
@@ -144,13 +149,20 @@ export function matchesServerUpdateReadyEvent(
149
: event.payload.updateOutcome?.id === result.updateId;
150
}
151
152
+/**
153
+ * `acceptedAt` is the `ready.at` of the process that accepted the update. A launcher host
154
+ * that comes back as any other process ends the wait, so validation can reject a missing
155
+ * or foreign outcome instead of timing out.
156
+ */
157
export function matchesServerUpdateResumeEvent(
158
result: ServerSelfUpdateResult,
159
event: ServerLifecycleStreamReadyEvent,
160
+ acceptedAt?: string,
161
): boolean {
162
return (
163
(result.method === "desktop-app" && result.desktopUpdateToken !== undefined) ||
153
- matchesServerUpdateReadyEvent(result, event)
164
+ matchesServerUpdateReadyEvent(result, event) ||
165
+ (result.updateId !== undefined && acceptedAt !== undefined && event.payload.at !== acceptedAt)
166
);
167
}
168
@@ -159,10 +171,10 @@ export function validateServerUpdateReadyEvent(
171
event: ServerLifecycleStreamReadyEvent,
172
): Effect.Effect<void, ServerUpdateTerminalError> {
173
if (result.updateId === undefined) return Effect.void;
162
- const outcome = event.payload.updateOutcome;
174
+ const reported = event.payload.updateOutcome;
175
+ const outcome = reported?.id === result.updateId ? reported : undefined;
176
if (
164
- outcome?.id === result.updateId &&
165
- outcome.status === "committed" &&
177
+ outcome?.status === "committed" &&
178
outcome.targetVersion === result.targetVersion &&
179
event.payload.environment.serverVersion === result.targetVersion
180
) {
@@ -859,6 +871,17 @@ export function createServerEnvironmentAtoms<R, E>(
871
const desktopCommitStarting = yield* Deferred.make<void>();
872
const desktopReconnectObserverArmed = yield* Deferred.make<void>();
873
const desktopReconnected = yield* Deferred.make<void>();
874
+ let accepting: { readonly session: RpcSession; readonly at: string } | undefined;
875
+ let acceptedAt: string | undefined;
876
+ // The baseline only describes the accepting process if the request rides its session,
877
+ // so the session read here is the one the request is sent on.
878
+ const acceptingSession = currentSession().pipe(
879
+ Effect.tap((session) =>
880
+ Effect.sync(() => {
881
+ acceptedAt = accepting?.session === session ? accepting.at : undefined;
882
+ }),
883
+ ),
884
+ );
885
yield* Deferred.await(desktopCommitStarting).pipe(
886
Effect.andThen(
887
environmentRegistry.stateChanges(target.environmentId).pipe(
@@ -885,6 +908,28 @@ export function createServerEnvironmentAtoms<R, E>(
908
fromVersion,
909
targetVersion,
910
});
911
+ // Only launcher updates carry an updateId. Read before the request so a ready from
912
+ // after it can never pose as the accepting process.
913
+ if (currentConfig?.environment.capabilities.serverSelfUpdate === "boot-service") {
914
+ accepting = yield* environmentRegistry
915
+ .followStream(
916
+ target.environmentId,
917
+ subscribeDynamicWithSession(WS_METHODS.subscribeServerLifecycle, () =>
918
+ Effect.succeed({}),
919
+ ),
920
+ )
921
+ .pipe(
922
+ Stream.filter(
923
+ (entry): entry is readonly [RpcSession, ServerLifecycleStreamReadyEvent] =>
924
+ entry[1].type === "ready",
925
+ ),
926
+ Stream.map(([session, ready]) => ({ session, at: ready.payload.at })),
927
+ Stream.runHead,
928
+ Effect.timeoutOption(SERVER_UPDATE_ACCEPTING_READY_TIMEOUT),
929
+ Effect.map((head) => Option.getOrUndefined(Option.flatten(head))),
930
+ Effect.orElseSucceed(() => undefined),
931
+ );
932
+ }
933
934
const supportsProgress =
935
currentConfig?.environment.capabilities.serverSelfUpdateProgress === true;
@@ -897,7 +942,17 @@ export function createServerEnvironmentAtoms<R, E>(
942
const streamExit = yield* environmentRegistry
943
.runStream(
944
target.environmentId,
900
- runStream(WS_METHODS.serverUpdateServerWithProgress, target.input),
945
+ Stream.unwrap(
946
+ acceptingSession.pipe(
947
+ Effect.map((session) =>
948
+ runStreamInSession(
949
+ session,
950
+ WS_METHODS.serverUpdateServerWithProgress,
951
+ target.input,
952
+ ),
953
+ ),
954
+ ),
955
+ ),
956
)
957
.pipe(
958
Stream.runForEach((event) =>
@@ -937,7 +992,14 @@ export function createServerEnvironmentAtoms<R, E>(
992
: yield* Effect.gen(function* () {
993
const selfUpdateMethod = currentConfig?.environment.capabilities.serverSelfUpdate;
994
const exit = yield* environmentRegistry
940
- .run(target.environmentId, request(WS_METHODS.serverUpdateServer, target.input))
995
+ .run(
996
+ target.environmentId,
997
+ acceptingSession.pipe(
998
+ Effect.flatMap((session) =>
999
+ requestInSession(session, WS_METHODS.serverUpdateServer, target.input),
1000
+ ),
1001
+ ),
1002
+ )
1003
.pipe(Effect.exit);
1004
if (Exit.isSuccess(exit)) {
1005
return exit.value;
@@ -1014,7 +1076,7 @@ export function createServerEnvironmentAtoms<R, E>(
1076
.pipe(
1077
Stream.filter(
1078
(event): event is ServerLifecycleStreamReadyEvent =>
1017
- event.type === "ready" && matchesServerUpdateResumeEvent(result, event),
1079
+ event.type === "ready" && matchesServerUpdateResumeEvent(result, event, acceptedAt),
1080
),
1081
Stream.runHead,
1082
Effect.timeoutOption(SERVER_UPDATE_RESUME_TIMEOUT),