The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): clear the swap overlay a superseded wake set, not just the current one
chelsealong0a32314c20fe
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 9d345d61fc2..07947fb0213 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -363,6 +363,13 @@ export const BOT_CHAT_SESSION_HYDRATION_TIMEOUT_MS = 60_000* needs a bound of its own or it outlives the wake it describes. */export const HYDRATION_SYNC_BADGE_TIMEOUT_MS = 30_000let openSessionGeneration = 0+/** Which generation's wake most recently set $gatewaySwapTarget. Clearing it+ * keys off this, not off `generation === openSessionGeneration`, so a+ * superseded wake still clears the overlay IT put up — the generation+ * counter has already moved on by the time its `finally` runs, and a later+ * wake that never sets the target (e.g. a paint-first open without+ * awaitHydration) would otherwise leave it stuck forever (#115844). */+let gatewaySwapTargetOwnerGeneration: number | null = nullexport interface PluginOpenSessionOptions {awaitHydration?: boolean@@ -1049,6 +1056,7 @@ export const host = {// Keep the target-specific overlay visible through transcript hydration,// not merely through the gateway/profile activation that precedes it.$gatewaySwapTarget.set(targetProfile)+ gatewaySwapTargetOwnerGeneration = generation}// Only the HYDRATION half retries. Activation already failed its own@@ -1191,8 +1199,13 @@ export const host = {throw error} finally {- if (options.awaitHydration && generation === openSessionGeneration) {+ // Clear the overlay THIS wake set, even when a later open superseded+ // it: `generation === openSessionGeneration` is false by then, but+ // nothing else is coming to clear it. Skip only when a newer wake has+ // since taken ownership of the target.+ if (gatewaySwapTargetOwnerGeneration === generation) {$gatewaySwapTarget.set(null)+ gatewaySwapTargetOwnerGeneration = null}}},diff --git a/apps/desktop/src/sdk/profile-routing.test.ts b/apps/desktop/src/sdk/profile-routing.test.tsindex e85162d1573..2d6b1b53a6c 100644--- a/apps/desktop/src/sdk/profile-routing.test.ts+++ b/apps/desktop/src/sdk/profile-routing.test.ts@@ -1192,6 +1192,34 @@ describe('profile-aware plugin session opens', () => {expect($gatewaySwapTarget.get()).toBeNull()})+ it('clears a stale overlay when a superseded wake never gets its own clear (#115844)', async () => {+ $activeGatewayProfile.set('jimin')++ const firstOutcome = host+ .openSession('chat-a', {+ profile: 'jimin',+ awaitHydration: true,+ expectHistory: true,+ hydrationTimeoutMs: 30+ })+ .then(+ () => 'resolved',+ error => String(error)+ )++ await Promise.resolve()+ expect($gatewaySwapTarget.get()).toBe('jimin')++ // A later open that never awaits hydration (a paint-first wake) bumps the+ // generation counter but never touches $gatewaySwapTarget - it has+ // nothing of its own to clear, so the first wake's own cleanup is the+ // only thing standing between here and a permanently stuck overlay.+ await host.openSession('chat-b', { profile: 'hyoseob' })++ expect(await firstOutcome).toMatch(/timed out loading/i)+ expect($gatewaySwapTarget.get()).toBeNull()+ })+it('keeps chrome API home on the previous profile when opening a Bot Chat', async () => {$activeGatewayProfile.set('default')