Skip to content

The agent that grows with you

fix(desktop): keep composer stable across compression

Johnny0d447712a0bd
diff --git a/apps/desktop/src/app/chat/index.tsx b/apps/desktop/src/app/chat/index.tsx
index 16f622bee9b..12ac010eced 100644
--- a/apps/desktop/src/app/chat/index.tsx
+++ b/apps/desktop/src/app/chat/index.tsx
@@ -59,6 +59,7 @@ import type { ChatBarState } from './composer/types'
import { type DroppedFile, partitionDroppedFiles } from './hooks/use-composer-actions'
import { type DragKind, useFileDropZone } from './hooks/use-file-drop-zone'
import { ProfileTag } from './profile-tag'
+import { isRouteSessionMismatch } from './route-session-state'
import { useRuntimeMessageRepository } from './runtime-repository'
import { ScrollToBottomButton } from './scroll-to-bottom-button'
import { useSessionView } from './session-view'
@@ -400,7 +401,9 @@ export const ChatView = memo(function ChatView({
// direct nav). Derived in render so the swap reads instantly: the same frame
// the id changes we drop the old transcript and show the loader, instead of
// waiting for the resume effect (which paints a frame later) to clear them.
- const routeSessionMismatch = isRoutedSessionView && routedSessionId !== selectedSessionId
+ const routeSessionMismatch = isPrimary
+ ? isRouteSessionMismatch(routedSessionId, selectedSessionId, sessions)
+ : false
// The compact new-session pop-out skips the wordmark/tagline intro — it's a
// scratch window, not the full-height empty state.
diff --git a/apps/desktop/src/app/chat/route-session-state.test.ts b/apps/desktop/src/app/chat/route-session-state.test.ts
new file mode 100644
index 00000000000..0d897c8abdb
--- /dev/null
+++ b/apps/desktop/src/app/chat/route-session-state.test.ts
@@ -0,0 +1,24 @@
+import { describe, expect, it } from 'vitest'
+
+import { isRouteSessionMismatch } from './route-session-state'
+
+describe('isRouteSessionMismatch', () => {
+ it('keeps the composer mounted when auto-compression rotates root to tip', () => {
+ const sessions = [{ id: 'tip-2', _lineage_root_id: 'root-1' }]
+
+ expect(isRouteSessionMismatch('root-1', 'tip-2', sessions)).toBe(false)
+ expect(isRouteSessionMismatch('tip-2', 'root-1', sessions)).toBe(false)
+ })
+
+ it('still suppresses the previous chat while a genuinely different route loads', () => {
+ const sessions = [{ id: 'selected', _lineage_root_id: null }]
+
+ expect(isRouteSessionMismatch('next-session', 'selected', sessions)).toBe(true)
+ expect(isRouteSessionMismatch('next-session', null, sessions)).toBe(true)
+ })
+
+ it('does not require a session row when the selected and routed ids already agree', () => {
+ expect(isRouteSessionMismatch('same', 'same', [])).toBe(false)
+ expect(isRouteSessionMismatch(null, 'same', [])).toBe(false)
+ })
+})
diff --git a/apps/desktop/src/app/chat/route-session-state.ts b/apps/desktop/src/app/chat/route-session-state.ts
new file mode 100644
index 00000000000..1c35b157f99
--- /dev/null
+++ b/apps/desktop/src/app/chat/route-session-state.ts
@@ -0,0 +1,31 @@
+import { sessionMatchesStoredId } from '@/store/session'
+import type { SessionInfo } from '@/types/hermes'
+
+/**
+ * Whether the route points at a different conversation than the selected view.
+ *
+ * Auto-compression rotates a conversation from its root id to a continuation
+ * tip while the durable URL intentionally stays on the root. Those ids are
+ * different strings but still the same conversation, so a loaded lineage row
+ * must win over the raw comparison. An unknown route remains a mismatch: that
+ * is the real navigation case where the old transcript/composer must hide
+ * until resume finishes.
+ */
+export function isRouteSessionMismatch(
+ routedSessionId: null | string,
+ selectedSessionId: null | string,
+ sessions: readonly Pick<SessionInfo, '_lineage_root_id' | 'id'>[]
+): boolean {
+ if (!routedSessionId || routedSessionId === selectedSessionId) {
+ return false
+ }
+
+ if (!selectedSessionId) {
+ return true
+ }
+
+ return !sessions.some(
+ session =>
+ sessionMatchesStoredId(session, routedSessionId) && sessionMatchesStoredId(session, selectedSessionId)
+ )
+}