The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): skip tail atom writes when the entry is unchanged
Yagna Vudathu9568f614c9ee
diff --git a/apps/desktop/src/store/transcript-tail.test.ts b/apps/desktop/src/store/transcript-tail.test.tsnew file mode 100644index 00000000000..cd33cbb72d6--- /dev/null+++ b/apps/desktop/src/store/transcript-tail.test.ts@@ -0,0 +1,44 @@+import { beforeEach, describe, expect, it } from 'vitest'++import { $transcriptTailBySessionId, recordTranscriptTail } from './transcript-tail'++const page = (count: number, limit = 10) => ({+ messages: Array.from({ length: count }, (_, i) => ({ id: `m${i}` })),+ pagination: { limit, offset: 0 }+}) as never++describe('recordTranscriptTail no-op suppression', () => {+ beforeEach(() => {+ $transcriptTailBySessionId.set({})+ })++ it('does not notify on an identical re-record (#113842)', () => {+ recordTranscriptTail('s1', page(5))++ let notifications = 0+ const unsub = $transcriptTailBySessionId.subscribe(() => {+ notifications += 1+ })+ notifications = 0++ recordTranscriptTail('s1', page(5))+ unsub()++ expect(notifications).toBe(0)+ })++ it('notifies when the tail actually advances', () => {+ recordTranscriptTail('s1', page(5))++ let notifications = 0+ const unsub = $transcriptTailBySessionId.subscribe(() => {+ notifications += 1+ })+ notifications = 0++ recordTranscriptTail('s1', page(7))+ unsub()++ expect(notifications).toBe(1)+ })+})diff --git a/apps/desktop/src/store/transcript-tail.ts b/apps/desktop/src/store/transcript-tail.tsindex 72857061b6b..84ef8adf5e4 100644--- a/apps/desktop/src/store/transcript-tail.ts+++ b/apps/desktop/src/store/transcript-tail.ts@@ -100,8 +100,21 @@ function tailStateFromPage(page: TailPage, profile?: TranscriptProfileScope): Tr}}+function sameTailState(a: TranscriptTailState, b: TranscriptTailState): boolean {+ return (+ a.nextOffset === b.nextOffset &&+ a.possiblyTruncated === b.possiblyTruncated &&+ JSON.stringify(a.profile ?? null) === JSON.stringify(b.profile ?? null)+ )+}+function setTranscriptTailEntry(key: string, state: TranscriptTailState): void {const current = $transcriptTailBySessionId.get()+ // Heartbeats re-record identical entries; a needless .set() re-renders the+ // whole chat tree through the tail atom (#113842).+ if (key in current && sameTailState(current[key], state)) {+ return+ }const existing = new Set(Object.keys(current))transcriptTailOrder = transcriptTailOrder.filter(candidate => candidate !== key && existing.has(candidate))transcriptTailOrder.push(key)