The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 12:15 UTC
fix(desktop): a waiting update is no longer re-announced on every poll (#31154)
Co-authored-by: Taylor Dolezal <117500+onlydole@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Taylor Dolezal committed
Nov 14, 2026 at 17:35 UTC
2cc4b4888e7a3c634332a7d98b9fc0fff85a0988
4 files changed
+111
-66
apps/desktop/src/app/DesktopStartupRecovery.ts
-1
@@ -217,7 +217,6 @@ export const listen: Effect.Effect<
217
const download = yield* updates.download;
218
if (!download.completed) return;
219
}
220
- // Waits for a running background check; plain install would refuse.
220
yield* updates.installPrepared(current.version);
221
return;
222
}
apps/desktop/src/updates/DesktopRemoteUpdates.test.ts
+1
-2
@@ -757,7 +757,7 @@ describe("DesktopRemoteUpdates", () => {
757
758
const backgroundCheck = yield* updates.check("poll").pipe(Effect.forkChild);
759
yield* Deferred.await(backgroundCheckStarted);
760
- assert.equal((yield* updates.getState).status, "checking");
760
+ assert.isTrue(yield* updates.isActionActive);
761
762
yield* Queue.offer(commits, {
763
version: 1,
@@ -767,7 +767,6 @@ describe("DesktopRemoteUpdates", () => {
767
yield* settle;
768
assert.equal(harness.quitAndInstalls(), 0);
769
770
- harness.emit("update-downloaded", { version: "1.2.4" });
770
yield* Deferred.succeed(releaseBackgroundCheck, undefined);
771
yield* Fiber.join(backgroundCheck);
772
yield* settle;
apps/desktop/src/updates/DesktopUpdates.test.ts
+33
-15
@@ -125,7 +125,7 @@ describe("DesktopUpdates", () => {
125
).pipe(Effect.provide(harness.layer));
126
});
127
128
- it.effect("checks for newer releases after an update has been downloaded", () => {
128
+ it.effect("re-checks an offered update without announcing it again", () => {
129
const harness = makeHarness();
130
131
return Effect.scoped(
@@ -138,14 +138,23 @@ describe("DesktopUpdates", () => {
138
releaseNotes: "## What's changed\n- fix: queued update",
139
});
140
yield* flushCallbacks;
141
+ const offeredStates = harness.sentStates.length;
142
+
143
+ yield* updates.check("poll");
144
+ harness.emit("update-available", { version: "1.2.4" });
145
+ yield* flushCallbacks;
146
+ assert.equal(harness.sentStates.length, offeredStates);
147
+
148
harness.emit("update-downloaded", { version: "1.2.4" });
149
yield* flushCallbacks;
150
+ const downloadedStates = harness.sentStates.length;
151
152
const result = yield* updates.check("poll");
153
assert.isTrue(result.checked);
154
155
harness.emit("update-available", { version: "1.2.4" });
156
yield* flushCallbacks;
157
+ assert.equal(harness.sentStates.length, downloadedStates);
158
159
const unchangedState = yield* updates.getState;
160
assert.equal(unchangedState.status, "downloaded");
@@ -267,15 +276,26 @@ describe("DesktopUpdates", () => {
276
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
277
});
278
270
- it.effect(
271
- "rejects install while a refresh check is in progress and releases the reservation",
272
- () =>
279
+ it.effect.each([
280
+ { action: "download", offer: "update-available", found: null, accepted: true },
281
+ { action: "install", offer: "update-downloaded", found: null, accepted: true },
282
+ { action: "download", offer: "update-available", found: "1.2.5", accepted: true },
283
+ { action: "install", offer: "update-downloaded", found: "1.2.5", accepted: false },
284
+ ] as const)(
285
+ "a $action waiting out a refresh check acts on what it found ($found)",
286
+ ({ action, offer, found, accepted }) =>
287
Effect.gen(function* () {
288
const checkStarted = yield* Deferred.make<void>();
289
const releaseCheck = yield* Deferred.make<void>();
290
const harness = makeHarness({
291
checkForUpdates: Deferred.succeed(checkStarted, undefined).pipe(
292
Effect.andThen(Deferred.await(releaseCheck)),
293
+ // electron-updater emits the check's outcome before its promise resolves.
294
+ Effect.andThen(
295
+ Effect.sync(() => {
296
+ if (found !== null) harness.emit("update-available", { version: found });
297
+ }),
298
+ ),
299
),
300
});
301
@@ -283,22 +303,20 @@ describe("DesktopUpdates", () => {
303
Effect.gen(function* () {
304
const updates = yield* DesktopUpdates.DesktopUpdates;
305
yield* updates.configure;
286
- harness.emit("update-downloaded", { version: "1.2.4" });
306
+ harness.emit(offer, { version: "1.2.4" });
307
yield* flushCallbacks;
308
289
- const checkFiber = yield* updates.check("manual").pipe(Effect.forkScoped);
309
+ const checkFiber = yield* updates.check("poll").pipe(Effect.forkScoped);
310
yield* Deferred.await(checkStarted);
291
-
292
- const installResult = yield* updates.install;
293
- assert.isFalse(installResult.accepted);
311
+ const actionFiber = yield* updates[action].pipe(Effect.forkScoped);
312
+ yield* flushCallbacks;
313
314
yield* Deferred.succeed(releaseCheck, undefined);
296
- const checkResult = yield* Fiber.join(checkFiber);
297
- assert.isTrue(checkResult.checked);
298
-
299
- const followUpCheck = yield* updates.check("manual");
300
- assert.isTrue(followUpCheck.checked);
301
- assert.equal(harness.checkCount(), 2);
315
+ assert.isTrue((yield* Fiber.join(checkFiber)).checked);
316
+ assert.equal((yield* Fiber.join(actionFiber)).accepted, accepted);
317
+ const state = yield* updates.getState;
318
+ assert.equal(state.availableVersion, found ?? "1.2.4");
319
+ if (action === "download") assert.equal(state.status, "downloading");
320
}),
321
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
322
}),
apps/desktop/src/updates/DesktopUpdates.ts
+77
-48
@@ -63,7 +63,7 @@ const CHANNEL_CHANGE_RETRY_DELAY = Duration.seconds(1);
63
const CHANNEL_CHANGE_RETRIES = 30;
64
const AUTO_UPDATE_STARTUP_DELAY = "15 seconds";
65
const AUTO_UPDATE_POLL_INTERVAL = "4 hours";
66
-const PREPARED_INSTALL_CHECK_WAIT = Duration.seconds(90);
66
+const UPDATE_CHECK_WAIT = Duration.seconds(90);
67
68
type UpdateAction = "check" | "download" | "install" | "install-recovery" | "channel";
69
@@ -318,6 +318,10 @@ function getCanRetryFromState(state: DesktopUpdateState): boolean {
318
return state.availableVersion !== null || state.downloadedVersion !== null;
319
}
320
321
+function isOffered(state: DesktopUpdateState): boolean {
322
+ return state.status === "available" || state.status === "downloaded";
323
+}
324
+
325
function shouldBroadcastDownloadProgress(
326
currentState: DesktopUpdateState,
327
nextPercent: number,
@@ -518,6 +522,23 @@ export const make = Effect.gen(function* () {
522
),
523
);
524
525
+ // Re-runs admit after each finished action, so a caller waiting on a check decides on its result.
526
+ const admitAfterCheck = Effect.fn("desktop.updates.admitAfterCheck")(function* (
527
+ admit: Effect.Effect<"admitted" | "refused" | "wait-for-check">,
528
+ ) {
529
+ const actionCompletions = yield* PubSub.subscribe(finishedUpdateActions);
530
+ let admission = yield* stateMutex.withPermits(1)(admit);
531
+ while (admission === "wait-for-check") {
532
+ const finishedAction = yield* PubSub.take(actionCompletions).pipe(
533
+ Effect.timeoutOption(UPDATE_CHECK_WAIT),
534
+ );
535
+ admission = Option.isNone(finishedAction)
536
+ ? "refused"
537
+ : yield* stateMutex.withPermits(1)(admit);
538
+ }
539
+ return admission;
540
+ });
541
+
542
const applyAutoUpdaterChannel = Effect.fn("desktop.updates.applyAutoUpdaterChannel")(function* (
543
channel: DesktopUpdateChannel,
544
) {
@@ -559,8 +580,10 @@ export const make = Effect.gen(function* () {
580
if (actionReservation === "acquire" && !(yield* tryStartUpdateAction("check"))) return false;
581
582
const check = Effect.gen(function* () {
562
- const checkedAt = yield* currentIsoTimestamp;
563
- yield* setState(reduceDesktopUpdateStateOnCheckStart(state, checkedAt));
583
+ // An offer stays on screen while re-checking, so finding it again changes nothing.
584
+ if (!isOffered(state)) {
585
+ yield* setState(reduceDesktopUpdateStateOnCheckStart(state, yield* currentIsoTimestamp));
586
+ }
587
yield* logUpdaterInfo("checking for updates", { reason });
588
589
// The flag is shared updater state, so it flips only while this check holds the reservation.
@@ -597,15 +620,30 @@ export const make = Effect.gen(function* () {
620
});
621
622
const downloadAvailableUpdate = Effect.gen(function* () {
600
- const state = yield* Ref.get(updateStateRef);
601
- if (!(yield* Ref.get(updaterConfiguredRef)) || state.status !== "available") {
602
- return { accepted: false, completed: false };
603
- }
604
-
605
- if (!(yield* tryStartUpdateAction("download"))) {
623
+ const admission = yield* Effect.scoped(
624
+ admitAfterCheck(
625
+ Effect.gen(function* () {
626
+ const state = yield* Ref.get(updateStateRef);
627
+ if (!(yield* Ref.get(updaterConfiguredRef)) || state.status !== "available") {
628
+ return "refused" as const;
629
+ }
630
+ const activeAction = yield* Ref.get(activeUpdateActionRef);
631
+ if (Option.isSome(activeAction)) {
632
+ return activeAction.value === "check"
633
+ ? ("wait-for-check" as const)
634
+ : ("refused" as const);
635
+ }
636
+ return (yield* tryStartUpdateAction("download"))
637
+ ? ("admitted" as const)
638
+ : ("refused" as const);
639
+ }),
640
+ ),
641
+ );
642
+ if (admission === "refused") {
643
return { accepted: false, completed: false };
644
}
645
646
+ const state = yield* Ref.get(updateStateRef);
647
return yield* Effect.gen(function* () {
648
yield* setState(reduceDesktopUpdateStateOnDownloadStart(state));
649
yield* electronUpdater.setDisableDifferentialDownload(
@@ -798,47 +836,35 @@ export const make = Effect.gen(function* () {
836
const installDownloadedUpdate = (expectedVersion?: string) =>
837
Effect.scoped(
838
Effect.gen(function* () {
801
- const actionCompletions = yield* PubSub.subscribe(finishedUpdateActions);
802
- let admission: "admitted" | "refused" | "wait-for-check" = "wait-for-check";
803
- while (admission === "wait-for-check") {
804
- admission = yield* stateMutex.withPermits(1)(
805
- Effect.gen(function* () {
806
- const state = yield* Ref.get(updateStateRef);
807
- const activeAction = yield* Ref.get(activeUpdateActionRef);
808
- const hasExpectedDownload =
809
- state.downloadedVersion !== null &&
810
- (expectedVersion === undefined || state.downloadedVersion === expectedVersion);
811
- if (
812
- (yield* Ref.get(desktopState.quitting)) ||
813
- !(yield* Ref.get(updaterConfiguredRef)) ||
814
- !hasExpectedDownload
815
- ) {
816
- return "refused" as const;
817
- }
818
- if (Option.isSome(activeAction)) {
819
- return activeAction.value === "check" && expectedVersion !== undefined
820
- ? ("wait-for-check" as const)
821
- : ("refused" as const);
822
- }
823
- const hasInstallableDownload =
824
- state.status === "downloaded" ||
825
- (state.status === "error" &&
826
- (state.errorContext === null || state.errorContext === "install"));
827
- if (!hasInstallableDownload) return "refused" as const;
828
- return (yield* tryStartUpdateAction("install"))
829
- ? ("admitted" as const)
839
+ const admission = yield* admitAfterCheck(
840
+ Effect.gen(function* () {
841
+ const state = yield* Ref.get(updateStateRef);
842
+ const activeAction = yield* Ref.get(activeUpdateActionRef);
843
+ const hasExpectedDownload =
844
+ state.downloadedVersion !== null &&
845
+ (expectedVersion === undefined || state.downloadedVersion === expectedVersion);
846
+ if (
847
+ (yield* Ref.get(desktopState.quitting)) ||
848
+ !(yield* Ref.get(updaterConfiguredRef)) ||
849
+ !hasExpectedDownload
850
+ ) {
851
+ return "refused" as const;
852
+ }
853
+ if (Option.isSome(activeAction)) {
854
+ return activeAction.value === "check"
855
+ ? ("wait-for-check" as const)
856
: ("refused" as const);
831
- }),
832
- );
833
- if (admission === "wait-for-check") {
834
- const finishedAction = yield* PubSub.take(actionCompletions).pipe(
835
- Effect.timeoutOption(PREPARED_INSTALL_CHECK_WAIT),
836
- );
837
- if (Option.isNone(finishedAction)) {
838
- admission = "refused";
857
}
840
- }
841
- }
858
+ const hasInstallableDownload =
859
+ state.status === "downloaded" ||
860
+ (state.status === "error" &&
861
+ (state.errorContext === null || state.errorContext === "install"));
862
+ if (!hasInstallableDownload) return "refused" as const;
863
+ return (yield* tryStartUpdateAction("install"))
864
+ ? ("admitted" as const)
865
+ : ("refused" as const);
866
+ }),
867
+ );
868
if (admission === "refused") {
869
return { accepted: false, completed: false, failed: false };
870
}
@@ -982,6 +1008,7 @@ export const make = Effect.gen(function* () {
1008
yield* Ref.set(lastLoggedDownloadMilestoneRef, -1);
1009
return;
1010
}
1011
+ if (isOffered(state) && state.availableVersion === info.version) return;
1012
1013
const checkedAt = yield* currentIsoTimestamp;
1014
const { releaseNotes, omittedReleaseCount } = normalizeDesktopUpdateReleaseNotes(
@@ -1161,6 +1188,8 @@ export const make = Effect.gen(function* () {
1188
),
1189
configure: Effect.gen(function* () {
1190
const context = yield* Effect.context<never>();
1191
+ // Runs synchronously up to the first await, so a check's outcome is applied before the
1192
+ // check's promise resolves and wakes the actions waiting on it.
1193
const runEffect = (effect: Effect.Effect<void>) => {
1194
void Effect.runPromiseWith(context)(effect);
1195
};