From feec7b1aa9c3e7388ab0bd3bc6e55bf6b8bbbbf1 Mon Sep 17 00:00:00 2001 From: Yusuf007R Date: Sat, 25 Jul 2026 01:29:34 -0500 Subject: [PATCH] fix: hide subagent threads from v2 lists Co-authored-by: codex --- .../src/features/threads/threadListV2.test.ts | 62 +++++++++++++++++++ .../src/features/threads/threadListV2.ts | 1 + apps/web/src/components/Sidebar.logic.test.ts | 50 +++++++++++++++ apps/web/src/components/Sidebar.logic.ts | 12 ++++ apps/web/src/components/SidebarV2.tsx | 8 +-- 5 files changed, 127 insertions(+), 6 deletions(-) diff --git a/apps/mobile/src/features/threads/threadListV2.test.ts b/apps/mobile/src/features/threads/threadListV2.test.ts index 1316b3480c..7a04562f18 100644 --- a/apps/mobile/src/features/threads/threadListV2.test.ts +++ b/apps/mobile/src/features/threads/threadListV2.test.ts @@ -259,6 +259,68 @@ describe("sortThreadsForListV2", () => { }); describe("buildThreadListV2Items", () => { + 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: [ + 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: "", + now: NOW, + settledLimit: 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", () => { const layout = buildThreadListV2Items({ threads: [ diff --git a/apps/mobile/src/features/threads/threadListV2.ts b/apps/mobile/src/features/threads/threadListV2.ts index fa5f58d5d0..a062789867 100644 --- a/apps/mobile/src/features/threads/threadListV2.ts +++ b/apps/mobile/src/features/threads/threadListV2.ts @@ -359,6 +359,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; diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts index 148ef10990..b49fa17beb 100644 --- a/apps/web/src/components/Sidebar.logic.test.ts +++ b/apps/web/src/components/Sidebar.logic.test.ts @@ -4,6 +4,7 @@ import { buildBulkTitleRegenerationContextMenuItem, buildMultiSelectThreadContextMenuItems, createThreadJumpHintVisibilityController, + filterSidebarV2VisibleThreads, getSidebarThreadIdsToPrewarm, getVisibleSidebarThreadIds, resolveAdjacentThreadId, @@ -236,6 +237,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({ diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index fb864cb881..95bac7cb73 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -54,6 +54,18 @@ export function isSidebarSubagentThread(thread: Pick, +>(threads: readonly T[], scopedProjectKeys: ReadonlySet | null): T[] { + return threads.filter( + (thread) => + thread.archivedAt === null && + !isSidebarSubagentThread(thread) && + (scopedProjectKeys === null || + scopedProjectKeys.has(`${thread.environmentId}:${thread.projectId}`)), + ); +} + export function getSidebarForkParentThreadId( thread: Pick, ) { diff --git a/apps/web/src/components/SidebarV2.tsx b/apps/web/src/components/SidebarV2.tsx index 81d8835080..8809eeb35b 100644 --- a/apps/web/src/components/SidebarV2.tsx +++ b/apps/web/src/components/SidebarV2.tsx @@ -112,6 +112,7 @@ import { buildThreadActionMenuItems } from "./threadActionMenu.logic"; import { buildBulkTitleRegenerationContextMenuItem, formatWorkingDurationLabel, + filterSidebarV2VisibleThreads, firstValidTimestampMs, hasUnseenCompletion, isTrailingDoubleClick, @@ -1711,12 +1712,7 @@ export default function SidebarV2() { // memo exactly at the next wake boundary. void snoozeWakeTick; const preciseNow = new Date().toISOString(); - const visible = threads.filter( - (thread) => - thread.archivedAt === null && - (scopedProjectKeys === null || - scopedProjectKeys.has(`${thread.environmentId}:${thread.projectId}`)), - ); + const visible = filterSidebarV2VisibleThreads(threads, scopedProjectKeys); const pinned: EnvironmentThreadShell[] = []; const active: EnvironmentThreadShell[] = []; const snoozed: EnvironmentThreadShell[] = [];