From cf50f929b46a7bb407034f9fc852d9c460c113a6 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Mon, 23 Feb 2026 14:10:10 +0000 Subject: [PATCH 1/3] Focus newly created sessions like resumed sessions Detect session switches even when no previous active session exists so new sessions are selected and focused immediately. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- PolyPilot/Components/Pages/Dashboard.razor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PolyPilot/Components/Pages/Dashboard.razor b/PolyPilot/Components/Pages/Dashboard.razor index 64e487c05e..9203b41cf6 100644 --- a/PolyPilot/Components/Pages/Dashboard.razor +++ b/PolyPilot/Components/Pages/Dashboard.razor @@ -879,7 +879,7 @@ try { var active = CopilotService.ActiveSessionName; - bool sessionSwitched = active != null && active != _lastActiveSession && _lastActiveSession != null; + bool sessionSwitched = active != _lastActiveSession; // Throttle non-switch state changes to max 2/sec, but always allow completed sessions through if (!_refreshThrottle.ShouldRefresh(sessionSwitched, completedSessions.Count > 0)) @@ -913,7 +913,7 @@ expandedSession = sessions[0].Name; CopilotService.SwitchSession(sessions[0].Name); } - if (sessionSwitched && sessions.Any(s => s.Name == active)) + if (sessionSwitched && active != null && sessions.Any(s => s.Name == active)) { _lastActiveSession = active; expandedSession = active; From 25cb0dcbdf490e8d605d91e3a6c1c4e38288b2d1 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Mon, 23 Feb 2026 10:12:32 -0600 Subject: [PATCH 2/3] Fix perpetual throttle bypass when active session is closed When the active session is closed (active becomes null) while _lastActiveSession still holds the previous session name, the new sessionSwitched condition (active != _lastActiveSession) evaluates to true but the focus block is correctly guarded by 'active != null' and never executes. This left _lastActiveSession stale, causing every subsequent RefreshState call to see sessionSwitched=true and permanently bypass the 2/sec render throttle. Add an else-if branch to sync _lastActiveSession to null in this case, so the throttle is restored on the next refresh cycle. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- PolyPilot/Components/Pages/Dashboard.razor | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PolyPilot/Components/Pages/Dashboard.razor b/PolyPilot/Components/Pages/Dashboard.razor index 9203b41cf6..88a1181b45 100644 --- a/PolyPilot/Components/Pages/Dashboard.razor +++ b/PolyPilot/Components/Pages/Dashboard.razor @@ -928,6 +928,12 @@ expandedSession = active; _needsScrollToBottom = true; } + else if (sessionSwitched && active == null) + { + // Active session was closed — sync _lastActiveSession so the throttle + // bypass doesn't persist across subsequent refreshes. + _lastActiveSession = null; + } if (_lastActiveSession == null && active != null) { From f21551846e673b216f90d81163b2fb472ed386a4 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Tue, 24 Feb 2026 14:41:35 -0600 Subject: [PATCH 3/3] fix: guard cooldown on session close, clear stale state - Guard 300ms render cooldown + scroll flag with active != null so closing the last session doesn't delay the empty-state render - Clear expandedSession and _focusedInputId in the session-close branch so stale UI state from the defunct session doesn't linger Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- PolyPilot/Components/Pages/Dashboard.razor | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PolyPilot/Components/Pages/Dashboard.razor b/PolyPilot/Components/Pages/Dashboard.razor index 88a1181b45..68458f9dd9 100644 --- a/PolyPilot/Components/Pages/Dashboard.razor +++ b/PolyPilot/Components/Pages/Dashboard.razor @@ -930,9 +930,11 @@ } else if (sessionSwitched && active == null) { - // Active session was closed — sync _lastActiveSession so the throttle - // bypass doesn't persist across subsequent refreshes. + // Active session was closed — clear all session-specific UI state so stale + // values don't linger until the next session is created. _lastActiveSession = null; + expandedSession = null; + _focusedInputId = null; } if (_lastActiveSession == null && active != null) @@ -944,7 +946,7 @@ if (!s.IsProcessing && streamingBySession.ContainsKey(s.Name)) streamingBySession.Remove(s.Name); } - if (sessionSwitched) + if (sessionSwitched && active != null) { // _sessionSwitching stays true until SafeRefreshAsync reads it — // this skips the expensive JS draft capture round-trip during switches