The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a cross-profile or stale project filter no longer empties the sidebar (#96246)
liuhao1024fd5428267865
diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsxindex 6fcd656da3b..2230ca1453e 100644--- a/apps/desktop/src/app/chat/sidebar/index.tsx+++ b/apps/desktop/src/app/chat/sidebar/index.tsx@@ -155,6 +155,7 @@ import { orderByIds, reconcileOrderIds, resolveManualSessionOrderIds, sameIds }import { filterSessionsByProfileScope } from './profile-scope'import { ProfileRail } from './profile-switcher'import { ProjectDialog } from './project-dialog'+import { resolveLiveProjectFilter } from './project-filter'import {excludeProjectSessions,liveSessionProjectId,@@ -371,7 +372,7 @@ export function ChatSidebar({const grouping = useStore($sidebarGrouping)const ordering = useStore($sidebarOrdering)const statusFilter = useStore($sidebarStatusFilter)- const projectFilter = useStore($sidebarProjectFilter)+ const persistedProjectFilter = useStore($sidebarProjectFilter)const profileFilter = useStore($sidebarProfileFilter)const prFilter = useStore($sidebarPrFilter)const prDataWanted = useStore($sidebarPrDataWanted)@@ -436,6 +437,16 @@ export function ChatSidebar({const projectOrderIds = useStore($sidebarProjectOrderIds)const projects = useStore($projects)const projectTree = useStore($projectTree)++ // The persisted project filter's storage is shared across profiles, so ids+ // picked in another profile don't resolve in the active one and the raw+ // membership whitelist empties every tier of the sidebar (#96246). Narrow+ // to ids the ACTIVE tree resolves; dead ids are inert, not fatal.+ const projectFilter = useMemo(+ () => resolveLiveProjectFilter(persistedProjectFilter, projectTree),+ [persistedProjectFilter, projectTree]+ )+const projectTreeLoading = useStore($projectTreeLoading)const removedSessionIds = useStore($removedSessionIds)const reposScanning = useStore($reposScanning)diff --git a/apps/desktop/src/app/chat/sidebar/project-filter.test.ts b/apps/desktop/src/app/chat/sidebar/project-filter.test.tsnew file mode 100644index 00000000000..a22d0390e33--- /dev/null+++ b/apps/desktop/src/app/chat/sidebar/project-filter.test.ts@@ -0,0 +1,36 @@+import { describe, expect, it } from 'vitest'++import { resolveLiveProjectFilter } from './project-filter'++describe('resolveLiveProjectFilter', () => {+ const treeA = [{ id: 'p_aaa' }, { id: '/Users/me/repos/alpha' }] as const+ const treeB = [{ id: 'p_bbb' }, { id: '/Users/me/repos/beta' }] as const++ it('returns the filter unchanged when it is empty', () => {+ expect(resolveLiveProjectFilter([], treeA)).toEqual([])+ })++ it('keeps ids the active tree resolves', () => {+ expect(resolveLiveProjectFilter(['p_aaa', '/Users/me/repos/alpha'], treeA)).toEqual([+ 'p_aaa',+ '/Users/me/repos/alpha'+ ])+ })++ it('drops ids that only resolve in another profile (#96246)', () => {+ // Persisted in profile B, active profile is A: nothing resolves, the+ // filter must become inert instead of filtering everything out.+ expect(resolveLiveProjectFilter(['p_bbb', '/Users/me/repos/beta'], treeA)).toEqual([])+ })++ it('keeps the live half of a mixed filter', () => {+ expect(resolveLiveProjectFilter(['p_bbb', 'p_aaa'], treeA)).toEqual(['p_aaa'])+ })++ it('fails open while the tree is loading', () => {+ // Empty/pending tree → no narrowing yet; re-hydrates when the tree lands.+ expect(resolveLiveProjectFilter(['p_aaa'], [])).toEqual([])+ expect(resolveLiveProjectFilter(['p_aaa'], null)).toEqual([])+ expect(resolveLiveProjectFilter(['p_aaa'], undefined)).toEqual([])+ })+})diff --git a/apps/desktop/src/app/chat/sidebar/project-filter.ts b/apps/desktop/src/app/chat/sidebar/project-filter.tsnew file mode 100644index 00000000000..7a4d6433e43--- /dev/null+++ b/apps/desktop/src/app/chat/sidebar/project-filter.ts@@ -0,0 +1,33 @@+/**+ * Project-filter resolution against the ACTIVE profile's project tree.+ *+ * The sidebar's project filter is a `persistentAtom` whose storage key is+ * shared across profiles. Ids picked in profile B (explicit `p_<hex>` ids or+ * repo-root paths) do not resolve against profile A's per-profile+ * `projects.db`, and both application sites treat the raw filter as a+ * membership whitelist — so one cross-profile switch empties every tier of+ * the sidebar, reading as data loss until the filter is manually cleared+ * (#96246).+ *+ * `resolveLiveProjectFilter` narrows the persisted filter to ids the given+ * tree actually resolves. Ids that resolve nowhere become inert (the filter+ * stops narrowing) instead of fatal (everything filters out). While the tree+ * is still loading (empty), an explicit non-empty filter resolves to an+ * empty live set — fail-open, matching the tree-refresh re-hydration timing.+ */+export function resolveLiveProjectFilter(+ projectFilter: readonly string[],+ tree: readonly { id: string }[] | null | undefined+): readonly string[] {+ if (!projectFilter.length) {+ return projectFilter+ }++ if (!tree || !tree.length) {+ return []+ }++ const liveIds = new Set(tree.map(project => project.id))++ return projectFilter.filter(id => liveIds.has(id))+}