fix: hide subagent threads from v2 lists

Co-authored-by: codex <[email protected]>
This commit is contained in:
Yusuf007Randcodex authored and Julius Marminge committed 2026-08-14 11:23:28 +02:00
1 parent 03366d5830
commit 94eb4ce02f
5 files changed
+3598 -7

No files matched your search

@@ -263,19 +263,66 @@ describe("sortThreadsForListV2", () => {
});
describe("buildThreadListV2Items", () => {
it("keeps a merged thread active when auto-settle on merge is off", () => {
const merged = makeThread({ id: ThreadId.make("merged"), title: "Merged" });
it("excludes subagent child threads from top-level rows and counts", () => {
const rootThreadId = ThreadId.make("root");
const activeChildId = ThreadId.make("active-child");
const forkId = ThreadId.make("fork");
const settledChildId = ThreadId.make("settled-child");
const snoozedChildId = ThreadId.make("snoozed-child");
const layout = buildThreadListV2Items({
threads: [merged],
threads: [
makeThread({ id: rootThreadId, title: "Root" }),
makeThread({
id: forkId,
title: "Fork",
lineage: {
rootThreadId,
parentThreadId: rootThreadId,
relationshipToParent: "fork",
},
}),
makeThread({
id: activeChildId,
title: "Active child",
lineage: {
rootThreadId,
parentThreadId: rootThreadId,
relationshipToParent: "subagent",
},
}),
makeThread({
id: settledChildId,
title: "Settled child",
lineage: {
rootThreadId,
parentThreadId: rootThreadId,
relationshipToParent: "subagent",
},
settledOverride: "settled",
settledAt: "2026-06-01T12:00:00.000Z",
}),
makeThread({
id: snoozedChildId,
title: "Snoozed child",
lineage: {
rootThreadId,
parentThreadId: rootThreadId,
relationshipToParent: "subagent",
},
snoozedUntil: "2026-06-03T09:00:00.000Z",
snoozedAt: "2026-06-01T12:00:00.000Z",
}),
],
environmentId: null,
searchQuery: "",
changeRequestStateByKey: new Map([[`${environmentId}:${merged.id}`, "merged"]]),
autoSettleOnMerge: false,
now: NOW,
settledLimit: 0,
});
expect(layout.items.map((item) => item.thread.id)).toEqual(["merged"]);
expect(layout.settledCount).toBe(0);
expect(layout.items.map((item) => item.thread.id)).toEqual([forkId, rootThreadId]);
expect(layout.hiddenSettledCount).toBe(0);
expect(layout.snoozedCount).toBe(0);
expect(layout.nextSnoozeWakeAt).toBeNull();
});
it("hides snoozed threads and counts them — visibility parity with web", () => {
@@ -361,6 +361,7 @@ export function buildThreadListV2Items(input: {
const snoozed: EnvironmentThreadShell[] = [];
let nextSnoozeWakeAt: string | null = null;
for (const thread of input.threads) {
if (thread.lineage.relationshipToParent === "subagent") continue;
// Callers pass live (unarchived) shells; settled threads are among them
// and partition into the tail via effectiveSettled.
if (input.environmentId !== null && thread.environmentId !== input.environmentId) continue;
@@ -4,6 +4,7 @@ import {
buildBulkTitleRegenerationContextMenuItem,
buildMultiSelectThreadContextMenuItems,
createThreadJumpHintVisibilityController,
filterSidebarV2VisibleThreads,
getSidebarThreadIdsToPrewarm,
getVisibleSidebarThreadIds,
resolveAdjacentThreadId,
@@ -240,6 +241,55 @@ describe("resolveSidebarStageBadgeLabel", () => {
});
describe("sidebar thread lineage helpers", () => {
it("keeps only top-level, unarchived threads in the Sidebar V2 project scope", () => {
const parentId = ThreadId.make("thread-parent");
const projectId = ProjectId.make("project-visible");
const environmentId = EnvironmentId.make("environment-visible");
const root = makeThreadFixture({
id: parentId,
environmentId,
projectId,
});
const subagent = makeThreadFixture({
id: ThreadId.make("thread-subagent"),
environmentId,
projectId,
lineage: {
rootThreadId: parentId,
parentThreadId: parentId,
relationshipToParent: "subagent",
},
});
const fork = makeThreadFixture({
id: ThreadId.make("thread-fork"),
environmentId,
projectId,
lineage: {
rootThreadId: parentId,
parentThreadId: parentId,
relationshipToParent: "fork",
},
});
const archived = makeThreadFixture({
id: ThreadId.make("thread-archived"),
environmentId,
projectId,
archivedAt: "2026-01-02T00:00:00.000Z",
});
const otherProject = makeThreadFixture({
id: ThreadId.make("thread-other-project"),
environmentId,
projectId: ProjectId.make("project-other"),
});
expect(
filterSidebarV2VisibleThreads(
[root, subagent, fork, archived, otherProject],
new Set([`${environmentId}:${projectId}`]),
).map((thread) => thread.id),
).toEqual([parentId, fork.id]);
});
it("identifies subagent threads so the sidebar can hide them", () => {
const parentId = ThreadId.make("thread-parent");
const subagent = makeThreadFixture({
+12
View File
@@ -54,6 +54,18 @@ export function isSidebarSubagentThread(thread: Pick<SidebarThreadSummary, "line
return thread.lineage.relationshipToParent === "subagent";
}
export function filterSidebarV2VisibleThreads<
T extends Pick<SidebarThreadSummary, "archivedAt" | "environmentId" | "lineage" | "projectId">,
>(threads: readonly T[], scopedProjectKeys: ReadonlySet<string> | null): T[] {
return threads.filter(
(thread) =>
thread.archivedAt === null &&
!isSidebarSubagentThread(thread) &&
(scopedProjectKeys === null ||
scopedProjectKeys.has(`${thread.environmentId}:${thread.projectId}`)),
);
}
export function getSidebarForkParentThreadId(
thread: Pick<SidebarThreadSummary, "forkedFrom" | "lineage">,
) {
File diff suppressed because it is too large. Load diff