Skip to content

The agent that grows with you

fix(webapp): name the picked profile in the live-status poll after a local reconnect

unsupportedpastelsa9a4af9fdc55
diff --git a/apps/desktop/src/app/contrib/hooks/use-background-sync.test.tsx b/apps/desktop/src/app/contrib/hooks/use-background-sync.test.tsx
index 93a0e4663d6..f33fe7fb7b3 100644
--- a/apps/desktop/src/app/contrib/hooks/use-background-sync.test.tsx
+++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.test.tsx
@@ -218,6 +218,48 @@ describe('useBackgroundSync live-status poll with no session open', () => {
window.history.replaceState(null, '', '/#/')
}
})
+
+ describe('on a native local gateway', () => {
+ // Native local profiles ride the one host backend too (multiplex-only routing): main
+ // resolves 'research' to the primary socket with sharedPrimary, and the primary's own
+ // descriptor to an unflagged local one.
+ const getConnection = vi.fn(async (profile?: string) =>
+ profile === 'research'
+ ? ({ mode: 'local', profile: 'research', sharedPrimary: true } as HermesConnection)
+ : ({ mode: 'local', profile: 'default' } as HermesConnection)
+ )
+
+ beforeEach(() => {
+ getConnection.mockClear()
+ Object.defineProperty(window, 'hermesDesktop', { configurable: true, value: { getConnection } })
+ })
+
+ afterEach(() => {
+ Reflect.deleteProperty(window, 'hermesDesktop')
+ })
+
+ it('keeps naming the picked profile after a reconnect republishes the primary local descriptor', async () => {
+ const request = vi.fn(async (_method: string, _params?: Record<string, unknown>) => ({ sessions: [] }))
+ $connection.set(await getConnection('research'))
+ render('research', 'local', async () => undefined, request as typeof requestGateway)
+ await act(async () => undefined)
+
+ $connection.set(await getConnection())
+ await act(async () => {
+ $sessionsChangeTick.set(1)
+ })
+ await act(async () => undefined)
+
+ expect(
+ request.mock.calls.filter(([method]) => method === 'session.active_list').map(([, params]) => params)
+ ).toEqual([{ profile: 'research' }, { profile: 'research' }])
+ })
+
+ it('names no profile and asks main nothing on the selected profile’s own local descriptor', async () => {
+ expect(await polledParams({ mode: 'local', profile: 'research' } as HermesConnection)).toEqual([{}])
+ expect(getConnection).not.toHaveBeenCalled()
+ })
+ })
})
describe('useBackgroundSync keeps a quiet working turn live', () => {
diff --git a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts b/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
index 7dd4a88c4c2..7e55032e307 100644
--- a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
@@ -912,15 +912,17 @@ export function rehydrateLiveSessionStatuses(
/** Params for the live-status poll. With a session open the session RPC
* dispatcher routes it to that session's owner, so it names nothing. With none
* open it rides the active socket, and a profile that shares the primary socket
- * (a Webapp tab's live pick, a global remote) is only reached by naming it: the
- * socket answers an unnamed request for its own profile, and the sidebar would
- * paint that profile's turns instead of the selected one's.
+ * (a Webapp tab's live pick, a native local profile, a global remote) is only
+ * reached by naming it: the socket answers an unnamed request for its own
+ * profile, and the sidebar would paint that profile's turns instead of the
+ * selected one's.
*
* The published descriptor is not enough on its own: a reconnect republishes
- * the primary's own descriptor (sharedPrimary false) while the picked profile
- * stays selected. So a remote descriptor that isn't the selected profile's own
- * asks main for the selected profile's route, the check requestGatewayForProfile
- * routes by. A local descriptor never shares the primary and asks nothing. */
+ * the primary's own descriptor (sharedPrimary false, local or remote) while the
+ * picked profile stays selected. So a descriptor that isn't the selected
+ * profile's own asks main for the selected profile's route, the check
+ * requestGatewayForProfile routes by. The selected profile's own descriptor
+ * asks nothing. */
async function liveStatusParams(activeGatewayProfile: string): Promise<Record<string, unknown>> {
const connection = $connection.get()
@@ -933,9 +935,8 @@ async function liveStatusParams(activeGatewayProfile: string): Promise<Record<st
}
const ownSocket =
- connection.mode !== 'remote' ||
- (Boolean(connection.profile?.trim()) &&
- normalizeProfileKey(connection.profile) === normalizeProfileKey(activeGatewayProfile))
+ Boolean(connection.profile?.trim()) &&
+ normalizeProfileKey(connection.profile) === normalizeProfileKey(activeGatewayProfile)
return !ownSocket && (await sharedPrimaryRoute(activeGatewayProfile)) ? { profile: activeGatewayProfile } : {}
}