The best way to control Claude Code, Codex and more from any computer or phone
fix(clients): keep accepted server updates through disconnects (#23532)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 30, 2026 at 15:52 UTC
b1b3c10e249c68d6be86708f453c28b5c226f9b9
4 files changed
+313
-4
packages/client-runtime/src/connection/outdatedHostUpdate.test.ts
+123
-2
@@ -124,6 +124,20 @@ class OutdatedHostSocket {
124
const message = decodeJson(data);
125
if (!isRpcRequest(message)) return;
126
this.requests.push(message);
127
+ if (message.tag === WS_METHODS.serverUpdateServerWithProgress) {
128
+ this.onUpdate();
129
+ queueMicrotask(() =>
130
+ this.emit({
131
+ type: "message",
132
+ data: encodeJson({
133
+ _tag: "Chunk",
134
+ requestId: message.id,
135
+ values: [{ type: "progress", stage: "downloading" }],
136
+ }),
137
+ }),
138
+ );
139
+ return;
140
+ }
141
if (message.tag !== WS_METHODS.serverUpdateServer) return;
142
this.onUpdate();
143
queueMicrotask(() =>
@@ -143,10 +157,10 @@ class OutdatedHostSocket {
157
158
close() {
159
this.readyState = 3;
146
- this.emit({ type: "close" });
160
+ this.emit({ type: "close", code: 1006 });
161
}
162
149
- private emit(event: { readonly type: string; readonly data?: unknown }) {
163
+ private emit(event: { readonly type: string; readonly data?: unknown; readonly code?: number }) {
164
for (const listener of this.listeners.get(event.type) ?? []) listener(event);
165
}
166
}
@@ -314,4 +328,111 @@ describe("updateOutdatedHost", () => {
328
expect(opened).toBe(false);
329
}),
330
);
331
+
332
+ it.effect("resumes an outdated host update after progress transport loss", () =>
333
+ Effect.gen(function* () {
334
+ const blocked = orchestrationProtocolCompatibilityError(descriptor(undefined, "0.0.45"));
335
+ expect(blocked).toMatchObject({ serverUpdateRequired: true });
336
+
337
+ const sockets: Array<OutdatedHostSocket> = [];
338
+ let served: ExecutionEnvironmentDescriptor = {
339
+ ...descriptor(undefined, "0.0.45"),
340
+ capabilities: {
341
+ repositoryIdentity: true,
342
+ serverSelfUpdate: "boot-service",
343
+ serverSelfUpdateProgress: true,
344
+ },
345
+ };
346
+ const entries = yield* SubscriptionRef.make<
347
+ ReadonlyMap<EnvironmentId, ConnectionCatalogEntry>
348
+ >(
349
+ new Map([
350
+ [
351
+ TARGET.environmentId,
352
+ {
353
+ target: TARGET,
354
+ profile: Option.none(),
355
+ enabled: false,
356
+ unsupportedReason: blocked?.message ?? "",
357
+ serverUpdateRequired: true,
358
+ },
359
+ ],
360
+ ]),
361
+ );
362
+ const calls: Array<string> = [];
363
+ const registry = EnvironmentRegistry.EnvironmentRegistry.of({
364
+ entries,
365
+ setCompatibility: (_environmentId: EnvironmentId, error: unknown) =>
366
+ Effect.sync(() => calls.push(`compatibility:${error === null ? "clear" : "block"}`)),
367
+ setEnabled: (_environmentId: EnvironmentId, enabled: boolean) =>
368
+ Effect.sync(() => calls.push(`enabled:${enabled}`)),
369
+ } as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]);
370
+ const resolver = ConnectionResolver.ConnectionResolver.of({
371
+ prepare: () => Effect.die(new Error("The update must bypass the protocol gate.")),
372
+ prepareForUpdate: () =>
373
+ Effect.sync(() => served).pipe(
374
+ Effect.map((current) => ({
375
+ descriptor: current,
376
+ prepared: {
377
+ environmentId: TARGET.environmentId,
378
+ label: TARGET.label,
379
+ httpBaseUrl: TARGET.httpBaseUrl,
380
+ socketUrl: "wss://build.example.test/ws?wsTicket=ticket",
381
+ httpAuthorization: null,
382
+ target: TARGET,
383
+ },
384
+ })),
385
+ ),
386
+ });
387
+ const httpClient = HttpClient.make((request) =>
388
+ Effect.sync(() =>
389
+ HttpClientResponse.fromWeb(request, new Response(encodeDescriptor(served))),
390
+ ),
391
+ );
392
+
393
+ const stages: Array<string> = [];
394
+ const result = yield* updateOutdatedHost(
395
+ TARGET.environmentId,
396
+ { targetVersion: "0.0.46" },
397
+ (stage) =>
398
+ Effect.sync(() => {
399
+ stages.push(stage);
400
+ // Lose the transport only after the consumer has observed progress.
401
+ if (stage === "downloading") sockets[0]?.close();
402
+ }),
403
+ ).pipe(
404
+ Effect.provide(
405
+ Layer.mergeAll(
406
+ Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, registry),
407
+ Layer.succeed(ConnectionResolver.ConnectionResolver, resolver),
408
+ Layer.succeed(
409
+ RelayEnvironmentDiscovery.RelayEnvironmentDiscovery,
410
+ RelayEnvironmentDiscovery.RelayEnvironmentDiscovery.of({
411
+ state: yield* SubscriptionRef.make(
412
+ RelayEnvironmentDiscovery.EMPTY_RELAY_ENVIRONMENT_DISCOVERY_STATE,
413
+ ),
414
+ refresh: Effect.void,
415
+ }),
416
+ ),
417
+ Layer.succeed(HttpClient.HttpClient, httpClient),
418
+ Layer.succeed(Socket.WebSocketConstructor, (url) => {
419
+ const socket = new OutdatedHostSocket(url, () => {
420
+ served = descriptor(ORCHESTRATION_PROTOCOL_VERSION, "0.0.46");
421
+ });
422
+ sockets.push(socket);
423
+ return socket as unknown as globalThis.WebSocket;
424
+ }),
425
+ ),
426
+ ),
427
+ );
428
+
429
+ expect(sockets[0]?.url).not.toContain("orchestrationProtocol");
430
+ expect(sockets[0]?.requests.map((request) => request.tag)).toEqual([
431
+ WS_METHODS.serverUpdateServerWithProgress,
432
+ ]);
433
+ expect(stages).toEqual(["downloading", "resuming"]);
434
+ expect(result.targetVersion).toBe("0.0.46");
435
+ expect(calls).toEqual(["compatibility:clear", "enabled:true"]);
436
+ }),
437
+ );
438
});
packages/client-runtime/src/connection/outdatedHostUpdate.ts
+12
-1
@@ -141,20 +141,31 @@ export const updateOutdatedHost = Effect.fn("clientRuntime.connection.updateOutd
141
capabilities.serverSelfUpdateProgress === true
142
? yield* Effect.gen(function* () {
143
const terminal = yield* Ref.make(Option.none<ServerSelfUpdateResult>());
144
+ let receivedProgress = false;
145
const streamExit = yield* client[WS_METHODS.serverUpdateServerWithProgress](
146
input,
147
).pipe(
148
Stream.runForEach((event) =>
149
event.type === "complete"
150
? Ref.set(terminal, Option.some(event.result))
150
- : onStage(event.stage),
151
+ : Effect.sync(() => {
152
+ receivedProgress = true;
153
+ }).pipe(Effect.andThen(onStage(event.stage))),
154
),
155
Effect.exit,
156
);
157
+ const selfUpdateMethod = capabilities.serverSelfUpdate;
158
+ // Desktop preparation needs its terminal commit token.
159
+ const accepted =
160
+ receivedProgress &&
161
+ (selfUpdateMethod === "boot-service" || selfUpdateMethod === "respawn")
162
+ ? { targetVersion: input.targetVersion, method: selfUpdateMethod }
163
+ : undefined;
164
return yield* resolveServerUpdateProgressResult(
165
input.targetVersion,
166
yield* Ref.get(terminal),
167
streamExit,
168
+ accepted,
169
);
170
})
171
: yield* client[WS_METHODS.serverUpdateServer](input).pipe(
packages/client-runtime/src/state/server.test.ts
+163
@@ -1,5 +1,6 @@
1
import {
2
EnvironmentId,
3
+ ServerSelfUpdateError,
4
ProviderInstanceId,
5
ServerObservability,
6
EnvironmentThemeId,
@@ -16,12 +17,14 @@ import * as Duration from "effect/Duration";
17
import * as Effect from "effect/Effect";
18
import * as Exit from "effect/Exit";
19
import * as Fiber from "effect/Fiber";
20
+import * as Layer from "effect/Layer";
21
import * as Option from "effect/Option";
22
import * as Queue from "effect/Queue";
23
import * as Ref from "effect/Ref";
24
import * as Schema from "effect/Schema";
25
import * as Stream from "effect/Stream";
26
import * as SubscriptionRef from "effect/SubscriptionRef";
27
+import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
28
import * as TestClock from "effect/testing/TestClock";
29
import { RpcClientError } from "effect/rpc";
30
import * as Socket from "effect/socket/Socket";
@@ -32,11 +35,15 @@ import {
35
type PreparedConnection,
36
} from "../connection/model.ts";
37
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
38
+import * as EnvironmentRegistry from "../connection/registry.ts";
39
+import { RpcPermissionGuard } from "../rpc/client.ts";
40
import * as Persistence from "../platform/persistence.ts";
41
import type { WsRpcProtocolClient } from "../rpc/protocol.ts";
42
import type { RpcSession } from "../rpc/session.ts";
43
import {
44
applyServerWelcomeEvent,
45
+ createServerEnvironmentAtoms,
46
+ serverUpdateStateAtom,
47
makeEnvironmentServerWelcomeState,
48
makeEnvironmentServerConfigState,
49
isLegacyUpdateHandoffLoss,
@@ -216,6 +223,162 @@ describe("update restart reconnect nudges", () => {
223
);
224
});
225
226
+describe("accepted server update recovery", () => {
227
+ it.effect.each([
228
+ { loss: "interrupt", resumes: true },
229
+ { loss: "socket", resumes: true },
230
+ { loss: "server_error", resumes: false },
231
+ { loss: "no_progress", resumes: false },
232
+ { loss: "cancel", resumes: false },
233
+ { loss: "socket", method: "respawn", resumes: true },
234
+ { loss: "socket", method: "desktop-managed", resumes: false },
235
+ ] as const)("handles $loss with $method and recovery=$resumes", (scenario) =>
236
+ Effect.gen(function* () {
237
+ const { loss, resumes } = scenario;
238
+ const method = "method" in scenario ? scenario.method : "boot-service";
239
+ const observing = yield* Deferred.make<void>();
240
+ const cancelFiber = yield* Deferred.make<Fiber.Fiber<unknown, unknown>>();
241
+ const oldReadyObserved = yield* Deferred.make<void>();
242
+ const readyEvents =
243
+ yield* Queue.unbounded<Parameters<typeof matchesServerUpdateReadyEvent>[1]>();
244
+ const config = {
245
+ ...CONFIG,
246
+ environment: {
247
+ ...CONFIG.environment,
248
+ serverVersion: "0.0.30",
249
+ capabilities: { serverSelfUpdate: method, serverSelfUpdateProgress: true },
250
+ },
251
+ } as ServerConfig;
252
+ const client = {
253
+ [WS_METHODS.subscribeServerConfig]: () => Stream.never,
254
+ [WS_METHODS.subscribeServerLifecycle]: () =>
255
+ Stream.fromEffect(Deferred.succeed(observing, undefined)).pipe(
256
+ Stream.drain,
257
+ Stream.concat(Stream.fromQueue(readyEvents)),
258
+ Stream.tap((event) =>
259
+ event.payload.environment.serverVersion === "0.0.30"
260
+ ? Deferred.succeed(oldReadyObserved, undefined)
261
+ : Effect.void,
262
+ ),
263
+ ),
264
+ [WS_METHODS.serverUpdateServerWithProgress]: () =>
265
+ (loss === "no_progress"
266
+ ? Stream.empty
267
+ : Stream.make({ type: "progress" as const, stage: "downloading" as const })
268
+ ).pipe(
269
+ Stream.concat(
270
+ Stream.fromEffect(
271
+ loss === "cancel"
272
+ ? Effect.fiber.pipe(
273
+ Effect.flatMap((fiber) => Deferred.succeed(cancelFiber, fiber)),
274
+ Effect.andThen(Effect.never),
275
+ )
276
+ : loss === "interrupt"
277
+ ? Effect.interrupt
278
+ : Effect.fail(
279
+ loss === "server_error"
280
+ ? new ServerSelfUpdateError({
281
+ reason: "Archive verification failed.",
282
+ })
283
+ : new RpcClientError.RpcClientError({
284
+ reason: new Socket.SocketCloseError({ code: 1006 }),
285
+ }),
286
+ ),
287
+ ),
288
+ ),
289
+ ),
290
+ } as unknown as WsRpcProtocolClient;
291
+ const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
292
+ target: TARGET,
293
+ state: yield* SubscriptionRef.make(AVAILABLE_CONNECTION_STATE),
294
+ session: yield* SubscriptionRef.make(Option.some(session(client))),
295
+ prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
296
+ connect: Effect.void,
297
+ disconnect: Effect.void,
298
+ retryNow: Effect.void,
299
+ });
300
+ const run: EnvironmentRegistry.EnvironmentRegistry["Service"]["run"] = (_id, effect) =>
301
+ Effect.provideService(effect, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
302
+ const runStream: EnvironmentRegistry.EnvironmentRegistry["Service"]["runStream"] = (
303
+ _id,
304
+ stream,
305
+ ) => Stream.provideService(stream, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
306
+ const environmentRegistry = EnvironmentRegistry.EnvironmentRegistry.of({
307
+ run,
308
+ runStream,
309
+ followStream: runStream,
310
+ stateChanges: () => Stream.never,
311
+ retryNow: () => Effect.void,
312
+ } as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]);
313
+ const runtime = Atom.runtime(
314
+ Layer.mergeAll(
315
+ Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environmentRegistry),
316
+ Layer.succeed(RpcPermissionGuard, { authorize: () => Effect.void }),
317
+ Layer.succeed(Persistence.EnvironmentCacheStore, {
318
+ loadServerConfig: () => Effect.succeedNone,
319
+ } as unknown as Persistence.EnvironmentCacheStore["Service"]),
320
+ ),
321
+ );
322
+ const atoms = createServerEnvironmentAtoms(runtime, {
323
+ initialConfigValueAtom: () => Atom.make(config),
324
+ });
325
+ const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (value) =>
326
+ Effect.sync(() => value.dispose()),
327
+ );
328
+ const pending = atoms.updateServer.run(registry, {
329
+ environmentId: TARGET.environmentId,
330
+ input: { targetVersion: "0.0.31" },
331
+ });
332
+ if (loss === "cancel") {
333
+ yield* Fiber.interrupt(yield* Deferred.await(cancelFiber));
334
+ const cancelled = yield* Effect.promise(() => pending);
335
+ expect(cancelled._tag).toBe("Failure");
336
+ if (cancelled._tag === "Failure")
337
+ expect(Cause.hasInterruptsOnly(cancelled.cause)).toBe(true);
338
+ expect(registry.get(serverUpdateStateAtom(TARGET.environmentId))).toEqual({
339
+ status: "idle",
340
+ });
341
+ expect(yield* Deferred.isDone(observing)).toBe(false);
342
+ return;
343
+ }
344
+ const first = yield* Effect.raceFirst(
345
+ Effect.promise(() => pending).pipe(Effect.as("settled")),
346
+ Deferred.await(observing).pipe(Effect.as("observing")),
347
+ );
348
+ if (!resumes) {
349
+ expect(first).toBe("settled");
350
+ expect(AsyncResult.isFailure(yield* Effect.promise(() => pending))).toBe(true);
351
+ expect(registry.get(serverUpdateStateAtom(TARGET.environmentId))).toMatchObject({
352
+ status: "failed",
353
+ });
354
+ return;
355
+ }
356
+ expect(first).toBe("observing");
357
+ expect(registry.get(serverUpdateStateAtom(TARGET.environmentId))).toMatchObject({
358
+ status: "running",
359
+ stage: "resuming",
360
+ });
361
+ const ready = (serverVersion: string) =>
362
+ ({
363
+ version: 1,
364
+ sequence: 1,
365
+ type: "ready",
366
+ payload: { at: "2026-09-01T00:00:00.000Z", environment: { serverVersion } },
367
+ }) as Parameters<typeof matchesServerUpdateReadyEvent>[1];
368
+ yield* Queue.offer(readyEvents, ready("0.0.30"));
369
+ yield* Deferred.await(oldReadyObserved);
370
+ expect(registry.get(serverUpdateStateAtom(TARGET.environmentId))).toMatchObject({
371
+ status: "running",
372
+ });
373
+ yield* Queue.offer(readyEvents, ready("0.0.31"));
374
+ expect(AsyncResult.isSuccess(yield* Effect.promise(() => pending))).toBe(true);
375
+ expect(registry.get(serverUpdateStateAtom(TARGET.environmentId))).toEqual({
376
+ status: "idle",
377
+ });
378
+ }).pipe(Effect.scoped),
379
+ );
380
+});
381
+
382
const makeConfigPersistenceHarness = Effect.fn("test.makeConfigPersistenceHarness")(function* (
383
saveServerConfig: Persistence.EnvironmentCacheStore["Service"]["saveServerConfig"],
384
) {
packages/client-runtime/src/state/server.ts
+15
-1
@@ -103,7 +103,7 @@ export class ServerUpdateResumeTimeoutError extends Schema.TaggedError<ServerUpd
103
},
104
) {
105
override get message(): string {
106
- return `The server did not resume on t3@${this.targetVersion}.`;
106
+ return `Could not confirm that the server resumed on t3@${this.targetVersion}. Reconnect to check the update outcome.`;
107
}
108
}
109
@@ -338,6 +338,7 @@ export function resolveServerUpdateProgressResult<E>(
338
targetVersion: string,
339
terminal: Option.Option<ServerSelfUpdateResult>,
340
streamExit: Exit.Exit<void, E>,
341
+ accepted?: ServerSelfUpdateResult,
342
): Effect.Effect<ServerSelfUpdateResult, E | ServerUpdateProgressIncompleteError> {
343
if (
344
Option.isSome(terminal) &&
@@ -346,6 +347,9 @@ export function resolveServerUpdateProgressResult<E>(
347
return Effect.succeed(terminal.value);
348
}
349
if (Exit.isFailure(streamExit)) {
350
+ if (accepted !== undefined && isLegacyUpdateHandoffLoss(streamExit.cause)) {
351
+ return Effect.succeed(accepted);
352
+ }
353
return Effect.failCause(streamExit.cause);
354
}
355
return Effect.fail(new ServerUpdateProgressIncompleteError({ targetVersion }));
@@ -882,6 +886,7 @@ export function createServerEnvironmentAtoms<R, E>(
886
currentConfig?.environment.capabilities.serverSelfUpdateProgress === true;
887
const updateResult: ServerSelfUpdateResult = supportsProgress
888
? yield* Effect.gen(function* () {
889
+ let receivedProgress = false;
890
const terminal = yield* Ref.make<Option.Option<ServerSelfUpdateResult>>(
891
Option.none(),
892
);
@@ -893,6 +898,7 @@ export function createServerEnvironmentAtoms<R, E>(
898
.pipe(
899
Stream.runForEach((event) =>
900
Effect.sync(() => {
901
+ receivedProgress ||= event.type === "progress";
902
const state = serverUpdateStateForProgressEvent(
903
fromVersion,
904
targetVersion,
@@ -910,10 +916,18 @@ export function createServerEnvironmentAtoms<R, E>(
916
),
917
Effect.exit,
918
);
919
+ const selfUpdateMethod = currentConfig?.environment.capabilities.serverSelfUpdate;
920
+ // Desktop preparation needs its terminal commit token.
921
+ const accepted =
922
+ receivedProgress &&
923
+ (selfUpdateMethod === "boot-service" || selfUpdateMethod === "respawn")
924
+ ? { targetVersion, method: selfUpdateMethod }
925
+ : undefined;
926
return yield* resolveServerUpdateProgressResult(
927
targetVersion,
928
yield* Ref.get(terminal),
929
streamExit,
930
+ accepted,
931
);
932
})
933
: yield* Effect.gen(function* () {