Skip to content

The agent that grows with you

fix(desktop): scope tour responses to active session

fangliquanflq0596631bf3d0
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/desktop-bridge.test.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/desktop-bridge.test.ts
index 5aee1b7b713..ef664fe0e03 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/desktop-bridge.test.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/desktop-bridge.test.ts
@@ -1,6 +1,7 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { $gateway } from '@/store/gateway'
+import { $toursEnabled } from '@/store/tours'
import { handleDesktopBridgeEvent } from './desktop-bridge'
import type { GatewayEventContext } from './types'
@@ -47,3 +48,48 @@ describe('preview action bridge routing', () => {
})
})
})
+
+function tourContext({
+ explicitSid,
+ isActiveEvent
+}: {
+ explicitSid: string
+ isActiveEvent: boolean
+}): GatewayEventContext {
+ return {
+ event: { session_id: explicitSid || undefined, type: 'tour.request' },
+ explicitSid,
+ isActiveEvent,
+ payload: { action: 'discover', request_id: 'tour-request-1' }
+ } as GatewayEventContext
+}
+
+describe('tour bridge routing', () => {
+ afterEach(() => {
+ $gateway.set(null)
+ $toursEnabled.set(true)
+ })
+
+ it('leaves a scoped request unanswered in another session even when tours are disabled', () => {
+ const request = vi.fn()
+ $gateway.set({ request } as never)
+ $toursEnabled.set(false)
+
+ expect(handleDesktopBridgeEvent(tourContext({ explicitSid: 'session-a', isActiveEvent: false }))).toBe(true)
+ expect(request).not.toHaveBeenCalled()
+ })
+
+ it('keeps the legacy fail-fast response for an unscoped inactive request', () => {
+ const request = vi.fn()
+ $gateway.set({ request } as never)
+
+ expect(handleDesktopBridgeEvent(tourContext({ explicitSid: '', isActiveEvent: false }))).toBe(true)
+ expect(request).toHaveBeenCalledWith('tour.respond', {
+ request_id: 'tour-request-1',
+ text: JSON.stringify({
+ error: 'Tours only run in the session the user is looking at.',
+ success: false
+ })
+ })
+ })
+})
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/desktop-bridge.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/desktop-bridge.ts
index a9d6b4fe739..be9edae8421 100644
--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/desktop-bridge.ts
+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/desktop-bridge.ts
@@ -186,6 +186,13 @@ export function handleDesktopBridgeEvent(ctx: GatewayEventContext): boolean {
const requestId = typeof payload?.request_id === 'string' ? payload.request_id : ''
if (requestId) {
+ // As with preview actions, only the renderer that owns an explicitly
+ // scoped request may answer. Inactive windows must stay silent even when
+ // tours are disabled locally, or their refusal can beat the owner.
+ if (explicitSid && !isActiveEvent) {
+ return true
+ }
+
const answer = (result: unknown) =>
$gateway.get()?.request('tour.respond', {
request_id: requestId,