Skip to content

The agent that grows with you

fix(desktop): re-check backend updates when switching between two remote profiles

JackJin406ec797dd65
diff --git a/apps/desktop/src/store/updates.test.ts b/apps/desktop/src/store/updates.test.ts
index 78f187cc9ac..df641bae3d0 100644
--- a/apps/desktop/src/store/updates.test.ts
+++ b/apps/desktop/src/store/updates.test.ts
@@ -1501,6 +1501,51 @@ describe('startUpdatePoller', () => {
await vi.advanceTimersByTimeAsync(0)
expect(checkMock).toHaveBeenCalledTimes(1)
})
+
+ it('re-checks backend updates when switching directly between two remote profiles', async () => {
+ // Both profiles resolve to mode: 'remote' — only baseUrl differs. A
+ // mode-only comparison would treat this as "no change" and never
+ // re-check, leaving profile A's stale status on screen for profile B.
+ checkHermesUpdateSpy.mockReset()
+ checkHermesUpdateSpy.mockResolvedValue({
+ install_method: 'git',
+ current_version: '0.16.0',
+ behind: 1,
+ update_available: true,
+ can_apply: true,
+ update_command: 'hermes update',
+ message: null
+ })
+
+ setConnection({
+ baseUrl: 'http://profile-a:9119',
+ isFullscreen: false,
+ mode: 'remote',
+ nativeOverlayWidth: 0,
+ token: 't',
+ wsUrl: 'ws://profile-a:9119',
+ logs: [],
+ windowButtonPosition: null
+ })
+
+ startUpdatePoller()
+ await vi.advanceTimersByTimeAsync(0)
+ checkHermesUpdateSpy.mockClear()
+
+ setConnection({
+ baseUrl: 'http://profile-b:9119',
+ isFullscreen: false,
+ mode: 'remote',
+ nativeOverlayWidth: 0,
+ token: 't',
+ wsUrl: 'ws://profile-b:9119',
+ logs: [],
+ windowButtonPosition: null
+ })
+ await vi.advanceTimersByTimeAsync(0)
+
+ expect(checkHermesUpdateSpy).toHaveBeenCalled()
+ })
})
describe('discontinued retirement notice', () => {
diff --git a/apps/desktop/src/store/updates.ts b/apps/desktop/src/store/updates.ts
index 920da298870..c9dcb43b827 100644
--- a/apps/desktop/src/store/updates.ts
+++ b/apps/desktop/src/store/updates.ts
@@ -1072,7 +1072,15 @@ function ingestProgress(payload: DesktopUpdateProgress): void {
let pollerStarted = false
let backgroundTimer: ReturnType<typeof setInterval> | null = null
let connectionUnsub: (() => void) | null = null
-let lastConnectionMode: string | undefined
+let lastConnectionKey: string | undefined
+
+// mode alone can't tell two remote backends apart — switching directly from
+// remote profile A to remote profile B leaves mode === 'remote' both times.
+// Key on the actual backend target so a target change re-checks even when
+// the mode doesn't.
+function connectionKey(conn: HermesConnection | null): string {
+ return conn?.mode === 'remote' ? `remote:${conn.baseUrl}` : String(conn?.mode)
+}
export const BACKGROUND_UPDATE_CHECK_MS = 24 * 60 * 60 * 1000
const FOCUS_RECHECK_KEY = 'hermes.updates.last-passive-check'
@@ -1108,13 +1116,16 @@ export function startUpdatePoller(): void {
// The poller starts at mount, before the gateway connects — so the first
// backend check above sees mode≠remote and no-ops. Re-check once the
- // connection resolves to remote.
+ // connection resolves to remote, and again whenever the remote target
+ // itself changes (switching between two remote profiles).
connectionUnsub = $connection.subscribe((conn: HermesConnection | null): void => {
- if (conn?.mode === lastConnectionMode) {
+ const key = connectionKey(conn)
+
+ if (key === lastConnectionKey) {
return
}
- lastConnectionMode = conn?.mode
+ lastConnectionKey = key
if (conn?.mode === 'remote') {
void checkBackendUpdates()
@@ -1133,7 +1144,7 @@ export function stopUpdatePoller(): void {
connectionUnsub?.()
connectionUnsub = null
- lastConnectionMode = undefined
+ lastConnectionKey = undefined
window.removeEventListener('focus', onFocus)
pollerStarted = false
}