Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions apps/desktop/src/app/session/hooks/use-session-actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { clearQueuedPrompts } from '@/store/composer-queue'
import { clearNotifications, notify, notifyError } from '@/store/notifications'
import { $activeGatewayProfile, $newChatProfile, ensureGatewayProfile, normalizeProfileKey } from '@/store/profile'
import { resolveNewSessionCwd, tombstoneSessions, untombstoneSessions } from '@/store/projects'

import { cullRenderCacheSession, normalizeCachedTranscriptRows, readCachedTranscript } from '../../../render-cache-hydration'
import { cullStashedTranscript, readStashedTranscript, stashTranscript } from '../../../transcript-stash'
import {
$connection,
$currentCwd,
Expand Down Expand Up @@ -47,7 +44,9 @@ import { broadcastSessionsChanged } from '@/store/session-sync'
import { isWatchWindow } from '@/store/windows'
import type { SessionCreateResponse, SessionResumeResponse, UsageStats } from '@/types/hermes'

import { cullRenderCacheSession, normalizeCachedTranscriptRows, readCachedTranscript } from '../../../render-cache-hydration'
import { NEW_CHAT_ROUTE, sessionRoute, SETTINGS_ROUTE } from '../../../routes'
import { cullStashedTranscript, readStashedTranscript, stashTranscript } from '../../../transcript-stash'
import type { ClientSessionState, SidebarNavItem } from '../../../types'

import {
Expand Down Expand Up @@ -375,7 +374,9 @@ export function useSessionActions({
if (!cachedRows || !isCurrentResume() || $messages.get().length > 0) {
return
}

const painted = normalizeCachedTranscriptRows(cachedRows)

if (painted.length > 0) {
setMessages(painted)
}
Expand Down Expand Up @@ -514,12 +515,15 @@ export function useSessionActions({
if (!rows || !isCurrentResume()) {
return
}

// A live payload may already have landed while the cache read
// resolved; never clobber it with the cached copy.
if ($messages.get().length > 0) {
return
}

const painted = normalizeCachedTranscriptRows(rows)

if (painted.length > 0) {
setMessages(painted)
}
Expand Down Expand Up @@ -872,6 +876,7 @@ export function useSessionActions({
// Keep $sessionsTotal in sync so the sidebar's "Load N more" footer
// doesn't keep claiming the removed row is still on the server.
setSessionsTotal(prev => Math.max(0, prev - 1))

// Tear down before awaiting so the route effect can't resume the
// doomed session via the stale /<sid> URL.
if (wasSelected) {
Expand Down Expand Up @@ -900,6 +905,7 @@ export function useSessionActions({
}

untombstoneSessions([storedSessionId, removed?.id, removed?._lineage_root_id])

if (wasSelected) {
setFreshDraftReady(false)
setSelectedStoredSessionId(storedSessionId)
Expand Down Expand Up @@ -952,6 +958,7 @@ export function useSessionActions({
// on the next refresh, so they count as "removed" for the load-more
// footer math.
setSessionsTotal(prev => Math.max(0, prev - 1))

if (wasSelected) {
startFreshSessionDraft(true)
}
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/app/transcript-stash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
clearStashedTranscripts,
cullStashedTranscript,
readStashedTranscript,
stashTranscript,
stashedTranscriptCount
stashedTranscriptCount,
stashTranscript
} from './transcript-stash'

const rows = (id: string): ChatMessage[] => [
Expand Down
Loading