The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): drop a profile's late messaging response after the scope switched (#96542)
teknium17b54f710bfe5
diff --git a/apps/desktop/src/app/messaging/index.test.tsx b/apps/desktop/src/app/messaging/index.test.tsxindex 5eb753fe1ae..aadba1f98ce 100644--- a/apps/desktop/src/app/messaging/index.test.tsx+++ b/apps/desktop/src/app/messaging/index.test.tsx@@ -216,6 +216,59 @@ describe('MessagingView enable switch', () => {$settingsScopeOverride.set(null)})})++ it("drops profile A's late response after the scope switched to B", async () => {+ // #96542 (second mechanism): A's in-flight getMessagingPlatforms resolves+ // AFTER the switch to B and must not repaint A's redacted token under B.+ const tokenA = '123456:AAE-profile-a-token'+ let resolveA: (value: unknown) => void = () => {}++ getMessagingPlatforms.mockImplementation((profile?: null | string) =>+ profile === 'profile-b'+ ? new Promise(() => {})+ : new Promise(resolve => {+ resolveA = resolve+ })+ )++ $settingsScopeOverride.set(null)+ await renderMessaging()++ await act(async () => {+ $settingsScopeOverride.set('profile-b')+ })++ await act(async () => {+ resolveA({+ platforms: [+ platform({+ env_vars: [+ {+ advanced: false,+ description: 'Telegram bot token from @BotFather.',+ is_password: true,+ is_set: true,+ key: 'TELEGRAM_TOKEN',+ prompt: 'Token',+ redacted_value: tokenA,+ required: true,+ url: null+ }+ ],+ id: 'telegram',+ name: 'Telegram'+ })+ ]+ })+ })++ expect(screen.queryByPlaceholderText(tokenA)).toBeNull()++ getMessagingPlatforms.mockReset()+ await act(async () => {+ $settingsScopeOverride.set(null)+ })+ })})describe('MessagingView setup-guide link', () => {diff --git a/apps/desktop/src/app/messaging/index.tsx b/apps/desktop/src/app/messaging/index.tsxindex a7448b3c802..f94f7849261 100644--- a/apps/desktop/src/app/messaging/index.tsx+++ b/apps/desktop/src/app/messaging/index.tsx@@ -1,6 +1,6 @@import { useStore } from '@nanostores/react'import type * as React from 'react'-import { useCallback, useEffect, useMemo, useState } from 'react'+import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { PageLoader } from '@/components/page-loader'import { StatusDot, type StatusTone } from '@/components/status-dot'@@ -179,6 +179,14 @@ export function MessagingView({ setStatusbarItemGroup: _setStatusbarItemGroup, .setRestartNeeded(true)}, [])+ // The scope each in-flight fetch was issued for. A→B: A's request can resolve+ // AFTER the switch and repaint A's platforms/env snapshot (its redacted+ // Telegram token included) under B until B's own response lands (#96542).+ // A response whose scope is no longer the rendered one is dropped.+ const scopeRef = useRef(scopeProfile)++ scopeRef.current = scopeProfile+const refreshPlatforms = useCallback(async (silent = false) => {if (!silent) {@@ -187,7 +195,10 @@ export function MessagingView({ setStatusbarItemGroup: _setStatusbarItemGroup, .try {const result = await getMessagingPlatforms(scopeProfile)- setPlatforms(result.platforms)++ if (scopeRef.current === scopeProfile) {+ setPlatforms(result.platforms)+ }} catch (err) {if (!silent) {notifyError(err, m.loadFailed)@@ -215,7 +226,10 @@ export function MessagingView({ setStatusbarItemGroup: _setStatusbarItemGroup, .const refreshPairing = useCallback(async () => {try {const result = await getPairing(scopeProfile)- setPairing({ approved: result.approved ?? [], pending: result.pending ?? [] })++ if (scopeRef.current === scopeProfile) {+ setPairing({ approved: result.approved ?? [], pending: result.pending ?? [] })+ }} catch {// Leave the last known rows in place rather than blanking them.}