fix: ignore subagents when sorting sidebar projects

Co-authored-by: codex <[email protected]>
This commit is contained in:
Yusuf007Randcodex authored and Julius Marminge committed 2026-08-15 16:50:12 +02:00
1 parent 08b97fe6df
commit 28e55c211d
3 files changed
+72 -3

No files matched your search

@@ -33,6 +33,9 @@ import {
planPinnedReorder,
sortPinnedThreadsForSidebar,
sortThreadsForSidebar,
sortSidebarV2ProjectGroups,
sortSettledThreadsForSidebarV2,
sortThreadsForSidebarV2,
sortProjectsForSidebar,
sortScopedProjectsForSidebar,
shouldCreateNewThreadInCurrentProject,
@@ -1715,3 +1718,51 @@ describe("sortLogicalProjectsForSidebar", () => {
).toEqual(["logical-newer", "logical-older"]);
});
});
describe("sortSidebarV2ProjectGroups", () => {
it("does not let a hidden subagent thread reorder projects", () => {
const olderProjectId = ProjectId.make("project-older");
const newerProjectId = ProjectId.make("project-newer");
const olderRootThreadId = ThreadId.make("thread-older-root");
const projects = [
{
...makeProject({ id: olderProjectId, title: "A older project" }),
projectKey: "logical-older",
memberProjectRefs: [{ environmentId: localEnvironmentId, projectId: olderProjectId }],
},
{
...makeProject({ id: newerProjectId, title: "Z newer project" }),
projectKey: "logical-newer",
memberProjectRefs: [{ environmentId: localEnvironmentId, projectId: newerProjectId }],
},
];
const threads = [
makeThread({
id: olderRootThreadId,
projectId: olderProjectId,
updatedAt: "2026-03-09T10:01:00.000Z",
}),
makeThread({
id: ThreadId.make("thread-newer-root"),
projectId: newerProjectId,
updatedAt: "2026-03-09T10:05:00.000Z",
}),
makeThread({
id: ThreadId.make("thread-hidden-subagent"),
projectId: olderProjectId,
updatedAt: "2026-03-09T10:10:00.000Z",
lineage: {
rootThreadId: olderRootThreadId,
parentThreadId: olderRootThreadId,
relationshipToParent: "subagent",
},
}),
];
expect(
sortSidebarV2ProjectGroups(projects, threads, "updated_at").map(
(project) => project.projectKey,
),
).toEqual(["logical-newer", "logical-older"]);
});
});
+19 -1
View File
@@ -55,7 +55,10 @@ export function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "line
}
export function filterSidebarV2VisibleThreads<
T extends Pick<SidebarThreadSummary, "archivedAt" | "environmentId" | "lineage" | "projectId">,
T extends Pick<SidebarThreadSummary, "archivedAt" | "lineage"> & {
environmentId: string;
projectId: string;
},
>(threads: readonly T[], scopedProjectKeys: ReadonlySet<string> | null): T[] {
return threads.filter(
(thread) =>
@@ -885,6 +888,21 @@ export function sortLogicalProjectsForSidebar<
);
}
export function sortSidebarV2ProjectGroups<
TProject extends LogicalSidebarProject,
TThread extends ScopedSidebarThread & Pick<SidebarThreadSummary, "lineage">,
>(
projects: readonly TProject[],
threads: readonly TThread[],
sortOrder: SidebarProjectSortOrder,
): TProject[] {
return sortLogicalProjectsForSidebar(
projects,
filterSidebarV2VisibleThreads(threads, null),
sortOrder,
);
}
/**
* Sorts the cross-environment project collection used by landing surfaces.
* Project ids are only unique within an environment, and archived threads
+2 -2
View File
@@ -123,7 +123,7 @@ import {
searchSidebarThreadsByTitle,
resolveWorkingStartedAt,
shouldNavigateAfterProjectRemoval,
sortLogicalProjectsForSidebar,
sortSidebarV2ProjectGroups,
sortSettledThreadsForSidebarV2,
sortThreadsForSidebarV2,
} from "./Sidebar.logic";
@@ -1448,7 +1448,7 @@ export default function SidebarV2() {
],
);
const projectGroups = useMemo(
() => sortLogicalProjectsForSidebar(unsortedProjectGroups, threads, sidebarProjectSortOrder),
() => sortSidebarV2ProjectGroups(unsortedProjectGroups, threads, sidebarProjectSortOrder),
[sidebarProjectSortOrder, threads, unsortedProjectGroups],
);
const serverProviders = useAtomValue(primaryServerProvidersAtom);