The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): dedupe persisted sidebar order ids to stop duplicate repo headers
Jreevob6d2f15b6cac
diff --git a/apps/desktop/src/app/chat/sidebar/order.test.ts b/apps/desktop/src/app/chat/sidebar/order.test.tsindex 37a4b36df96..0c84107b4db 100644--- a/apps/desktop/src/app/chat/sidebar/order.test.ts+++ b/apps/desktop/src/app/chat/sidebar/order.test.ts@@ -51,6 +51,11 @@ describe('orderByIds', () => {expect(orderByIds(items, id, ['b', 'a'])).toEqual([{ id: 'fresh' }, { id: 'b' }, { id: 'a' }])})+ it('never duplicates an item when the persisted order repeats its id', () => {+ const items = [{ id: 'a' }, { id: 'b' }]+ expect(orderByIds(items, id, ['a', 'a', 'b'])).toEqual([{ id: 'a' }, { id: 'b' }])+ })+it('keeps a newly-loaded older page below the hand-picked order', () => {// Callers pass recency-sorted lists, so an unknown id BELOW the ordered// ones is an older page that just loaded — hoisting it to the top was@@ -94,6 +99,10 @@ describe('reconcileOrderIds', () => {it('puts newly-seen ids ahead of the retained saved order', () => {expect(reconcileOrderIds(['fresh', 'a', 'b'], ['b', 'a', 'gone'])).toEqual(['fresh', 'b', 'a'])})++ it('dedupes a corrupted saved order instead of perpetuating it', () => {+ expect(reconcileOrderIds(['a', 'b'], ['a', 'a', 'b'])).toEqual(['a', 'b'])+ })})describe('sameIds', () => {diff --git a/apps/desktop/src/app/chat/sidebar/order.ts b/apps/desktop/src/app/chat/sidebar/order.tsindex c65a53dc030..625cb083f31 100644--- a/apps/desktop/src/app/chat/sidebar/order.ts+++ b/apps/desktop/src/app/chat/sidebar/order.ts@@ -35,9 +35,13 @@ function mergeFreshByPosition(currentIds: string[], keptIds: string[]): string[]export function reconcileFreshFirst(currentIds: string[], orderIds: string[]): string[] {const current = new Set(currentIds)+ // Dedupe both inputs: a corrupted persisted order (same id twice) must not+ // self-perpetuate through reconcile, and duplicate live ids (e.g. the same+ // repo surfacing under several projects) must not be written back into the+ // saved order — either one paints as duplicate headers (#73314).return mergeFreshByPosition(- currentIds,- orderIds.filter(id => current.has(id))+ [...new Set(currentIds)],+ [...new Set(orderIds.filter(id => current.has(id)))])}@@ -74,7 +78,10 @@ export function orderByIds<T>(items: T[], getId: (item: T) => string, orderIds:for (const id of orderIds) {const item = byId.get(id)- if (item) {+ // Guard against duplicates in the persisted order: pushing the same item+ // twice renders the row/header twice (e.g. two identical repo headers+ // under one project).+ if (item && !seen.has(id)) {ordered.push(item)seen.add(id)}@@ -89,10 +96,17 @@ export function orderByIds<T>(items: T[], getId: (item: T) => string, orderIds:const older: T[] = []items.forEach((item, index) => {- if (seen.has(getId(item))) {+ const itemId = getId(item)++ // `seen` doubles as the duplicate guard for live items: two rows carrying+ // the same id (e.g. one repo surfacing under several projects) must render+ // once, not once per occurrence (#73314).+ if (seen.has(itemId)) {return}+ seen.add(itemId)+if (firstOrdered >= 0 && index < firstOrdered) {newer.push(item)} else {@@ -119,7 +133,9 @@ export function reconcileOrderIds(currentIds: string[], orderIds: string[]): str}if (!orderIds.length) {- return currentIds+ // Still dedupe: persisting duplicate live ids here is what seeded the+ // #73314 feedback loop in the first place.+ return [...new Set(currentIds)]}return reconcileFreshFirst(currentIds, orderIds)