The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): paint stored Bot Chat history immediately instead of stranding the wake on an unsatisfiable profile gate
Tekniumdd0aae4173ec
diff --git a/apps/desktop/src/app/chat/chat-swap-overlay.tsx b/apps/desktop/src/app/chat/chat-swap-overlay.tsxindex 0226a63d347..4e8068f2a45 100644--- a/apps/desktop/src/app/chat/chat-swap-overlay.tsx+++ b/apps/desktop/src/app/chat/chat-swap-overlay.tsx@@ -39,3 +39,26 @@ export function ChatSwapOverlay({ profile }: { profile: string | null }) {</div>)}++// Subtle corner badge for a PAINT-FIRST wake (#89843): the stored transcript+// is already on screen and usable, but the active-profile gate hasn't caught+// up yet (shared-remote serves every profile through the primary socket).+// Deliberately quiet — a pill in the corner, not an overlay — because the+// content is real; only the background profile sync is still settling.+export function ChatSyncBadge({ profile }: { profile: string | null }) {+ const { t } = useI18n()++ if (!profile) {+ return null+ }++ return (+ <div+ aria-live="polite"+ className="pointer-events-none absolute right-3 top-2 z-30 flex items-center gap-1.5 rounded-full border border-border/50 bg-[color-mix(in_srgb,var(--dt-card)_92%,transparent)] px-2 py-0.5 font-mono text-[0.6875rem] text-muted-foreground shadow-composer"+ >+ <GlyphSpinner className="w-3 justify-start text-(--ui-accent)" spinner="braille" />+ {t.desktop.hydrationSyncing(profile)}+ </div>+ )+}diff --git a/apps/desktop/src/app/chat/index.test.tsx b/apps/desktop/src/app/chat/index.test.tsxindex 8caace4cc98..52571fcba3d 100644--- a/apps/desktop/src/app/chat/index.test.tsx+++ b/apps/desktop/src/app/chat/index.test.tsx@@ -47,7 +47,7 @@ vi.mock('@/lib/model-options', () => ({requestModelOptions: vi.fn(async () => ({ models: [] }))}))vi.mock('./chat-drop-overlay', () => ({ ChatDropOverlay: () => null }))-vi.mock('./chat-swap-overlay', () => ({ ChatSwapOverlay: () => null }))+vi.mock('./chat-swap-overlay', () => ({ ChatSwapOverlay: () => null, ChatSyncBadge: () => null }))vi.mock('./composer', () => ({ ChatBar: () => null, ChatBarFallback: () => null }))vi.mock('./hooks/use-file-drop-zone', () => ({useFileDropZone: () => ({ dragKind: null, dropHandlers: {} })diff --git a/apps/desktop/src/app/chat/index.tsx b/apps/desktop/src/app/chat/index.tsxindex b0965a66621..d263ff9fad6 100644--- a/apps/desktop/src/app/chat/index.tsx+++ b/apps/desktop/src/app/chat/index.tsx@@ -31,7 +31,7 @@ import { $introSplash } from '@/store/intro-splash'import { $pinnedSessionIds } from '@/store/layout'import { $petActive } from '@/store/pet'import { $petOverlayActive } from '@/store/pet-overlay'-import { $activeGatewayProfile, $gatewaySwapTarget, $profiles } from '@/store/profile'+import { $activeGatewayProfile, $gatewaySwapTarget, $hydrationSyncProfile, $profiles } from '@/store/profile'import {$connection,$contextSuggestions,@@ -56,7 +56,7 @@ import { primaryRouteSelectedSessionId, routeSessionId } from '../routes'import { titlebarHeaderBaseClass, titlebarHeaderShadowClass, titlebarHeaderTitleClass } from '../shell/titlebar'import { ChatDropOverlay } from './chat-drop-overlay'-import { ChatSwapOverlay } from './chat-swap-overlay'+import { ChatSwapOverlay, ChatSyncBadge } from './chat-swap-overlay'import { ChatBar, ChatBarFallback } from './composer'import { requestComposerInsert } from './composer/focus'import { droppedFileInlineRefs } from './composer/inline-refs'@@ -419,6 +419,7 @@ const ChatViewContent = memo(function ChatViewContent({const freshDraftReady = useStore($freshDraftReady)const gatewayState = useStore($gatewayState)const gatewaySwapTarget = useStore($gatewaySwapTarget)+ const hydrationSyncProfile = useStore($hydrationSyncProfile)const gatewayOpen = gatewayState === 'open'const introPersonality = useStore($introPersonality)const introSeed = useStore($introSeed)@@ -685,6 +686,9 @@ const ChatViewContent = memo(function ChatViewContent({target; the link overlay shows only for the center region. */}<ChatDropOverlay kind={overlayKind} /><ChatSwapOverlay profile={gatewaySwapTarget} />+ {/* Paint-first wake (#89843): transcript is live, profile gate still+ settling in the background — subtle badge, not an overlay. */}+ {isPrimary && !gatewaySwapTarget && <ChatSyncBadge profile={hydrationSyncProfile} />}</div>{/* Composer renders OUTSIDE the contain:[layout paint] wrapper above:that wrapper is a containing block for — and clips — position:fixeddiff --git a/apps/desktop/src/i18n/ar.ts b/apps/desktop/src/i18n/ar.tsindex eb018b7344b..8f8c72e8f25 100644--- a/apps/desktop/src/i18n/ar.ts+++ b/apps/desktop/src/i18n/ar.ts@@ -2793,6 +2793,7 @@ export const ar = defineLocale({cwdStagedTitle: 'تم تجهيز مجلد العمل',cwdStagedMessage: 'سيطبق مجلد العمل على الرسالة التالية.',modelSwitchFailed: 'فشل تبديل النموذج',+ hydrationSyncing: (profile: string) => `جارٍ مزامنة ${profile}\u2026`,sessionExported: 'تم تصدير الجلسة',sessionExportFailed: 'فشل تصدير الجلسة',imageSaved: 'تم حفظ الصورة',diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.tsindex 19d3fd770e8..0d2c9a335bf 100644--- a/apps/desktop/src/i18n/en.ts+++ b/apps/desktop/src/i18n/en.ts@@ -3396,6 +3396,7 @@ export const en: Translations = {cwdStagedTitle: 'Working directory staged',cwdStagedMessage: 'Restart the desktop backend to apply cwd changes to this active session.',modelSwitchFailed: 'Model switch failed',+ hydrationSyncing: (profile: string) => `Syncing ${profile}\u2026`,sessionExported: 'Session exported',sessionExportFailed: 'Could not export session',imageSaved: 'Image saved',diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.tsindex 7d89e577eab..f7613108769 100644--- a/apps/desktop/src/i18n/ja.ts+++ b/apps/desktop/src/i18n/ja.ts@@ -3045,6 +3045,7 @@ export const ja = defineLocale({cwdStagedMessage:'このアクティブなセッションへの cwd の変更を適用するにはデスクトップバックエンドを再起動してください。',modelSwitchFailed: 'モデルの切り替えに失敗しました',+ hydrationSyncing: (profile: string) => `${profile} を同期中\u2026`,sessionExported: 'セッションをエクスポートしました',sessionExportFailed: 'セッションをエクスポートできませんでした',imageSaved: '画像を保存しました',diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.tsindex 1b1962d4aad..5df1bf0f00e 100644--- a/apps/desktop/src/i18n/types.ts+++ b/apps/desktop/src/i18n/types.ts@@ -2916,6 +2916,7 @@ export interface Translations {cwdStagedTitle: stringcwdStagedMessage: stringmodelSwitchFailed: string+ hydrationSyncing: (profile: string) => stringsessionExported: stringsessionExportFailed: stringimageSaved: stringdiff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.tsindex 005ad3d1dd1..e06f28013d6 100644--- a/apps/desktop/src/i18n/zh-hant.ts+++ b/apps/desktop/src/i18n/zh-hant.ts@@ -2918,6 +2918,7 @@ export const zhHant = defineLocale({cwdStagedTitle: '工作目錄已暫存',cwdStagedMessage: '重新啟動桌面後端後,工作目錄變更才會套用至此作用中工作階段。',modelSwitchFailed: '模型切換失敗',+ hydrationSyncing: (profile: string) => `正在同步 ${profile}\u2026`,sessionExported: '工作階段已匯出',sessionExportFailed: '無法匯出工作階段',imageSaved: '圖片已儲存',diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.tsindex fd56a1a6187..2bc19f44a2d 100644--- a/apps/desktop/src/i18n/zh.ts+++ b/apps/desktop/src/i18n/zh.ts@@ -3540,6 +3540,7 @@ export const zh: Translations = {cwdStagedTitle: '工作目录已暂存',cwdStagedMessage: '重启桌面后端后,工作目录更改才会应用到当前活跃会话。',modelSwitchFailed: '模型切换失败',+ hydrationSyncing: (profile: string) => `正在同步 ${profile}\u2026`,sessionExported: '会话已导出',sessionExportFailed: '无法导出会话',imageSaved: '图片已保存',diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 20b0e56d504..dc508b48cf2 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -57,6 +57,7 @@ import { notify, notifyError } from '@/store/notifications'import {$activeGatewayProfile,$gatewaySwapTarget,+ $hydrationSyncProfile,$profiles,ensureGatewayAgent,ensureGatewayProfile,@@ -346,6 +347,24 @@ export interface PluginNewChatOptions {workspaceOwnerKey?: string}+// Raise the "Syncing…" affordance for a paint-first wake (#89843) and tear it+// down as soon as the active-profile gate catches up. The listener clears ONLY+// its own profile's badge: a newer wake may have replaced the badge with a+// different profile, and the stale listener must not wipe the winner's.+function beginHydrationBackgroundSync(profile: string): void {+ $hydrationSyncProfile.set(profile)++ const unlisten = $activeGatewayProfile.listen(next => {+ if (normalizeProfileKey(next) === profile) {+ if ($hydrationSyncProfile.get() === profile) {+ $hydrationSyncProfile.set(null)+ }++ unlisten()+ }+ })+}+function waitForFocusedSessionHydration({expectHistory,generation,@@ -432,8 +451,33 @@ function waitForFocusedSessionHydration({// surface is real rather than a stuck loader.const hydrated = expectHistory ? historyPainted : runtimeReady- if (profileMatches && (mainMatches || tileMatches) && hydrated) {- finish()+ if ((mainMatches || tileMatches) && hydrated) {+ if (profileMatches) {+ finish()++ return+ }++ // Paint-first completion on an unsatisfiable profile gate (#89843).+ // On a shared-remote connection every profile is legitimately served+ // through the primary socket, so $activeGatewayProfile can NEVER+ // equal the bot's profile — the old gate held a fully painted+ // transcript hostage for the whole 20s budget and then stranded the+ // pane. When the stored history is already painted on exactly this+ // session, that content IS the proof the surface is real: resolve+ // now, raise the subtle "Syncing…" affordance, and let the profile+ // gate catch up in the background.+ //+ // Fail closed everywhere the content is NOT its own proof: a+ // superseded generation already rejected above (conflicting+ // concurrent hydration never resolves paint-first), and an+ // expected-EMPTY chat keeps waiting for the full gate — with no+ // transcript to paint, a bound runtime on an unmatched profile is+ // not evidence of a real surface.+ if (expectHistory && historyPainted) {+ beginHydrationBackgroundSync(profile)+ finish()+ }}}@@ -745,6 +789,10 @@ export const host = {* also scope chrome onto that profile and collapse the sidebar. */openSession: async (storedSessionId: string, options: PluginOpenSessionOptions = {}): Promise<void> => {const generation = ++openSessionGeneration++ // A new wake owns the syncing affordance — a lingering badge from an+ // earlier paint-first wake must not survive into this one.+ $hydrationSyncProfile.set(null)const explicitRoute = options.route ? { ...options.route } : nullconst profile = (explicitRoute?.profile ?? options.profile ?? '').trim()const targetProfile = normalizeProfileKey(profile || $activeGatewayProfile.get())diff --git a/apps/desktop/src/sdk/profile-routing.test.ts b/apps/desktop/src/sdk/profile-routing.test.tsindex 973bcb511b1..43d70390311 100644--- a/apps/desktop/src/sdk/profile-routing.test.ts+++ b/apps/desktop/src/sdk/profile-routing.test.ts@@ -65,6 +65,7 @@ vi.mock('@/store/profile', async () => {return {$activeGatewayProfile: atom('remote-worker'),$gatewaySwapTarget: atom(null),+ $hydrationSyncProfile: atom(null),$profiles: profiles,ensureGatewayAgent: vi.fn(),ensureGatewayProfile: vi.fn(),@@ -119,6 +120,7 @@ const {const {$activeGatewayProfile,$gatewaySwapTarget,+ $hydrationSyncProfile,$profiles,ensureGatewayProfile,refreshProfiles,@@ -156,6 +158,7 @@ afterEach(() => {vi.mocked(activeGatewayConnectionId).mockReturnValue('local')$activeGatewayProfile.set('remote-worker')$gatewaySwapTarget.set(null)+ setMockAtom($hydrationSyncProfile, null)setMockAtom($focusedRuntimeId, null)setMockAtom($focusedStoredSessionId, null)setMockAtom($focusedSessionState, null)@@ -1153,3 +1156,98 @@ describe('profile-aware plugin session opens', () => {expect(setResumeExhaustedSessionId).not.toHaveBeenCalled()})})++describe('shared-remote hydration gate (#89843)', () => {+ it('paints stored history immediately instead of holding the wake on an unsatisfiable profile gate', async () => {+ $activeGatewayProfile.set('default')+ // Shared-remote: every profile is served through the primary socket, so+ // the dial resolves but $activeGatewayProfile NEVER moves to the bot's+ // profile — the old profileMatches gate could not be satisfied and the+ // wake burned the whole 20s budget with the transcript already painted.+ vi.mocked(ensureGatewayProfile).mockImplementationOnce(async () => undefined)++ const opening = host.openSession('shared-remote-bot', {+ awaitHydration: true,+ expectHistory: true,+ hydrationTimeoutMs: 250,+ keepAllProfilesScope: false,+ profile: 'shadow'+ })++ await Promise.resolve()+ setMockAtom($selectedStoredSessionId, 'shared-remote-bot')+ setMockAtom($activeSessionId, 'runtime-shared-remote')+ setMockAtom($messages, [{ id: 'stored-history', parts: [], role: 'assistant' }] as never)++ // Must resolve on the painted transcript, well inside the budget.+ await opening+ expect(setResumeExhaustedSessionId).not.toHaveBeenCalled()++ // The wake resolved paint-first, so the subtle syncing affordance is up…+ expect($hydrationSyncProfile.get()).toBe('shadow')++ // …and clears itself when the profile gate finally catches up.+ $activeGatewayProfile.set('shadow')+ expect($hydrationSyncProfile.get()).toBeNull()+ })++ it('still fails closed for an expected-empty chat when the profile gate stays unsatisfied', async () => {+ $activeGatewayProfile.set('default')+ vi.mocked(ensureGatewayProfile).mockImplementationOnce(async () => undefined)++ // No transcript to paint: a bound runtime on the WRONG profile is not+ // proof of a real surface, so the paint-first bypass must not fire.+ setMockAtom($selectedStoredSessionId, 'shared-remote-empty')+ setMockAtom($activeSessionId, 'runtime-empty')++ await expect(+ host.openSession('shared-remote-empty', {+ awaitHydration: true,+ expectHistory: false,+ hydrationTimeoutMs: 40,+ keepAllProfilesScope: false,+ profile: 'shadow'+ })+ ).rejects.toThrow(/timed out loading/i)++ expect($hydrationSyncProfile.get()).toBeNull()+ })++ it('never paint-first resolves a superseded wake (fail closed on conflicting concurrent hydration)', async () => {+ $activeGatewayProfile.set('default')+ vi.mocked(ensureGatewayProfile).mockImplementation(async () => undefined)++ const firstOutcome = host+ .openSession('conflict-a', {+ awaitHydration: true,+ expectHistory: true,+ hydrationTimeoutMs: 1_000,+ keepAllProfilesScope: false,+ profile: 'shadow'+ })+ .then(+ () => 'resolved',+ error => String(error)+ )++ await Promise.resolve()++ const second = host.openSession('conflict-b', {+ awaitHydration: true,+ expectHistory: true,+ hydrationTimeoutMs: 1_000,+ keepAllProfilesScope: false,+ profile: 'zephyr'+ })++ setMockAtom($selectedStoredSessionId, 'conflict-b')+ setMockAtom($activeSessionId, 'runtime-conflict-b')+ setMockAtom($messages, [{ id: 'history-conflict-b', parts: [], role: 'assistant' }] as never)++ await second+ expect(await firstOutcome).toMatch(/superseded/i)+ // Only the CURRENT wake's profile is syncing — the superseded one never+ // painted its badge over the winner.+ expect($hydrationSyncProfile.get()).toBe('zephyr')+ })+})diff --git a/apps/desktop/src/store/profile.ts b/apps/desktop/src/store/profile.tsindex 0ca214a9279..869c96b8da5 100644--- a/apps/desktop/src/store/profile.ts+++ b/apps/desktop/src/store/profile.ts@@ -369,6 +369,16 @@ $activeGatewayProfile.subscribe(value => {// so a lazy spawn doesn't read as a hang. Single-profile users never swap.export const $gatewaySwapTarget = atom<string | null>(null)+// Profile whose wake resolved PAINT-FIRST while the active-profile gate was+// still unsatisfied (#89843): on a shared-remote connection every profile is+// legitimately served through the primary socket, so $activeGatewayProfile+// never moves to the bot's profile and the old gate burned the whole 20s+// hydration budget with the transcript already painted. The stored history is+// shown immediately instead; this atom drives the subtle "Syncing…" affordance+// until the gate catches up (or the next wake supersedes it). Null when no+// paint-first wake is outstanding.+export const $hydrationSyncProfile = atom<string | null>(null)+// ── Hover-intent backend pre-warm ───────────────────────────────────────────// A cold switch to a profile whose pool backend isn't running pays the full// spawn (Python boot + port announce + readiness probe — measured ~2.5-3s)