The best way to control Claude Code, Codex and more from any computer or phone
fix(desktop): recover prepared remote updates on retry (#33605)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Amman committed
Nov 14, 2026 at 12:51 UTC
c03498e68904634c85f42f40302a5c43ac4c6bac
5 files changed
+125
-3
apps/desktop/src/updates/DesktopRemoteUpdates.test.ts
+66
@@ -102,6 +102,29 @@ describe("DesktopRemoteUpdates", () => {
102
assert.equal(terminals[0]?.requestId, "req-1");
103
assert.equal(harness.quitAndInstalls(), 0);
104
105
+ yield* Queue.offer(requests, request("req-retry"));
106
+ yield* settle;
107
+ assert.deepEqual(
108
+ terminalReports(reports).map((report) => report.outcome),
109
+ ["ready-to-install", "ready-to-install"],
110
+ );
111
+ assert.equal(terminalReports(reports)[1]?.requestId, "req-retry");
112
+ assert.equal(terminalReports(reports)[1]?.preparedRequestId, "req-1");
113
+ assert.equal(harness.quitAndInstalls(), 0);
114
+ assert.equal(harness.downloadCount(), 1);
115
+
116
+ yield* Queue.offer(requests, {
117
+ ...request("req-other-track"),
118
+ channel: "nightly",
119
+ targetVersion: "1.2.4-nightly.20261027.1",
120
+ });
121
+ yield* settle;
122
+ assert.equal(terminalReports(reports)[2]?.outcome, "failed");
123
+ assert.equal(
124
+ terminalReports(reports)[2]?.reason,
125
+ "A prepared desktop update is already in progress.",
126
+ );
127
+
128
yield* Queue.offer(commits, {
129
version: 1,
130
type: "commitDesktopUpdate",
@@ -119,6 +142,49 @@ describe("DesktopRemoteUpdates", () => {
142
);
143
});
144
145
+ it.effect("does not renew the preparation lease when a retry recovers its token", () => {
146
+ const harness = makeHarness();
147
+
148
+ return runRemoteUpdatesTest(harness, ({ reports, requests, commits }) =>
149
+ Effect.gen(function* () {
150
+ harness.emit("update-downloaded", { version: "1.2.4" });
151
+ yield* settle;
152
+ yield* Queue.offer(requests, request("req-original"));
153
+ yield* settle;
154
+
155
+ yield* TestClock.adjust(Duration.minutes(4));
156
+ harness.emit("update-available", { version: "1.2.4" });
157
+ yield* settle;
158
+ yield* Queue.offer(requests, request("req-retry"));
159
+ yield* settle;
160
+ assert.equal(terminalReports(reports)[1]?.preparedRequestId, "req-original");
161
+
162
+ yield* TestClock.adjust(Duration.minutes(1));
163
+ yield* Queue.offer(commits, {
164
+ version: 1,
165
+ type: "commitDesktopUpdate",
166
+ requestId: "req-original",
167
+ });
168
+ yield* settle;
169
+ assert.equal(
170
+ terminalReports(reports)[2]?.reason,
171
+ "This desktop update is no longer prepared.",
172
+ );
173
+ assert.equal(harness.quitAndInstalls(), 0);
174
+
175
+ yield* Queue.offer(requests, request("req-new"));
176
+ yield* settle;
177
+ yield* Queue.offer(commits, {
178
+ version: 1,
179
+ type: "commitDesktopUpdate",
180
+ requestId: "req-new",
181
+ });
182
+ yield* settle;
183
+ assert.equal(harness.quitAndInstalls(), 1);
184
+ }),
185
+ );
186
+ });
187
+
188
it.effect("switches to the requested track before preparing its release", () => {
189
// In-memory settings keep the channel write off real disk I/O.
190
const harness = makeHarness({ beforeSetUpdateChannel: Effect.void });
apps/desktop/src/updates/DesktopRemoteUpdates.ts
+27
-2
@@ -32,6 +32,8 @@ const PREPARED_UPDATE_TTL = Duration.minutes(5);
32
33
interface PreparedUpdate {
34
readonly requestId: string;
35
+ readonly channel: DesktopTelemetryRequestDesktopUpdate["channel"];
36
+ readonly targetVersion: DesktopTelemetryRequestDesktopUpdate["targetVersion"];
37
readonly downloadedVersion: string;
38
readonly status: "prepared" | "committing" | "failed";
39
readonly failureReason?: string;
@@ -67,7 +69,11 @@ export const listen: Effect.Effect<
69
70
const publishReport = (
71
state: DesktopUpdateState,
70
- terminal?: { readonly outcome: DesktopUpdateRemoteOutcome; readonly reason?: string },
72
+ terminal?: {
73
+ readonly outcome: DesktopUpdateRemoteOutcome;
74
+ readonly reason?: string;
75
+ readonly preparedRequestId?: string;
76
+ },
77
explicitRequestId?: string,
78
): Effect.Effect<void> => {
79
const reason = normalizeRemoteUpdateReason(terminal?.reason);
@@ -82,6 +88,9 @@ export const listen: Effect.Effect<
88
? { requestId: requestId.value }
89
: {}),
90
...(terminal === undefined ? {} : { outcome: terminal.outcome }),
91
+ ...(terminal?.preparedRequestId === undefined
92
+ ? {}
93
+ : { preparedRequestId: terminal.preparedRequestId }),
94
...(reason ? { reason } : {}),
95
state,
96
}),
@@ -167,8 +176,22 @@ export const listen: Effect.Effect<
176
: ([current, current] as const),
177
);
178
if (Option.isSome(prepared) && prepared.value.status !== "failed") {
179
+ const state = yield* updates.getState;
180
+ if (
181
+ prepared.value.status === "prepared" &&
182
+ prepared.value.channel === request.channel &&
183
+ prepared.value.targetVersion === request.targetVersion &&
184
+ state.downloadedVersion === prepared.value.downloadedVersion
185
+ ) {
186
+ yield* publishReport(
187
+ state,
188
+ { outcome: "ready-to-install", preparedRequestId: prepared.value.requestId },
189
+ request.requestId,
190
+ );
191
+ return;
192
+ }
193
yield* publishReport(
171
- yield* updates.getState,
194
+ state,
195
{
196
outcome: "failed",
197
reason: "A prepared desktop update is already in progress.",
@@ -301,6 +324,8 @@ export const listen: Effect.Effect<
324
preparedUpdateRef,
325
Option.some({
326
requestId: request.requestId,
327
+ channel: request.channel,
328
+ targetVersion: request.targetVersion,
329
downloadedVersion: state.downloadedVersion,
330
status: "prepared",
331
expiresAt:
apps/server/src/desktopUpdate/DesktopAppUpdate.test.ts
+26
@@ -42,6 +42,7 @@ function report(
42
terminal?: {
43
readonly outcome: DesktopUpdateStatusReport["outcome"];
44
readonly reason?: string;
45
+ readonly preparedRequestId?: string;
46
},
47
): DesktopUpdateStatusReport {
48
return {
@@ -50,6 +51,9 @@ function report(
51
requestId,
52
...(terminal?.outcome === undefined ? {} : { outcome: terminal.outcome }),
53
...(terminal?.reason === undefined ? {} : { reason: terminal.reason }),
54
+ ...(terminal?.preparedRequestId === undefined
55
+ ? {}
56
+ : { preparedRequestId: terminal.preparedRequestId }),
57
state,
58
};
59
}
@@ -133,6 +137,28 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("desktop app upda
137
}),
138
);
139
140
+ it.effect("commits the original preparation when a retry joins its downloaded update", () =>
141
+ Effect.gen(function* () {
142
+ const { service } = yield* makeHarness({
143
+ reports: (requestId) => [
144
+ report(requestId, makeState({ status: "downloaded", downloadedVersion: "1.2.4" }), {
145
+ outcome: "ready-to-install",
146
+ preparedRequestId: "original-preparation",
147
+ }),
148
+ report("original-preparation", makeState({ status: "downloaded" }), {
149
+ outcome: "failed",
150
+ reason: "installer refused",
151
+ }),
152
+ ],
153
+ });
154
+ const prepared = yield* service.run(() => Effect.void);
155
+ expect(prepared.desktopUpdateToken).toBe("original-preparation");
156
+ expect(
157
+ (yield* service.commit(prepared.desktopUpdateToken ?? "missing").pipe(Effect.flip)).reason,
158
+ ).toBe("installer refused");
159
+ }),
160
+ );
161
+
162
it.effect("succeeds without an install when a track switch finds the host current", () =>
163
Effect.gen(function* () {
164
const { service } = yield* makeHarness({
apps/server/src/desktopUpdate/DesktopAppUpdate.ts
+5
-1
@@ -121,7 +121,11 @@ export const make = Effect.fn("desktopUpdate.desktopAppUpdate.make")(function* (
121
targetVersion,
122
});
123
yield* Ref.set(inFlight, false);
124
- return { targetVersion, method: "desktop-app" as const, desktopUpdateToken: requestId };
124
+ return {
125
+ targetVersion,
126
+ method: "desktop-app" as const,
127
+ desktopUpdateToken: report.preparedRequestId ?? requestId,
128
+ };
129
}
130
if (report.outcome === "up-to-date") {
131
// A switch's host already on the newest build of its track only saved the track.
packages/contracts/src/resourceTelemetry.ts
+1
@@ -289,6 +289,7 @@ export const DesktopUpdateStatusReport = Schema.Struct({
289
version: Schema.Literal(1),
290
type: Schema.Literal("desktopUpdateStatus"),
291
requestId: Schema.optionalKey(TrimmedNonEmptyString),
292
+ preparedRequestId: Schema.optionalKey(TrimmedNonEmptyString),
293
outcome: Schema.optionalKey(DesktopUpdateRemoteOutcome),
294
reason: Schema.optionalKey(TrimmedNonEmptyString),
295
state: DesktopUpdateStateSchema,