The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a local primary never absorbs a pooled profile's chat when the pool probe fails
teknium10dcbc9e5ba86
diff --git a/apps/desktop/src/store/gateway-profile-request.test.ts b/apps/desktop/src/store/gateway-profile-request.test.tsindex 5dfc6f11608..705dbce79a4 100644--- a/apps/desktop/src/store/gateway-profile-request.test.ts+++ b/apps/desktop/src/store/gateway-profile-request.test.ts@@ -677,6 +677,33 @@ describe('attached shared-remote group turns (#96493)', () => {expect(primary.request).toHaveBeenCalledOnce()})+ it('never collapses a pooled LOCAL profile onto the primary when its pool probe fails', async () => {+ // A local Desktop primary is one `hermes serve --profile <primary>` child;+ // pooled profiles get their own child. Sending `session.create` with+ // `profile: sean` to the primary still succeeds (profile_home+ // multiplexing), but the lease then belongs to the primary's pid while+ // every later resume — after a renderer reload or a pool respawn — dials+ // sean's pool backend and is refused with SESSION_NOT_OWNED.+ const primary = makePrimary()+ setPrimaryGateway(primary as never, 'default')+ setPrimaryGatewayConnection({ connectionId: 'local', mode: 'local' })+ ;(window as unknown as { hermesDesktop: unknown }).hermesDesktop = {+ getConnection: vi.fn(async (profile: null | string) => ({ mode: 'local', port: 4242, profile, token: 't' })),+ getConnectionFor: vi.fn(async () => {+ throw new Error('Timed out connecting to profile "sean"')+ }),+ getGatewayWsUrlFor: vi.fn(async () => ({ ok: true as const, wsUrl: 'ws://local/sean' })),+ touchBackend: vi.fn(async () => undefined)+ }+ await ensureGatewayForProfile('default')++ await expect(requestGatewayForAgent('local', 'sean', 'session.create', { title: 'g' })).rejects.toThrow(+ /Timed out connecting to profile "sean"/+ )++ expect(primary.request).not.toHaveBeenCalled()+ })+it('returning to an attached shared remote activates its socket without closing the other source', async () => {const primary = makePrimary()setPrimaryGateway(primary as never, 'default')diff --git a/apps/desktop/src/store/gateway.ts b/apps/desktop/src/store/gateway.tsindex 141d8917c11..77093cf124e 100644--- a/apps/desktop/src/store/gateway.ts+++ b/apps/desktop/src/store/gateway.ts@@ -180,6 +180,10 @@ interface GatewayRegistryState {primaryGateway: HermesGateway | null/** Registry source currently served by primaryGateway, when known. */primaryConnectionId: null | string+ /** Resolved mode of the primary's descriptor: a `local` primary is ONE+ * `hermes serve --profile <primary>` child and can never stand in for a+ * pooled profile's own backend. */+ primaryConnectionMode: 'local' | 'remote' | nullprimaryProfile: stringactiveKey: stringactivationEpoch: number@@ -201,6 +205,7 @@ function createRegistryState(): GatewayRegistryState {config: null,primaryGateway: null,primaryConnectionId: null,+ primaryConnectionMode: null,primaryProfile: 'default',activeKey: 'default',activationEpoch: 0,@@ -316,6 +321,7 @@ export function setPrimaryGateway(gateway: HermesGateway | null, profile = 'defaif (g.primaryGateway !== gateway) {g.primaryConnectionId = null+ g.primaryConnectionMode = null}// Route identity is exact-scope, never bare-name (#93892 follow-up): when@@ -336,7 +342,10 @@ export function setPrimaryGateway(gateway: HermesGateway | null, profile = 'defa}}-export function setPrimaryGatewayConnectionId(connectionId: null | string | undefined): void {+export function setPrimaryGatewayConnectionId(+ connectionId: null | string | undefined,+ mode: 'local' | 'remote' | null | undefined = undefined+): void {// Hardening for #95628: while the active route is a secondary scope, the// window is looking at a NON-primary socket — any connection id flowing// through presentation-layer code at that moment describes the secondary,@@ -349,6 +358,7 @@ export function setPrimaryGatewayConnectionId(connectionId: null | string | unde}g.primaryConnectionId = (connectionId ?? '').trim() || null+ g.primaryConnectionMode = mode === 'local' || mode === 'remote' ? mode : nullif (g.activeKey === g.primaryProfile) {setApiRequestConnection(g.primaryConnectionId)@@ -356,8 +366,8 @@ export function setPrimaryGatewayConnectionId(connectionId: null | string | unde}/** Publish the registry source owned by the window primary socket. */-export function setPrimaryGatewayConnection(connection: Pick<HermesConnection, 'connectionId'> | null): void {- setPrimaryGatewayConnectionId(connection?.connectionId)+export function setPrimaryGatewayConnection(connection: Pick<HermesConnection, 'connectionId' | 'mode'> | null): void {+ setPrimaryGatewayConnectionId(connection?.connectionId, connection?.mode)}function isPrimaryRegistryRoute(connectionId: null | string, profile: string): boolean {@@ -413,11 +423,18 @@ async function isAttachedSharedRemote(return Boolean(conn && typeof conn === 'object' && (conn as { sharedRemote?: boolean }).sharedRemote === true)} catch {- // Probe failed. A secondary at this already-attached source is the #96493- // ghost WebSocket (accept/close, messages=1). Prefer the primary until a- // later probe can prove isolation (`sharedRemote: false`). Isolated SSH- // still dials its own socket when getConnectionFor succeeds.- return true+ // Probe failed. On a REMOTE primary a secondary at this already-attached+ // source is the #96493 ghost WebSocket (accept/close, messages=1), so+ // prefer the primary until a later probe can prove isolation+ // (`sharedRemote: false`). A LOCAL primary is a different animal: it is+ // one `hermes serve --profile <primary>` child and every other local+ // profile has its own pooled child. The primary would still ACCEPT a+ // `profile`-tagged session.create (profile_home multiplexing) and mint+ // the session under its own pid, but the exact-owner route then names the+ // pool backend — after a renderer reload or a pool respawn the resume+ // dials that backend and is refused SESSION_NOT_OWNED by a pid of the+ // same Desktop (#101416). Let the pooled dial surface its own failure.+ return g.primaryConnectionMode !== 'local'}}