The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): give ⌘T session tabs a live gateway so slash completions load
Brooklyn Nicholsonbfc8e3b00db4
diff --git a/apps/desktop/src/app/chat/session-tile.tsx b/apps/desktop/src/app/chat/session-tile.tsxindex 410cf87e2e4..6ca29e70ade 100644--- a/apps/desktop/src/app/chat/session-tile.tsx+++ b/apps/desktop/src/app/chat/session-tile.tsx@@ -113,7 +113,7 @@ function TileChat({storedSessionId: stringview: SessionView}) {- const { gatewayRef, requestGateway } = useGatewayRequest()+ const { gateway, requestGateway } = useGatewayRequest()const queryClient = useQueryClient()const { selectModel } = useModelControls({ queryClient, requestGateway })const activeGatewayProfile = useStore($activeGatewayProfile)@@ -151,20 +151,20 @@ function TileChat({() =>gatewayOpen ? (<ModelMenuPanel- gateway={gatewayRef.current || undefined}+ gateway={gateway || undefined}onSelectModel={selectModel}profile={activeGatewayProfile}requestGateway={requestGateway}/>) : null,- [activeGatewayProfile, gatewayOpen, gatewayRef, requestGateway, selectModel]+ [activeGatewayProfile, gateway, gatewayOpen, requestGateway, selectModel])return (<SessionViewProvider value={view}><ComposerScopeProvider value={scope}><ChatView- gateway={gatewayRef.current}+ gateway={gateway}modelMenuContent={modelMenuContent}onAddContextRef={composer.addContextRefAttachment}onAddUrl={url => composer.addContextRefAttachment(`@url:${formatRefValue(url)}`, url)}diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsxindex e8716bde926..963fc67c3d0 100644--- a/apps/desktop/src/app/contrib/wiring.tsx+++ b/apps/desktop/src/app/contrib/wiring.tsx@@ -222,7 +222,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {setMessages})- const { connectionRef, gatewayRef, requestGateway } = useGatewayRequest()+ const { connectionRef, gateway, gatewayRef, requestGateway } = useGatewayRequest()const {loadMoreMessagingForPlatform,@@ -943,13 +943,13 @@ export function ContribWiring({ children }: { children: ReactNode }) {/>)}<ModelPickerOverlay- gateway={gatewayRef.current || undefined}+ gateway={gateway || undefined}onSelect={selectModel}profile={activeGatewayProfile}/><SessionPickerOverlay onResume={resumeSession} /><ModelVisibilityOverlay- gateway={gatewayRef.current || undefined}+ gateway={gateway || undefined}onOpenProviders={openProviderSettings}profile={activeGatewayProfile}/>@@ -965,7 +965,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {{settingsOpen && (<Suspense fallback={null}><SettingsView- gateway={gatewayRef.current}+ gateway={gateway}onClose={closeOverlayToPreviousRoute}onConfigSaved={() => {void refreshHermesConfig()diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-request.test.ts b/apps/desktop/src/app/gateway/hooks/use-gateway-request.test.tsnew file mode 100644index 00000000000..72ad6a2a268--- /dev/null+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-request.test.ts@@ -0,0 +1,39 @@+import { act, renderHook } from '@testing-library/react'+import { afterEach, describe, expect, it } from 'vitest'++import type { HermesGateway } from '@/hermes'+import { $gateway } from '@/store/gateway'++import { useGatewayRequest } from './use-gateway-request'++const fakeGateway = { connectionState: 'open' } as unknown as HermesGateway++afterEach(() => {+ $gateway.set(null)+})++describe('useGatewayRequest', () => {+ // The composer's `/` completions only exist when ChatBar receives a non-null+ // gateway PROP. `gatewayRef` is populated by a subscription effect, so it is+ // still null on the first render — a surface that read the ref while+ // rendering (session tiles / ⌘T tabs) shipped `gateway={null}` and silently+ // lost slash completions. The returned `gateway` value must be live+ // immediately so that never happens again.+ it('exposes the live gateway on the first render, before effects run', () => {+ $gateway.set(fakeGateway)++ const { result } = renderHook(() => useGatewayRequest())++ expect(result.current.gateway).toBe(fakeGateway)+ })++ it('tracks the gateway when the active socket changes', () => {+ const { result } = renderHook(() => useGatewayRequest())++ expect(result.current.gateway).toBeNull()++ act(() => $gateway.set(fakeGateway))++ expect(result.current.gateway).toBe(fakeGateway)+ })+})diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-request.ts b/apps/desktop/src/app/gateway/hooks/use-gateway-request.tsindex 76c98c17a23..04f53f785b4 100644--- a/apps/desktop/src/app/gateway/hooks/use-gateway-request.ts+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-request.ts@@ -9,6 +9,14 @@ import { $gatewayState, setConnection } from '@/store/session'export function useGatewayRequest() {const gatewayState = useStore($gatewayState)+ // Reactive companion to `gatewayRef`. The ref exists so `requestGateway`+ // keeps a stable identity and always reaches the live socket, but it is only+ // populated by the subscription effect below — i.e. AFTER the first render.+ // A component that reads `gatewayRef.current` while rendering therefore sees+ // null on mount, and if the connection state doesn't happen to flip+ // afterwards it never re-renders to pick the instance up. Anything that needs+ // the gateway as a render-time VALUE (props, memo deps) must use this.+ const gateway = useStore($gateway) as HermesGateway | nullconst gatewayRef = useRef<HermesGateway | null>(null)const connectionRef = useRef<Awaited<ReturnType<NonNullable<typeof window.hermesDesktop>['getConnection']>> | null>(@@ -136,5 +144,5 @@ export function useGatewayRequest() {[ensureGatewayOpen])- return { connectionRef, gatewayRef, requestGateway }+ return { connectionRef, gateway, gatewayRef, requestGateway }}