Skip to content

The agent that grows with you

fix(desktop): Check for Updates updates this app, not the remote backend

Brooklyn Nicholson79856ba49ba8
diff --git a/apps/desktop/src/app/contrib/hooks/use-desktop-integrations.ts b/apps/desktop/src/app/contrib/hooks/use-desktop-integrations.ts
index 9cd069c2538..132dffe6564 100644
--- a/apps/desktop/src/app/contrib/hooks/use-desktop-integrations.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-desktop-integrations.ts
@@ -73,7 +73,12 @@ export function useDesktopIntegrations({
// Background MCP health: HTTP/SSE servers only (never spawns stdio),
// notifies on transitions into needs-auth/error with a Sign in action.
startMcpHealthChecker()
- const unsubscribe = window.hermesDesktop?.onOpenUpdatesRequested?.(() => openUpdatesWindow())
+ // The native "Check for Updates…" menu item lives in the app menu next to
+ // "About Hermes" — it is the OS-standard affordance for updating THIS app,
+ // so it always opens the client overlay. Inheriting the connection-mode
+ // default pointed a Mac at its remote Linux backend and left the app itself
+ // silently stale (#70266).
+ const unsubscribe = window.hermesDesktop?.onOpenUpdatesRequested?.(() => openUpdatesWindow('client'))
return () => {
unsubscribe?.()
diff --git a/apps/desktop/src/app/settings/about-settings.tsx b/apps/desktop/src/app/settings/about-settings.tsx
index 8ff1e27e643..281f75d2c63 100644
--- a/apps/desktop/src/app/settings/about-settings.tsx
+++ b/apps/desktop/src/app/settings/about-settings.tsx
@@ -199,7 +199,7 @@ export function AboutSettings() {
<Button onClick={() => startActiveUpdate()} size="sm">
{a.updateNow}
</Button>
- <Button onClick={() => openUpdatesWindow()} size="sm" variant="textStrong">
+ <Button onClick={() => openUpdatesWindow('client')} size="sm" variant="textStrong">
{a.seeWhatsNew}
</Button>
</>
diff --git a/apps/desktop/src/store/updates.test.ts b/apps/desktop/src/store/updates.test.ts
index cea46b004fc..a69727031d9 100644
--- a/apps/desktop/src/store/updates.test.ts
+++ b/apps/desktop/src/store/updates.test.ts
@@ -89,6 +89,8 @@ const {
applyUpdates,
applyEverythingUpdate,
hasMultipleUpdateTargets,
+ openUpdatesWindow,
+ startActiveUpdate,
$updateApply,
$updateEverything,
$updateOverlayOpen,
@@ -117,7 +119,7 @@ const status = (over: Partial<DesktopUpdateStatus> = {}): DesktopUpdateStatus =>
...over
})
-const lastToast = () => notifySpy.mock.calls.at(-1)?.[0] as { onDismiss: () => void }
+const lastToast = () => notifySpy.mock.calls.at(-1)?.[0] as { action: { onClick: () => void }; onDismiss: () => void }
const setRemote = (on: boolean) =>
setConnection({
@@ -410,6 +412,102 @@ describe('requestActiveUpdate', () => {
})
})
+// Surface-bound update entry points. A surface that displays ONE target's
+// status must act on that target: the overlay has no target switcher, so
+// inheriting the connection-mode default silently pointed the user at the
+// other machine. This is what left a Mac desktop on a months-old build while
+// its remote Linux backend updated fine, with no error anywhere (#70266).
+describe('explicit update targets', () => {
+ const applyClientMock = vi.fn()
+ const checkClientMock = vi.fn()
+
+ beforeEach(() => {
+ storage.clear()
+ notifySpy.mockClear()
+ dismissSpy.mockClear()
+ applyClientMock.mockReset().mockResolvedValue({ ok: true, handedOff: true })
+ checkClientMock.mockReset().mockResolvedValue(status({ behind: 4, updateAvailable: true }))
+ updateHermesSpy.mockReset().mockResolvedValue({ ok: true, name: 'update' })
+ checkHermesUpdateSpy.mockReset().mockResolvedValue({
+ install_method: 'git',
+ current_version: '0.4.2',
+ behind: 0,
+ update_available: false,
+ can_apply: true,
+ update_command: null,
+ message: null
+ })
+ getActionStatusSpy.mockReset().mockResolvedValue({ lines: [], running: false, exit_code: 0 })
+ resetUpdateApplyState()
+ $updateStatus.set(null)
+ $backendUpdateStatus.set(null)
+ $updateOverlayOpen.set(false)
+ $updateOverlayTarget.set('backend')
+ $mockConnectionsRegistry.set(null)
+ setRemote(true)
+ ;(globalThis as unknown as { window: unknown }).window = {
+ hermesDesktop: { updates: { apply: applyClientMock, check: checkClientMock } }
+ }
+ vi.useRealTimers()
+ })
+
+ afterEach(async () => {
+ await vi.waitFor(() => expect($updateEverything.get().running).toBe(false), { timeout: 5000 })
+ await vi.waitFor(() => expect($backendUpdateApply.get().applying).toBe(false), { timeout: 5000 })
+ setRemote(false)
+ delete (globalThis as unknown as { window?: unknown }).window
+ })
+
+ // The macOS "Check for Updates…" app-menu item — the OS-standard affordance
+ // for updating THIS app — routes here via `hermes:open-updates`.
+ it('opens the client overlay on an explicit client target, even in remote mode', async () => {
+ openUpdatesWindow('client')
+
+ expect($updateOverlayTarget.get()).toBe('client')
+ await vi.waitFor(() => expect(checkClientMock).toHaveBeenCalledTimes(1))
+ expect(checkHermesUpdateSpy).not.toHaveBeenCalled()
+ })
+
+ it('still defaults to the connected machine when no target is named', async () => {
+ openUpdatesWindow()
+
+ expect($updateOverlayTarget.get()).toBe('backend')
+ await vi.waitFor(() => expect(checkHermesUpdateSpy).toHaveBeenCalled())
+ expect(checkClientMock).not.toHaveBeenCalled()
+ })
+
+ it('applies the client update on an explicit client target, without fanning out', async () => {
+ startActiveUpdate('client')
+
+ expect($updateOverlayTarget.get()).toBe('client')
+ await vi.waitFor(() => expect(applyClientMock).toHaveBeenCalledTimes(1))
+ expect(updateHermesSpy).not.toHaveBeenCalled()
+ expect($updateEverything.get().running).toBe(false)
+ })
+
+ it('keeps the everything-flow for the generic, target-less apply', async () => {
+ $backendUpdateStatus.set(status({ behind: 3 }))
+
+ startActiveUpdate()
+
+ await vi.waitFor(() => expect(updateHermesSpy).toHaveBeenCalled(), { timeout: 5000 })
+ })
+
+ // A toast raised by the CLIENT check must open the client overlay: the user
+ // was told the app is behind, so landing them on the backend's (current)
+ // status reads as the update having vanished.
+ it('opens the overlay for the target whose status raised the toast', () => {
+ maybeNotifyUpdateAvailable(status(), 'client')
+ lastToast().action.onClick()
+ expect($updateOverlayTarget.get()).toBe('client')
+
+ storage.clear() // clear the snooze the click just set
+ maybeNotifyUpdateAvailable(status({ targetSha: 'sha-b' }), 'backend')
+ lastToast().action.onClick()
+ expect($updateOverlayTarget.get()).toBe('backend')
+ })
+})
+
// The everything-flow: on multi-target installs (remote mode / multi-connection
// registry) "update" must mean every machine — active backend, other registered
// sources via the Electron fan-out, and the client LAST. Before this flow,
diff --git a/apps/desktop/src/store/updates.ts b/apps/desktop/src/store/updates.ts
index f6e977f9757..3243e7aa27a 100644
--- a/apps/desktop/src/store/updates.ts
+++ b/apps/desktop/src/store/updates.ts
@@ -205,8 +205,12 @@ export function reportInstallMethodWarning(message: string | undefined): void {
* Closing the toast — dismissing it or opening the updates window from it —
* (re)starts the cooldown, so a busy upstream branch doesn't re-spam the user
* on every new commit. The snooze is persisted, so it survives relaunches too.
+ *
+ * `target` is the target whose status produced this toast. The overlay has no
+ * target switcher, so a client-status toast that opened the backend overlay
+ * showed the user a machine they weren't told about, with no way back.
*/
-export function maybeNotifyUpdateAvailable(status: DesktopUpdateStatus | null) {
+export function maybeNotifyUpdateAvailable(status: DesktopUpdateStatus | null, target: UpdateTarget = 'client') {
if (!status || status.supported === false || status.error || !status.targetSha) {
return
}
@@ -232,7 +236,7 @@ export function maybeNotifyUpdateAvailable(status: DesktopUpdateStatus | null) {
label: translateNow('notifications.seeWhatsNew'),
onClick: () => {
snoozeUpdateToast()
- openUpdatesWindow()
+ openUpdateOverlayFor(target)
}
},
durationMs: 0,
@@ -248,8 +252,24 @@ export function maybeNotifyUpdateAvailable(status: DesktopUpdateStatus | null) {
})
}
-export function openUpdatesWindow(): void {
- openUpdateOverlayFor(isRemoteMode() ? 'backend' : 'client')
+/** The target a generic, surface-less update command acts on: the machine the
+ * user is connected to. Surfaces that display one target's status must pass
+ * that target explicitly instead of inheriting this. */
+function activeUpdateTarget(): UpdateTarget {
+ return isRemoteMode() ? 'backend' : 'client'
+}
+
+/**
+ * Open the updates overlay and kick off its check.
+ *
+ * Callers tied to a specific status surface pass its target; only genuinely
+ * generic entry points take the connection-mode default. The macOS "Check for
+ * Updates…" menu item is the former — it is the OS-standard affordance for
+ * updating *this app*, so in remote mode it checked the wrong machine and the
+ * Mac client silently drifted behind (#70266).
+ */
+export function openUpdatesWindow(target: UpdateTarget = activeUpdateTarget()): void {
+ openUpdateOverlayFor(target)
}
/**
@@ -263,19 +283,22 @@ export function openUpdatesWindow(): void {
* through the everything-flow so "update" means every machine, not just the
* active target — the single-target ternary is what left remote-mode users
* updating the backend forever while the GUI itself went stale.
+ *
+ * An explicit `target` opts out of both: the caller is acting on one named
+ * machine's status and must not fan out to the others.
*/
-export function startActiveUpdate(): void {
- if (hasMultipleUpdateTargets()) {
+export function startActiveUpdate(target?: UpdateTarget): void {
+ if (!target && hasMultipleUpdateTargets()) {
$updateOverlayOpen.set(true)
void applyEverythingUpdate()
return
}
- const target: UpdateTarget = isRemoteMode() ? 'backend' : 'client'
- $updateOverlayTarget.set(target)
+ const effective = target ?? activeUpdateTarget()
+ $updateOverlayTarget.set(effective)
$updateOverlayOpen.set(true)
- void (target === 'backend' ? applyBackendUpdate() : applyUpdates())
+ void (effective === 'backend' ? applyBackendUpdate() : applyUpdates())
}
/**
@@ -304,11 +327,11 @@ export function requestActiveUpdate(): void {
}
}
- const target: UpdateTarget = isRemoteMode() ? 'backend' : 'client'
+ const target = activeUpdateTarget()
const status = target === 'backend' ? $backendUpdateStatus.get() : $updateStatus.get()
if ((status?.behind ?? 0) > 0 || status?.updateAvailable) {
- startActiveUpdate()
+ startActiveUpdate(target)
return
}
@@ -373,7 +396,7 @@ export async function checkBackendUpdates(): Promise<DesktopUpdateStatus | null>
try {
const status = mapBackendCheck(await checkHermesUpdate(true))
$backendUpdateStatus.set(status)
- maybeNotifyUpdateAvailable(status)
+ maybeNotifyUpdateAvailable(status, 'backend')
return status
} catch (error) {
@@ -404,7 +427,7 @@ export async function checkUpdates(): Promise<DesktopUpdateStatus | null> {
try {
const status = await bridge.check()
$updateStatus.set(status)
- maybeNotifyUpdateAvailable(status)
+ maybeNotifyUpdateAvailable(status, 'client')
void refreshDesktopVersion()
return status