The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: delete-path drops every scope of a removed id; legacy purge latches on success only
Teknium3b672a689737
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.tsindex 57257b32740..0e96be4ed0b 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts@@ -110,7 +110,7 @@ import {import { broadcastSessionsChanged } from '@/store/session-sync'import { forgetSessionUnread } from '@/store/session-unread'import { $archivedSessions } from '@/store/sidebar-archive'-import { dropTranscriptTail, loadTranscriptTail, saveTranscriptTail } from '@/store/transcript-tail-cache'+import { dropTranscriptTail, dropTranscriptTailEverywhere, loadTranscriptTail, saveTranscriptTail } from '@/store/transcript-tail-cache'import { isWatchWindow } from '@/store/windows'import type { SessionCreateResponse, SessionMessage, SessionResumeResponse, UsageStats } from '@/types/hermes'@@ -2125,8 +2125,8 @@ export function useSessionActions({}await deleteSession(storedSessionId, removedOwner)- // A deleted session's cached tail must not resurrect on a recycled id.- dropTranscriptTail(storedSessionId, removedOwner)++ dropTranscriptTailEverywhere(storedSessionId)// Only after the RPC lands — the optimistic eviction above can roll// back, and a rolled-back row must keep its watermark/marker.forgetSessionUnread(removedIds, profile)diff --git a/apps/desktop/src/store/transcript-tail-cache.test.ts b/apps/desktop/src/store/transcript-tail-cache.test.tsindex df64a0d3b9a..146a9f9e071 100644--- a/apps/desktop/src/store/transcript-tail-cache.test.ts+++ b/apps/desktop/src/store/transcript-tail-cache.test.ts@@ -5,6 +5,7 @@ import type { ChatMessage } from '@/lib/chat-messages'import {clearTranscriptTails,dropTranscriptTail,+ dropTranscriptTailEverywhere,loadTranscriptTail,saveTranscriptTail} from './transcript-tail-cache'@@ -168,6 +169,21 @@ describe('transcript tail cache', () => {expect(loadTranscriptTail('sess-d', { profile: 'p2' })).not.toBeNull()})+ it('delete-path everywhere-drop clears every scope of the id even when scopes drifted', () => {+ // Save under a routed scope (connectionId present); the delete path+ // derives its scope from the removed row, which may lack the tag —+ // the everywhere-drop must still clear the entry (#94914 defect 1).+ saveTranscriptTail('sess-gone', [msg('routed-row')], { connectionId: 'homelab', profile: 'ops' })+ saveTranscriptTail('sess-gone', [msg('local-row')], { profile: 'ops' })+ saveTranscriptTail('sess-kept', [msg('other-row')], { profile: 'ops' })++ dropTranscriptTailEverywhere('sess-gone')++ expect(loadTranscriptTail('sess-gone', { connectionId: 'homelab', profile: 'ops' })).toBeNull()+ expect(loadTranscriptTail('sess-gone', { profile: 'ops' })).toBeNull()+ expect(loadTranscriptTail('sess-kept', { profile: 'ops' })).not.toBeNull()+ })+it('purges pre-scoping v1 entries so a stale tail can never paint again', async () => {const stale = {messages: [{ id: 'old', parts: [{ text: 'x', type: 'text' }], role: 'assistant' }],diff --git a/apps/desktop/src/store/transcript-tail-cache.ts b/apps/desktop/src/store/transcript-tail-cache.tsindex 40efce656d5..04f13898a55 100644--- a/apps/desktop/src/store/transcript-tail-cache.ts+++ b/apps/desktop/src/store/transcript-tail-cache.ts@@ -61,8 +61,6 @@ function purgeLegacyV1(store: Storage): void {return}- legacyPurged = true-try {const doomed: string[] = []@@ -77,6 +75,11 @@ function purgeLegacyV1(store: Storage): void {for (const key of doomed) {store.removeItem(key)}++ // Only latch on a completed sweep: a mid-sweep throw retries on the next+ // storage() touch instead of leaving a partial purge latched for the+ // window's lifetime.+ legacyPurged = true} catch {// best effort}@@ -284,6 +287,55 @@ export function dropTranscriptTail(storedSessionId: string, scope?: TranscriptTa}}+/** Drop EVERY scope's entry for a stored id. Delete-path only: the save-path+ * scope (ownerRoute) and the delete-path scope (the removed row's+ * connection_id) are derived from different sources, so a shape drift+ * between them would orphan the entry until LRU eviction (#94914 review,+ * defect 1). A DELETED stored id cannot be legitimately reused, so sweeping+ * all scopes is safe there — but never on the failed-resume path, where a+ * same-id twin in another profile must keep its own tail. */+export function dropTranscriptTailEverywhere(storedSessionId: string): void {+ const id = (storedSessionId ?? '').trim()+ const store = storage()++ if (!store || !id) {+ return+ }++ try {+ const namesId = (entry: string): boolean => {+ if (entry === id) {+ return true+ }++ if (!entry.startsWith('[')) {+ return false+ }++ try {+ const parsed = JSON.parse(entry)++ return Array.isArray(parsed) && parsed[2] === id+ } catch {+ return false+ }+ }++ const index = readIndex(store)++ for (const entry of index.filter(namesId)) {+ store.removeItem(PREFIX + entry)+ }++ writeIndex(+ store,+ index.filter(entry => !namesId(entry))+ )+ } catch {+ // best effort+ }+}+/** Wipe the whole cache (connection/mode re-home, quota recovery). */export function clearTranscriptTails(): void {const store = storage()