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-07-27 18:52:45 +02:00
1 parent 97a04be613
commit 13543cd065
3 files changed
+70 -3

No files matched your search

@@ -26,6 +26,7 @@ import {
shouldNavigateAfterProjectRemoval,
shouldClearThreadSelectionOnMouseDown,
sortLogicalProjectsForSidebar,
sortSidebarV2ProjectGroups,
sortSettledThreadsForSidebarV2,
sortThreadsForSidebarV2,
sortScopedProjectsForSidebar,
@@ -1502,3 +1503,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
@@ -97,7 +97,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) =>
@@ -827,6 +830,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
@@ -112,7 +112,7 @@ import {
resolveSidebarV2Status,
resolveWorkingStartedAt,
shouldNavigateAfterProjectRemoval,
sortLogicalProjectsForSidebar,
sortSidebarV2ProjectGroups,
sortSettledThreadsForSidebarV2,
sortThreadsForSidebarV2,
} from "./Sidebar.logic";
@@ -1104,7 +1104,7 @@ export default function SidebarV2() {
],
);
const projectGroups = useMemo(
() => sortLogicalProjectsForSidebar(unsortedProjectGroups, threads, sidebarProjectSortOrder),
() => sortSidebarV2ProjectGroups(unsortedProjectGroups, threads, sidebarProjectSortOrder),
[sidebarProjectSortOrder, threads, unsortedProjectGroups],
);
const serverProviders = useAtomValue(primaryServerProvidersAtom);