Skip to content

The agent that grows with you

fix: keep same-session route during context switch

teknium13c0dcbbdc775
diff --git a/apps/desktop/src/app/chat/route-session-state.test.ts b/apps/desktop/src/app/chat/route-session-state.test.ts
index 5d628f38fc0..af324ecc3f1 100644
--- a/apps/desktop/src/app/chat/route-session-state.test.ts
+++ b/apps/desktop/src/app/chat/route-session-state.test.ts
@@ -24,6 +24,20 @@ describe('isRouteSessionMismatch', () => {
expect(isRouteSessionMismatch(null, 'same', [])).toBe(false)
})
+ it('keeps the same-session route visible while a context switch is in flight', () => {
+ const sessions = [{ id: 'a', _lineage_root_id: null }]
+
+ expect(
+ isRouteSessionMismatch('a', 'a', sessions, {
+ activeRuntimeId: 'r',
+ contextSwitching: true,
+ messagesEmpty: false,
+ transcriptStoredSessionId: 'a'
+ }),
+ 'a profile swap while route == selected must not blank the chat to the splash'
+ ).toBe(false)
+ })
+
it('keeps only the routed chat whose active view owns an existing transcript during selection churn', () => {
const routedSessionId = routeSessionId(sessionRoute('session-a'))
diff --git a/apps/desktop/src/app/chat/route-session-state.ts b/apps/desktop/src/app/chat/route-session-state.ts
index d761fcc6d1e..778ab78d7f1 100644
--- a/apps/desktop/src/app/chat/route-session-state.ts
+++ b/apps/desktop/src/app/chat/route-session-state.ts
@@ -28,10 +28,6 @@ export function isRouteSessionMismatch(
return false
}
- if (activeTranscript?.contextSwitching) {
- return true
- }
-
const matchesRoute = (storedSessionId: null | string) =>
storedSessionId === routedSessionId ||
Boolean(
@@ -42,10 +38,18 @@ export function isRouteSessionMismatch(
)
)
+ // The selected view already owns the routed conversation: a profile or
+ // connection switch must not blank it to the splash.
if (matchesRoute(selectedSessionId)) {
return false
}
+ // Only the transcript-retention fallback below must be denied while a
+ // context switch is in flight; the prior context must not be retained.
+ if (activeTranscript?.contextSwitching) {
+ return true
+ }
+
return !(
activeTranscript?.activeRuntimeId &&
!activeTranscript.messagesEmpty &&