Skip to content

The agent that grows with you

fix(desktop): a parked session pane releases its transcript from the warm cache (#77311)

teknium1af2a3be5fe0a
diff --git a/apps/desktop/src/app/session/hooks/use-session-state-cache.ts b/apps/desktop/src/app/session/hooks/use-session-state-cache.ts
index 6a3f0dd97d7..eb5a4ce5893 100644
--- a/apps/desktop/src/app/session/hooks/use-session-state-cache.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-state-cache.ts
@@ -22,6 +22,7 @@ import {
setYoloActive
} from '@/store/session'
import {
+ $parkedTileStoredIds,
$sessionStates,
$sessionTiles,
isSessionInForeground,
@@ -107,8 +108,9 @@ export function useSessionStateCache({
.get()
.some(
tile =>
- tile.runtimeId === runtimeId ||
- (state.storedSessionId !== null && tile.storedSessionId === state.storedSessionId)
+ !$parkedTileStoredIds.get().has(tile.storedSessionId) &&
+ (tile.runtimeId === runtimeId ||
+ (state.storedSessionId !== null && tile.storedSessionId === state.storedSessionId))
),
// A connection death mid-turn leaves snapshots whose frozen busy flags
// will never settle (the respawned backend re-mints runtime ids), which
diff --git a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
index b72afec1684..16bfb56627f 100644
--- a/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
+++ b/apps/desktop/src/components/pane-shell/tree/renderer/tree-group.tsx
@@ -31,7 +31,7 @@ import { useContributions } from '@/contrib/react/use-contributions'
import { useI18n } from '@/i18n'
import { useKeybindHint } from '@/lib/keybinds/use-keybind-hint'
import { cn } from '@/lib/utils'
-import { closeAllOpenSessionTiles } from '@/store/session-states'
+import { closeAllOpenSessionTiles, setZoneParkedTiles } from '@/store/session-states'
import { $layoutEditMode } from '../../edit-mode'
import { useWindowControlsOverlap } from '../../geometry'
@@ -343,6 +343,21 @@ export function TreeGroup({
const paneLifecycle = lifecycleRef.current.entries
const keptPanes = shown.filter(id => paneLifecycle[id] && paneLifecycle[id].lifecycle !== 'parked')
+ // A parked session pane releases its transcript from the warm cache
+ // (#77311): publish which tiles are parked so use-session-state-cache stops
+ // treating them as referenced. Cleared on unmount so a zone that goes away
+ // never leaves a tile marked parked.
+ const parkedSessionKey = shown
+ .filter(id => id.startsWith('session-tile:') && paneLifecycle[id]?.lifecycle === 'parked')
+ .map(id => id.slice('session-tile:'.length))
+ .join('\n')
+
+ useEffect(() => {
+ setZoneParkedTiles(node.id, parkedSessionKey ? parkedSessionKey.split('\n') : [])
+
+ return () => setZoneParkedTiles(node.id, [])
+ }, [node.id, parkedSessionKey])
+
// HIDE ≠ CLOSE for stateful guests: a minimized zone keeps only its
// keep-alive panes mounted (the embedded Browser's <webview> would otherwise
// be destroyed and rebuilt on restore — fresh document, lost automation
diff --git a/apps/desktop/src/store/session-states-parked.test.ts b/apps/desktop/src/store/session-states-parked.test.ts
new file mode 100644
index 00000000000..749b3dab391
--- /dev/null
+++ b/apps/desktop/src/store/session-states-parked.test.ts
@@ -0,0 +1,24 @@
+// #77311: a PARKED session tile (pane-lifecycle unmounts it) must not pin its
+// transcript — the warm cache treats it as unreferenced and evicts it, and the
+// tile's resume path re-hydrates on unpark. In-flight (busy) states are never
+// evicted by the cache regardless.
+import { describe, expect, it } from 'vitest'
+
+import { $parkedTileStoredIds, setZoneParkedTiles } from './session-states'
+
+describe('parked session tiles', () => {
+ it('unions parked tiles across zones and clears a zone on unmount', () => {
+ setZoneParkedTiles('zone-a', ['s1', 's2'])
+ setZoneParkedTiles('zone-b', ['s3'])
+ expect([...$parkedTileStoredIds.get()].sort()).toEqual(['s1', 's2', 's3'])
+
+ const before = $parkedTileStoredIds.get()
+ setZoneParkedTiles('zone-b', ['s3'])
+ expect($parkedTileStoredIds.get()).toBe(before) // no churn on an identical report
+
+ setZoneParkedTiles('zone-a', [])
+ expect([...$parkedTileStoredIds.get()]).toEqual(['s3'])
+ setZoneParkedTiles('zone-b', [])
+ expect($parkedTileStoredIds.get().size).toBe(0)
+ })
+})
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index 788a84caf14..04211e9bad0 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -1055,6 +1055,34 @@ const profileKey = () => normalizeProfileKey($activeGatewayProfile.get())
// atom hydrates from the stored (runtime-less) tiles for the active profile.
// A secondary window (single-chat pop-out) shows ONLY its routed session — no
// tiles, and no repopulation on a profile switch.
+/** Stored ids of session tiles whose pane is PARKED (unmounted by the zone's
+ * bounded keep-alive, pane-lifecycle.ts). A parked tile still exists, so it
+ * used to count as "referenced" and its full transcript stayed pinned in the
+ * warm cache forever — the retained-`$messages` leak of #77311. Parked tiles
+ * are unreferenced for eviction; the tile's resume path re-hydrates from the
+ * backend on unpark exactly as a cold mount does. */
+export const $parkedTileStoredIds = atom<ReadonlySet<string>>(new Set())
+
+const parkedTilesByZone = new Map<string, readonly string[]>()
+
+/** Each pane zone reports its own parked session tiles; the atom is the union. */
+export function setZoneParkedTiles(zoneKey: string, storedSessionIds: readonly string[]): void {
+ if (storedSessionIds.length === 0) {
+ parkedTilesByZone.delete(zoneKey)
+ } else {
+ parkedTilesByZone.set(zoneKey, storedSessionIds)
+ }
+
+ const next = new Set([...parkedTilesByZone.values()].flat())
+ const prev = $parkedTileStoredIds.get()
+
+ if (next.size === prev.size && [...next].every(id => prev.has(id))) {
+ return
+ }
+
+ $parkedTileStoredIds.set(next)
+}
+
export const $sessionTiles = atom<SessionTile[]>(
isSecondaryWindow() || isBrowserWindow()
? []