The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): the Bot Screen install card is app-level, not bound to the ambient chat
teknium1bd2ae0a8eb1f
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.test.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.test.tsnew file mode 100644index 00000000000..78ecb004622--- /dev/null+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.test.ts@@ -0,0 +1,46 @@+import { afterEach, describe, expect, it, vi } from 'vitest'++import { $activeSessionId } from '@/store/session'+import { $sudoRequest, clearSudoRequest } from '@/store/prompts'++import { handleInputRequestEvent } from './input-requests'+import type { GatewayEventContext } from './types'++vi.mock('@/store/native-notifications', () => ({ dispatchNativeNotification: vi.fn() }))++function context(type: string, requestId: string, routedSession: string | null): GatewayEventContext {+ const payload = { request_id: requestId, profile_key: '/home/h/.hermes' }+ return {+ deps: { updateSessionState: vi.fn() } as unknown as GatewayEventContext['deps'],+ event: { payload, type },+ explicitSid: '',+ fromActiveSource: () => true,+ isActiveEvent: true,+ occurredAt: 1,+ payload: payload as GatewayEventContext['payload'],+ scheduleConfigRefresh: vi.fn(),+ sessionId: routedSession+ }+}++describe('Bot Screen install password card', () => {+ afterEach(() => {+ clearSudoRequest()+ $activeSessionId.set(null)+ })++ it('belongs to the app, not to the chat that happened to be open: it survives a chat switch and its expiry finds it', () => {+ // The gateway emits the card sessionless; the stream resolver attributes an unscoped event to the+ // ambient chat. Stored under that chat, the card vanished the moment the user switched chats and+ // the expiry (routed to the NEW ambient chat) never reached it.+ $activeSessionId.set('chat-a')+ expect(handleInputRequestEvent(context('display.install.sudo.request', 'req-1', 'chat-a'))).toBe(true)+ expect($sudoRequest.get()?.requestId).toBe('req-1')++ $activeSessionId.set('chat-b')+ expect($sudoRequest.get()?.requestId).toBe('req-1')++ expect(handleInputRequestEvent(context('display.install.sudo.expire', 'req-1', 'chat-b'))).toBe(true)+ expect($sudoRequest.get()).toBeNull()+ })+})diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.tsindex 2ad74121fb2..ab9988f9507 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/input-requests.ts@@ -206,9 +206,12 @@ export function handleInputRequestEvent(ctx: GatewayEventContext): boolean {}if (event.type === 'sudo.expire' || event.type === 'display.install.sudo.expire') {- // The backend gave up waiting; tear the card down so a late Send cannot go anywhere.+ // The backend gave up waiting; tear the card down so a late Send cannot go anywhere. The install+ // card is app-level (stored under the null session), so its expiry must not be routed to whatever+ // chat is active now.const requestId = typeof payload?.request_id === 'string' ? payload.request_id : ''- clearSudoRequest(sessionId ?? undefined, requestId || undefined)+ const install = event.type === 'display.install.sudo.expire'+ clearSudoRequest(install ? null : sessionId ?? undefined, requestId || undefined)return true}@@ -331,15 +334,18 @@ export function handleInputRequestEvent(ctx: GatewayEventContext): boolean {const install = event.type === 'display.install.sudo.request'if (requestId) {+ // The install card belongs to the app, not to a chat: the gateway emits it sessionless and the+ // stream resolver would otherwise attribute it to the ambient chat, hiding it on a chat switch.+ const owner = install ? null : sessionId ?? nullsetSudoRequest({requestId,- sessionId: sessionId ?? null,+ sessionId: owner,origin: { connectionId: event.connectionId ?? null, profile: event.profile ?? $activeGatewayProfile.get() },...(install ? { respondMethod: 'display.install.sudo.respond', description: translateNow('prompts.sudoInstallDesc') } : {})})- if (sessionId) {- updateSessionState(sessionId, state => ({ ...state, needsInput: true }))+ if (owner) {+ updateSessionState(owner, state => ({ ...state, needsInput: true }))}dispatchNativeNotification({diff --git a/apps/desktop/src/store/prompts.ts b/apps/desktop/src/store/prompts.tsindex e08c4584697..9de2c842dda 100644--- a/apps/desktop/src/store/prompts.ts+++ b/apps/desktop/src/store/prompts.ts@@ -41,7 +41,10 @@ function keyedPromptStore<T extends KeyedPrompt>(): PromptStore<T> {const idOf = (value: T): string | undefined => (value as { requestId?: string }).requestIdreturn {- $active: computed([$all, $activeSessionId], (all, activeId) => all[keyFor(activeId)] ?? null),+ // An app-level prompt (sessionId null: the Bot Screen install card) is not about any chat, so it is+ // shown in whichever chat is active rather than only while the chat that happened to be open at+ // request time stays open.+ $active: computed([$all, $activeSessionId], (all, activeId) => all[keyFor(activeId)] ?? all[keyFor(null)] ?? null),$all,reset: () => $all.set({}),set: request => $all.set({ ...$all.get(), [keyFor(request.sessionId)]: request }),