Skip to content

The agent that grows with you

fix(desktop): stop a stale cache skipping the app's own update leg

Brooklyn Nicholson5b0f68b47849
diff --git a/apps/desktop/src/store/updates.test.ts b/apps/desktop/src/store/updates.test.ts
index a69727031d9..a3a7c9cc810 100644
--- a/apps/desktop/src/store/updates.test.ts
+++ b/apps/desktop/src/store/updates.test.ts
@@ -662,6 +662,35 @@ describe('applyEverythingUpdate', () => {
expect(updateAllMock).toHaveBeenCalledTimes(1)
})
+ it('re-checks the client instead of trusting a stale cached status', async () => {
+ setRemote(true)
+ $backendUpdateStatus.set(status({ behind: 3 }))
+ // FAIL-BEFORE: `$updateStatus.get() ?? (await checkUpdates())` short-circuits
+ // on this cached row — captured up to a poll interval (30 min) ago, and
+ // before the backend leg ran — so the client apply was skipped and the app
+ // stayed stale. The live check says otherwise and must win.
+ $updateStatus.set(status({ behind: 0, updateAvailable: false }))
+ checkClientMock.mockResolvedValue(status({ behind: 7, updateAvailable: true }))
+
+ await applyEverythingUpdate()
+
+ expect(applyClientMock).toHaveBeenCalledTimes(1)
+ })
+
+ it('falls back to the cached client status when the live re-check fails', async () => {
+ setRemote(true)
+ $backendUpdateStatus.set(status({ behind: 3 }))
+ $updateStatus.set(status({ behind: 7, updateAvailable: true }))
+ // `checkUpdates()` never rejects — it resolves with an error-status and
+ // overwrites the atom with it, so an unreachable bridge must not read as
+ // "client is current" and skip the leg.
+ checkClientMock.mockRejectedValue(new Error('bridge gone'))
+
+ await applyEverythingUpdate()
+
+ expect(applyClientMock).toHaveBeenCalledTimes(1)
+ })
+
it('requestActiveUpdate routes through the everything-flow when EITHER target is behind', async () => {
setRemote(true)
// Backend current, client behind — the exact case the old remote-only
diff --git a/apps/desktop/src/store/updates.ts b/apps/desktop/src/store/updates.ts
index 3243e7aa27a..327c31b0a6e 100644
--- a/apps/desktop/src/store/updates.ts
+++ b/apps/desktop/src/store/updates.ts
@@ -878,6 +878,12 @@ export function applyEverythingUpdate(): Promise<void> {
async function runEverythingUpdate(): Promise<void> {
$updateEverything.set({ running: true })
+ // Snapshot the client status before any leg runs: the backend leg's own
+ // post-update nudge re-checks the client and overwrites `$updateStatus`,
+ // including with an error row when the bridge is unreachable. Step 3 needs a
+ // pre-flow value to fall back on when its own live check can't answer.
+ const cachedClientStatus = $updateStatus.get()
+
try {
// 1. Active backend first (remote mode), with the detailed overlay flow.
// Its own finish path re-checks and nudges, but the everything-flow
@@ -934,7 +940,14 @@ async function runEverythingUpdate(): Promise<void> {
// 3. The client last — its apply relaunches or hands off the app, so it
// must come after every dispatch above. Skipped when already current.
- const clientStatus = $updateStatus.get() ?? (await checkUpdates())
+ // Re-check rather than trusting `$updateStatus`: the cached value can be
+ // up to a poll interval (30 min) old and was captured BEFORE the backend
+ // update above, so a cached `behind: 0` would skip the client leg and
+ // leave the app stale — the exact failure this flow exists to prevent.
+ // `checkUpdates()` resolves with an error-status rather than rejecting,
+ // so fall back to the pre-flow snapshot when the live check can't answer.
+ const freshClientStatus = await checkUpdates().catch(() => null)
+ const clientStatus = freshClientStatus?.error ? cachedClientStatus : (freshClientStatus ?? cachedClientStatus)
if ((clientStatus?.behind ?? 0) > 0 || clientStatus?.updateAvailable) {
$updateOverlayTarget.set('client')