Skip to content

The agent that grows with you

fix(desktop): name the session in blocking-prompt OS notifications

finn763eb7687b99568
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.test.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.test.ts
index 81db01a7d8d..29783ea8819 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.test.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/server-requests.test.ts
@@ -1,8 +1,10 @@
-import { afterEach, describe, expect, it, vi } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createClientSessionState } from '@/lib/chat-runtime'
+import { setActiveSessionId, setSessions } from '@/store/session'
import { $sessionTiles } from '@/store/session-states'
import { $toursEnabled } from '@/store/tours'
+import type { SessionInfo } from '@/types/hermes'
import { handleServerRequest, previewSessionRoute } from './server-requests'
import type { ServerRequestContext } from './server-requests'
@@ -42,6 +44,36 @@ describe('connection request routing', () => {
})
})
+describe('approval request routing', () => {
+ const notify = vi.fn().mockResolvedValue(true)
+ const desktopWindow = window as unknown as { hermesDesktop?: Window['hermesDesktop'] }
+
+ beforeEach(() => {
+ notify.mockClear()
+ desktopWindow.hermesDesktop = { notify } as unknown as Window['hermesDesktop']
+ setSessions([{ id: 'session-a', title: 'Fix the flaky test' } as SessionInfo])
+ setActiveSessionId('session-b')
+ })
+
+ afterEach(() => {
+ delete desktopWindow.hermesDesktop
+ setSessions([])
+ setActiveSessionId(null)
+ })
+
+ it('titles the parked approval toast with the session it belongs to', () => {
+ deliver(
+ 'approval',
+ { command: 'rm -rf /', description: 'dangerous', request_id: 'r1', session_id: 'session-a' },
+ 'session-b'
+ )
+
+ expect(notify).toHaveBeenCalledWith(
+ expect.objectContaining({ kind: 'approval', title: 'Approval needed — Fix the flaky test' })
+ )
+ })
+})
+
describe('preview action request routing', () => {
it('retries a replayed scoped request only while no session is bound yet', () => {
expect(previewSessionRoute({ replayed: true, sessionId: 'session-a', activeSessionId: null })).toBe('retry')
diff --git a/apps/desktop/src/store/native-notifications.test.ts b/apps/desktop/src/store/native-notifications.test.ts
index b9358bb8d3f..b2e6577c1db 100644
--- a/apps/desktop/src/store/native-notifications.test.ts
+++ b/apps/desktop/src/store/native-notifications.test.ts
@@ -1,6 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createClientSessionState } from '@/lib/chat-runtime'
+import type { SessionInfo } from '@/types/hermes'
import { $gateway } from './gateway'
import {
@@ -18,7 +19,7 @@ import {
import { __resetNativeNotifyBaselineForTests, markNativeNotifyBaseline } from './notify-baseline'
import { $approvalRequest, clearAllPrompts, setApprovalRequest } from './prompts'
import { markSessionGone, resetBackgroundPollingGuard } from './runtime-gone'
-import { $activeSessionId, setActiveSessionId } from './session'
+import { $activeSessionId, setActiveSessionId, setSessions } from './session'
import { dropSessionState, publishSessionState } from './session-states'
const desktopWindow = window as unknown as { hermesDesktop?: Window['hermesDesktop'] }
@@ -168,6 +169,47 @@ describe('dispatchNativeNotification preferences', () => {
})
})
+describe('dispatchNativeNotification session context', () => {
+ it('names the session in a blocking-prompt title so parked approvals stay tellable apart', () => {
+ setSessions([{ id: 'review-chat', title: 'Fix the flaky test' } as SessionInfo])
+
+ try {
+ dispatchNativeNotification({ kind: 'approval', sessionId: 'review-chat', title: 'Approval needed' })
+ expect(notify).toHaveBeenCalledWith(expect.objectContaining({ title: 'Approval needed — Fix the flaky test' }))
+ } finally {
+ setSessions([])
+ }
+ })
+
+ it('carries the same label on the sibling input.request toast', () => {
+ setSessions([{ id: 'named-chat', title: 'Migrate the schema' } as SessionInfo])
+
+ try {
+ dispatchNativeNotification({ kind: 'input', sessionId: 'named-chat', title: 'Input needed' })
+ expect(notify).toHaveBeenCalledWith(expect.objectContaining({ title: 'Input needed — Migrate the schema' }))
+ } finally {
+ setSessions([])
+ }
+ })
+
+ it('falls back to a short id tail while the session has no row yet', () => {
+ dispatchNativeNotification({ kind: 'approval', sessionId: 'abcdef123456', title: 'Approval needed' })
+ expect(notify).toHaveBeenCalledWith(expect.objectContaining({ title: 'Approval needed — #123456' }))
+ })
+
+ it('leaves a completion title alone (only blocking prompts need the session)', () => {
+ setSessions([{ id: 'done-chat', title: 'Fix the flaky test' } as SessionInfo])
+ setActiveSessionId('done-chat')
+
+ try {
+ dispatchNativeNotification({ kind: 'turnDone', sessionId: 'done-chat', title: 'Hermes finished' })
+ expect(notify).toHaveBeenCalledWith(expect.objectContaining({ title: 'Hermes finished' }))
+ } finally {
+ setSessions([])
+ }
+ })
+})
+
describe('dispatchNativeNotification post-connect baseline', () => {
it('suppresses a prompt replayed right after a socket opens', () => {
markNativeNotifyBaseline()
diff --git a/apps/desktop/src/store/native-notifications.ts b/apps/desktop/src/store/native-notifications.ts
index d7a71a40142..cc70fa13f0b 100644
--- a/apps/desktop/src/store/native-notifications.ts
+++ b/apps/desktop/src/store/native-notifications.ts
@@ -13,7 +13,7 @@ import {
sessionApprovalRequests
} from './prompts'
import { isSessionGone, isSessionGoneForBackgroundPolling, markSessionGone } from './runtime-gone'
-import { $activeSessionId } from './session'
+import { $activeSessionId, ownerLookupSessionRows, sessionMatchesStoredId } from './session'
import { storedSessionIdForRuntimeId } from './session-states'
export type { HermesOpenTarget }
@@ -155,6 +155,26 @@ function shouldFire(kind: NativeNotificationKind, sessionId?: null | string, glo
return isBackgrounded() && Boolean(sessionId) && sessionId === $activeSessionId.get()
}
+/** Last-resort label for a session the renderer has no row for (yet): the id
+ * tail still tells three parked approvals apart. */
+const shortSessionId = (id: string) => `#${id.slice(-6)}`
+
+/** Name the session in a blocking-prompt title: "Approval needed — Fix the flaky
+ * test". Without it every parallel parked approval raises an identical OS toast
+ * and the user cannot tell which chat is waiting (the runtime id the caller
+ * already passes is the whole hint needed). */
+function withSessionLabel(title: string, runtimeSessionId: string): string {
+ const storedId = storedSessionIdForRuntimeId(runtimeSessionId) ?? runtimeSessionId
+ const row = ownerLookupSessionRows().find(session => sessionMatchesStoredId(session, storedId))
+ const name = row?.title?.trim() || row?.preview?.trim()
+
+ if (!name) {
+ return `${title} — ${shortSessionId(storedId)}`
+ }
+
+ return `${title} — ${name.length > 80 ? `${name.slice(0, 80).trimEnd()}…` : name}`
+}
+
export interface NativeNotificationAction {
id: string
text: string
@@ -214,6 +234,9 @@ export function dispatchNativeNotification(input: NativeNotificationInput): bool
return false
}
+ const title =
+ ATTENTION_KINDS.has(input.kind) && input.sessionId ? withSessionLabel(input.title, input.sessionId) : input.title
+
void window.hermesDesktop?.notify({
actions: input.actions,
activate: input.activate,
@@ -225,7 +248,7 @@ export function dispatchNativeNotification(input: NativeNotificationInput): bool
sessionId: input.sessionId ?? undefined,
silent: input.silent,
tag: input.tag,
- title: input.title
+ title
})
return true