Skip to content

Commit 0ec5a65

Browse files
t3dotggclaude
andcommitted
fix(desktop): an uncommitted prepared switch restores its track when it expires
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 675af66 commit 0ec5a65

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎apps/desktop/src/updates/DesktopRemoteUpdates.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,36 @@ describe("DesktopRemoteUpdates", () => {
599599
);
600600
});
601601

602+
it.effect("restores the track when a prepared switch is never committed", () => {
603+
const harness = makeHarness({ beforeSetUpdateChannel: Effect.void });
604+
605+
return runRemoteUpdatesTest(harness, ({ reports, requests }) =>
606+
Effect.gen(function* () {
607+
const updates = yield* DesktopUpdates.DesktopUpdates;
608+
const nightly = "1.2.4-nightly.20261027.1";
609+
yield* Queue.offer(requests, {
610+
...request("req-abandoned"),
611+
channel: "nightly",
612+
targetVersion: nightly,
613+
});
614+
yield* settle;
615+
harness.emit("update-available", { version: nightly });
616+
yield* settle;
617+
harness.emit("update-downloaded", { version: nightly });
618+
yield* settle;
619+
assert.deepEqual(
620+
terminalReports(reports).map((report) => report.outcome),
621+
["ready-to-install"],
622+
);
623+
624+
yield* TestClock.adjust(Duration.minutes(6));
625+
yield* settle;
626+
627+
assert.equal((yield* updates.getState).channel, "latest");
628+
}),
629+
);
630+
});
631+
602632
it.effect("cancels a track switch while its own feed check is still running", () => {
603633
const releaseCheck = Deferred.makeUnsafe<void>();
604634
const harness = makeHarness({

‎apps/desktop/src/updates/DesktopRemoteUpdates.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ export const listen: Effect.Effect<
114114
Effect.flatMap((fiber) => Ref.set(pendingRestoreRef, Option.some(fiber))),
115115
);
116116

117+
const expireSwitch = (requestId: string) =>
118+
Ref.modify(preparedUpdateRef, (prepared) =>
119+
Option.isSome(prepared) &&
120+
prepared.value.requestId === requestId &&
121+
prepared.value.status === "prepared"
122+
? ([prepared, Option.none<PreparedUpdate>()] as const)
123+
: ([Option.none<PreparedUpdate>(), prepared] as const),
124+
).pipe(
125+
Effect.flatMap((expired) =>
126+
Option.isSome(expired) ? scheduleRestore(expired.value) : Effect.void,
127+
),
128+
);
129+
117130
const failPrepared = Effect.fn("DesktopRemoteUpdates.failPrepared")(function* (
118131
requestId: string,
119132
reason: string,
@@ -344,6 +357,13 @@ export const listen: Effect.Effect<
344357
}),
345358
);
346359
keepsTrack = true;
360+
if (request.channel !== undefined) {
361+
// With no commit (the client went away), the switch's track must not outlive it.
362+
yield* Effect.sleep(PREPARED_UPDATE_TTL).pipe(
363+
Effect.andThen(expireSwitch(request.requestId)),
364+
Effect.forkDetach,
365+
);
366+
}
347367
yield* publishReport(state, { outcome: "ready-to-install" }, request.requestId);
348368
yield* logInfo("remote update prepared", { requestId: request.requestId });
349369
return true;

0 commit comments

Comments
 (0)