From 5a48695efde197de14c2c96f5b965d03db76c1b5 Mon Sep 17 00:00:00 2001
From: nullStack65 <112618179+nullStack65@users.noreply.github.com>
Date: Fri, 20 Nov 2026 07:53:31 +0000
Subject: [PATCH 1/2] fix(web): sidebar filter counts include settled threads
from server totals
The filter menu counted only loaded, unsettled threads, so rows read about 10
while each server held hundreds. Count settled threads too, using the servers'
older-settled groups for threads the shell did not send, and say which threads
the counts leave out: unclassified threads the default inbox filter hides, and
delegated or subagent threads that open from their parent.
Model: claude-opus-5-5
Task: fix
Agent: claude-code
Lane: CLO-969
Co-Authored-By: Claude Opus 5.5
---
apps/web/src/components/Sidebar.tsx | 52 +++++++++--
.../sidebar/SidebarThreadFilterMenu.tsx | 33 +++++--
.../sidebar/threadListFilter.logic.test.ts | 58 ++++++++++---
.../sidebar/threadListFilter.logic.ts | 86 ++++++++++++++-----
4 files changed, 188 insertions(+), 41 deletions(-)
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index fc47b59ee670b..be6e1d70c36d4 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -1,11 +1,17 @@
import { SidebarThreadFilterMenu } from "./sidebar/SidebarThreadFilterMenu";
-import { matchesThreadListFilter, threadListFilterOf } from "./sidebar/threadListFilter.logic";
import {
+ matchesThreadListFilter,
+ threadListFilterOf,
+ type OlderSettledCounts,
+} from "./sidebar/threadListFilter.logic";
+import {
+ attributionOfSender,
launchingThreadIdOf,
resolveMachineOwners,
resolveThreadAttributions,
threadAttributionKey,
threadSenderLine,
+ type FounderByEnvironmentId,
} from "@t3tools/client-runtime/state/thread-attribution";
import {
matchesOlderSettledGroup,
@@ -15,6 +21,7 @@ import { threadRoutingUpdateFromMenuAction } from "./threadActionMenu.logic";
import { attachSidebarTree } from "../lib/sidebarTree";
import {
effectiveInboxFilter,
+ isOlderSettledThreadShell,
staysActiveWhileWorking,
type EnvironmentId,
type InboxChoice,
@@ -82,6 +89,7 @@ import {
} from "@t3tools/contracts";
import {
resolveListedAncestorThreadRef,
+ type OlderSettled,
type OlderSettledFilter,
type OlderSettledScope,
} from "@t3tools/client-runtime/state/threads";
@@ -780,6 +788,34 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) {
};
}
+function olderSettledFilterCounts(
+ scopes: ReadonlyArray,
+ olderOf: (environmentId: EnvironmentId) => OlderSettled | null,
+ owners: FounderByEnvironmentId,
+): OlderSettledCounts {
+ const counted = scopes.flatMap((scope) => {
+ const older = olderOf(scope.environmentId);
+ return older?.groups == null ? [] : [{ scope, older, groups: older.groups }];
+ });
+ return {
+ groups: counted.flatMap(({ scope, groups }) =>
+ (scope.projectIds ?? [...groups.keys()]).flatMap((projectId) =>
+ (groups.get(projectId) ?? []).map((group) => ({
+ environmentId: scope.environmentId,
+ group,
+ })),
+ ),
+ ),
+ attributionOf: (environmentId, group) => attributionOfSender(group, owners[environmentId]),
+ covers: (thread) =>
+ counted.some(
+ ({ scope, older }) =>
+ scope.environmentId === thread.environmentId &&
+ isOlderSettledThreadShell(thread.source, older.beforeMs),
+ ),
+ };
+}
+
/** The sidebar's scope per environment: the scoped projects there, or every project. */
function olderSettledScopes(
environmentIds: ReadonlyArray,
@@ -3112,11 +3148,15 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
- filterSidebarV2VisibleThreads(
- threads,
- scopedProjectKeys,
- delegatedUnderParent,
- ).filter((thread) => thread.settledOverride !== "settled")
+ filterSidebarV2VisibleThreads(threads, scopedProjectKeys, delegatedUnderParent)
+ }
+ olderSettled={() =>
+ olderSettledFilterCounts(
+ olderSettledScopes([...serverConfigs.keys()], scopedProjectKeys),
+ (environmentId) =>
+ olderSettledShelf.environments.get(environmentId)?.older ?? null,
+ machineOwners,
+ )
}
/>
}
diff --git a/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx b/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
index ac4716755cb33..95a200058c008 100644
--- a/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
+++ b/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
@@ -35,6 +35,7 @@ import {
threadListFilterOf,
toggleFilterOption,
toggleHiddenEnvironment,
+ type OlderSettledCounts,
type ThreadListFilter,
type ThreadListFilterBucketCounts,
} from "./threadListFilter.logic";
@@ -52,10 +53,12 @@ const LAST_OPTION_NOTE = ", the last one shown, so it stays checked";
/** Chooses which inboxes and environments the thread list shows. Search still finds every thread. */
export function SidebarThreadFilterMenu({
countedThreads,
+ olderSettled,
attributionOf,
}: {
/** Called only while the menu is open. */
countedThreads: () => ReadonlyArray;
+ olderSettled: () => OlderSettledCounts;
attributionOf: (thread: T) => ThreadAttribution;
}) {
const filter = useClientSettings(threadListFilterOf);
@@ -86,9 +89,10 @@ export function SidebarThreadFilterMenu({
}>
0 && "text-primary")} />
-
+
({
// Mounted only while the menu is open, so counting never runs on streaming ticks.
function SidebarThreadFilterOptions({
countedThreads,
+ olderSettled,
attributionOf,
filter,
owner,
@@ -110,6 +115,7 @@ function SidebarThreadFilterOptions({
isChanged,
}: {
countedThreads: () => ReadonlyArray;
+ olderSettled: () => OlderSettledCounts;
attributionOf: (thread: T) => ThreadAttribution;
filter: ThreadListFilter;
owner: Founder | undefined;
@@ -117,11 +123,18 @@ function SidebarThreadFilterOptions({
isChanged: boolean;
}) {
const connectedEnvironmentIds = useConnectedEnvironmentIds();
- const counts = threadListFilterCounts(countedThreads(), filter, attributionOf, owner);
+ const inboxOrder = inboxMenuOrder(owner);
+ const counts = threadListFilterCounts(
+ countedThreads(),
+ filter,
+ attributionOf,
+ owner,
+ olderSettled(),
+ );
+ const allInboxesShown = inboxOrder.every((inbox) => filter.inboxes.includes(inbox));
const shownAttributions = THREAD_ATTRIBUTIONS.filter(
(from) => !filter.hiddenAttributions.includes(from),
);
- const inboxOrder = inboxMenuOrder(owner);
const environmentIds = environments.map((environment) => environment.environmentId);
const shownEnvironmentIds = environmentIds.filter(
(id) => !filter.hiddenEnvironmentIds.includes(id),
@@ -225,6 +238,13 @@ function SidebarThreadFilterOptions({
>
) : null}
+
+
+ {!allInboxesShown && counts.unclassified > 0
+ ? `${counts.unclassified} thread${counts.unclassified === 1 ? " has" : "s have"} no inbox and ${counts.unclassified === 1 ? "shows" : "show"} only with every inbox checked. `
+ : null}
+ Delegated and subagent threads are not counted here; open them from their parent thread.
+
{isChanged ? (
<>
@@ -249,6 +269,7 @@ const STATE_COUNT_COLUMNS = [
["working", "working"],
["done", "done"],
["needsMe", "needs me"],
+ ["settled", "settled"],
] as const satisfies ReadonlyArray;
function stateCountPhrase(counts: ThreadListFilterBucketCounts) {
@@ -268,7 +289,7 @@ function FilterOptionRow({
{indicator}
{label}
-
+
{STATE_COUNT_COLUMNS.map(([key, name]) => {
const value = count[key];
return (
@@ -282,7 +303,9 @@ function FilterOptionRow({
? "text-info-foreground"
: key === "done"
? "text-success-foreground"
- : "text-warning-foreground",
+ : key === "needsMe"
+ ? "text-warning-foreground"
+ : "text-muted-foreground",
)}
>
{value}
diff --git a/apps/web/src/components/sidebar/threadListFilter.logic.test.ts b/apps/web/src/components/sidebar/threadListFilter.logic.test.ts
index 65d32f9f23ff3..05ed997a1e72a 100644
--- a/apps/web/src/components/sidebar/threadListFilter.logic.test.ts
+++ b/apps/web/src/components/sidebar/threadListFilter.logic.test.ts
@@ -57,16 +57,16 @@ describe("thread list filter", () => {
(candidate) => candidate.from,
);
expect(Object.fromEntries(counts.inboxes)).toEqual({
- kameron: { working: 0, done: 1, needsMe: 0 },
- agents: { working: 0, done: 1, needsMe: 0 },
+ kameron: { working: 0, done: 1, needsMe: 0, settled: 0 },
+ agents: { working: 0, done: 1, needsMe: 0, settled: 0 },
});
expect(Object.fromEntries(counts.environments)).toEqual({
- laptop: { working: 0, done: 1, needsMe: 0 },
- crown: { working: 0, done: 1, needsMe: 0 },
+ laptop: { working: 0, done: 1, needsMe: 0, settled: 0 },
+ crown: { working: 0, done: 1, needsMe: 0, settled: 0 },
});
expect(Object.fromEntries(counts.from)).toEqual({
- kameron: { working: 0, done: 1, needsMe: 0 },
- unknown: { working: 0, done: 1, needsMe: 0 },
+ kameron: { working: 0, done: 1, needsMe: 0, settled: 0 },
+ unknown: { working: 0, done: 1, needsMe: 0, settled: 0 },
});
expect(
matchesThreadListFilter(
@@ -233,7 +233,7 @@ describe("thread list filter", () => {
expect(threadListFilterBucket(fixtures.attention, "kameron")).toBe("needsMe");
expect(threadListFilterBucket(fixtures.parked, "kameron")).toBe("working");
expect(threadListFilterBucket(fixtures.parkedAttention, "kameron")).toBe("working");
- expect(threadListFilterBucket(fixtures.settled, "kameron")).toBeNull();
+ expect(threadListFilterBucket(fixtures.settled, "kameron")).toBe("settled");
expect(threadListFilterBucket(fixtures.otherFounder, "kameron")).toBe("done");
expect(threadListFilterBucket(fixtures.unstarted, "kameron")).toBeNull();
@@ -251,11 +251,49 @@ describe("thread list filter", () => {
(candidate) => candidate.from,
"kameron",
);
- const kameronRow = { working: 4, done: 2, needsMe: 4 };
- const everyRow = { working: 4, done: 3, needsMe: 4 };
+ const kameronRow = { working: 4, done: 2, needsMe: 4, settled: 1 };
+ const everyRow = { working: 4, done: 3, needsMe: 4, settled: 1 };
expect(counts.inboxes.get("kameron")).toEqual(kameronRow);
- expect(counts.inboxes.get("jeff")).toEqual({ working: 0, done: 1, needsMe: 0 });
+ expect(counts.inboxes.get("jeff")).toEqual({ working: 0, done: 1, needsMe: 0, settled: 0 });
expect(counts.environments.get(laptop)).toEqual(everyRow);
expect(counts.from.get("kameron")).toEqual(everyRow);
});
+
+ it("counts older settled threads from the servers' groups instead of the loaded rows", () => {
+ const settledRow = (environmentId: EnvironmentId, older: boolean) => ({
+ ...thread(environmentId, kameron),
+ settledOverride: "settled" as const,
+ older,
+ });
+ const loaded = [settledRow(laptop, false), settledRow(laptop, true), settledRow(crown, true)];
+ const group = (inbox: "kameron" | "jeff" | null, count: number, agentCreated = false) => ({
+ inbox,
+ agentCreated,
+ founder: "kameron" as const,
+ byAgent: false,
+ count,
+ });
+ const counts = threadListFilterCounts(
+ loaded,
+ threadListFilterOf({ founderInboxOwner: "kameron" }),
+ () => "kameron" as const,
+ "kameron",
+ {
+ groups: [
+ { environmentId: laptop, group: group("kameron", 40) },
+ { environmentId: laptop, group: group("jeff", 7) },
+ { environmentId: laptop, group: group(null, 5) },
+ { environmentId: laptop, group: group(null, 3, true) },
+ ],
+ attributionOf: () => "kameron",
+ covers: (candidate) => candidate.environmentId === laptop && candidate.older,
+ },
+ );
+ expect(counts.inboxes.get("kameron")?.settled).toBe(1 + 40 + 1);
+ expect(counts.inboxes.get("jeff")?.settled).toBe(7);
+ expect(counts.inboxes.get("agents")?.settled).toBe(3);
+ expect(counts.environments.get(laptop)?.settled).toBe(1 + 40 + 3);
+ expect(counts.environments.get(crown)?.settled).toBe(1);
+ expect(counts.unclassified).toBe(5);
+ });
});
diff --git a/apps/web/src/components/sidebar/threadListFilter.logic.ts b/apps/web/src/components/sidebar/threadListFilter.logic.ts
index 2ebaad0a2f2cb..5c936f0a08284 100644
--- a/apps/web/src/components/sidebar/threadListFilter.logic.ts
+++ b/apps/web/src/components/sidebar/threadListFilter.logic.ts
@@ -9,6 +9,7 @@ import {
InboxChoice,
primaryInbox,
type EnvironmentId,
+ type OrchestrationV2OlderSettledGroup,
type ThreadInbox,
} from "@t3tools/contracts";
import type { ThreadAttribution } from "@t3tools/contracts/settings";
@@ -49,20 +50,34 @@ const FINISHED_RUN_STATUSES: ReadonlySet = new Set([
"rolled_back",
]);
-export type ThreadListFilterBucket = "working" | "done" | "needsMe";
+export type ThreadListFilterBucket = "working" | "done" | "needsMe" | "settled";
export interface ThreadListFilterBucketCounts {
readonly working: number;
readonly done: number;
readonly needsMe: number;
+ readonly settled: number;
}
export const EMPTY_THREAD_LIST_FILTER_BUCKETS: ThreadListFilterBucketCounts = {
working: 0,
done: 0,
needsMe: 0,
+ settled: 0,
};
+export interface OlderSettledCounts {
+ readonly groups: ReadonlyArray<{
+ readonly environmentId: EnvironmentId;
+ readonly group: OrchestrationV2OlderSettledGroup;
+ }>;
+ readonly attributionOf: (
+ environmentId: EnvironmentId,
+ group: OrchestrationV2OlderSettledGroup,
+ ) => ThreadAttribution;
+ readonly covers: (thread: T) => boolean;
+}
+
const activityStatus = (thread: FilterableThread) =>
thread.runtime?.status ?? thread.latestRun?.status ?? null;
@@ -94,7 +109,7 @@ export function threadListFilterBucket(
thread: FilterableThread,
viewingFounder?: Founder,
): ThreadListFilterBucket | null {
- if (thread.settledOverride === "settled") return null;
+ if (thread.settledOverride === "settled") return "settled";
const status = activityStatus(thread);
if (waitsOnHuman(thread, viewingFounder)) return "needsMe";
if (thread.runtime?.status === "idle") return "working";
@@ -109,13 +124,6 @@ export function threadListFilterBucket(
return null;
}
-const matchesInboxes = (thread: FilterableThread, inboxes: ReadonlyArray) =>
- matchesListedInboxes(
- primaryInbox(thread.source.inbox),
- thread.source.createdBy === "agent",
- inboxes,
- );
-
/** The chosen founder's inbox first, then Agents, so the common pair sits together. */
export const inboxMenuOrder = (owner: Founder | undefined): ReadonlyArray => {
const first = owner ?? Founder.literals[0];
@@ -162,9 +170,10 @@ const addBucket = (
counts: Map,
key: K,
bucket: ThreadListFilterBucket | null,
+ amount: number,
) => {
const current = counts.get(key) ?? EMPTY_THREAD_LIST_FILTER_BUCKETS;
- counts.set(key, bucket === null ? current : { ...current, [bucket]: current[bucket] + 1 });
+ counts.set(key, bucket === null ? current : { ...current, [bucket]: current[bucket] + amount });
};
/**
@@ -176,25 +185,62 @@ export function threadListFilterCounts(
filter: ThreadListFilter,
attributionOf: (thread: T) => ThreadAttribution,
viewingFounder?: Founder,
+ older?: OlderSettledCounts,
) {
const inboxes = new Map();
const environments = new Map();
const from = new Map();
- for (const thread of threads) {
- const bucket = threadListFilterBucket(thread, viewingFounder);
- const attribution = attributionOf(thread);
- const environmentShown = !filter.hiddenEnvironmentIds.includes(thread.environmentId);
- const fromShown = !filter.hiddenAttributions.includes(attribution);
- const inboxShown = matchesInboxes(thread, filter.inboxes);
+ let unclassified = 0;
+ const tally = (entry: {
+ readonly environmentId: EnvironmentId;
+ readonly inbox: InboxChoice | null;
+ readonly agentCreated: boolean;
+ readonly attribution: ThreadAttribution;
+ readonly bucket: ThreadListFilterBucket | null;
+ readonly amount: number;
+ }) => {
+ const environmentShown = !filter.hiddenEnvironmentIds.includes(entry.environmentId);
+ const fromShown = !filter.hiddenAttributions.includes(entry.attribution);
+ const inboxShown = matchesListedInboxes(entry.inbox, entry.agentCreated, filter.inboxes);
if (environmentShown && fromShown) {
for (const choice of InboxChoice.literals) {
- if (matchesInboxes(thread, [choice])) addBucket(inboxes, choice, bucket);
+ if (matchesListedInboxes(entry.inbox, entry.agentCreated, [choice])) {
+ addBucket(inboxes, choice, entry.bucket, entry.amount);
+ }
+ }
+ if (entry.bucket !== null && entry.inbox === null && !entry.agentCreated) {
+ unclassified += entry.amount;
}
}
- if (inboxShown && fromShown) addBucket(environments, thread.environmentId, bucket);
- if (inboxShown && environmentShown) addBucket(from, attribution, bucket);
+ if (inboxShown && fromShown) {
+ addBucket(environments, entry.environmentId, entry.bucket, entry.amount);
+ }
+ if (inboxShown && environmentShown) {
+ addBucket(from, entry.attribution, entry.bucket, entry.amount);
+ }
+ };
+ for (const thread of threads) {
+ if (older?.covers(thread) === true) continue;
+ tally({
+ environmentId: thread.environmentId,
+ inbox: primaryInbox(thread.source.inbox),
+ agentCreated: thread.source.createdBy === "agent",
+ attribution: attributionOf(thread),
+ bucket: threadListFilterBucket(thread, viewingFounder),
+ amount: 1,
+ });
+ }
+ for (const { environmentId, group } of older?.groups ?? []) {
+ tally({
+ environmentId,
+ inbox: group.inbox,
+ agentCreated: group.agentCreated,
+ attribution: older?.attributionOf(environmentId, group) ?? "unknown",
+ bucket: "settled",
+ amount: group.count,
+ });
}
- return { inboxes, environments, from };
+ return { inboxes, environments, from, unclassified };
}
/** Toggles one option, keeping at least one checked so the list never empties by accident. */
From e5d099e5b976b7ddd1d2a9736dc9dc8ca6ffd3db Mon Sep 17 00:00:00 2001
From: nullStack65 <112618179+nullStack65@users.noreply.github.com>
Date: Fri, 20 Nov 2026 08:00:01 +0000
Subject: [PATCH 2/2] fix(web): count settled threads consistently and mark
minimum counts
Count loaded delegated rows the same way the servers' older-settled groups do,
mark settled counts as minimums when a server sends totals without groups,
and move the older-settled grouping into the tested filter logic.
Model: claude-opus-5-5
Task: fix
Agent: claude-code
Lane: CLO-969
Co-Authored-By: Claude Opus 5.5
---
apps/web/src/components/Sidebar.tsx | 37 +--------
.../sidebar/SidebarThreadFilterMenu.tsx | 19 +++--
.../sidebar/threadListFilter.logic.test.ts | 78 +++++++++++++----
.../sidebar/threadListFilter.logic.ts | 83 ++++++++++++++-----
4 files changed, 139 insertions(+), 78 deletions(-)
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index be6e1d70c36d4..182eec0612df3 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -1,17 +1,15 @@
import { SidebarThreadFilterMenu } from "./sidebar/SidebarThreadFilterMenu";
import {
matchesThreadListFilter,
+ olderSettledFilterCounts,
threadListFilterOf,
- type OlderSettledCounts,
} from "./sidebar/threadListFilter.logic";
import {
- attributionOfSender,
launchingThreadIdOf,
resolveMachineOwners,
resolveThreadAttributions,
threadAttributionKey,
threadSenderLine,
- type FounderByEnvironmentId,
} from "@t3tools/client-runtime/state/thread-attribution";
import {
matchesOlderSettledGroup,
@@ -21,7 +19,6 @@ import { threadRoutingUpdateFromMenuAction } from "./threadActionMenu.logic";
import { attachSidebarTree } from "../lib/sidebarTree";
import {
effectiveInboxFilter,
- isOlderSettledThreadShell,
staysActiveWhileWorking,
type EnvironmentId,
type InboxChoice,
@@ -89,7 +86,6 @@ import {
} from "@t3tools/contracts";
import {
resolveListedAncestorThreadRef,
- type OlderSettled,
type OlderSettledFilter,
type OlderSettledScope,
} from "@t3tools/client-runtime/state/threads";
@@ -367,6 +363,7 @@ const EMPTY_PROVIDER_ENTRIES: ReadonlyMap = new Ma
const EMPTY_THREADS: readonly EnvironmentThreadShell[] = [];
const SETTLED_TAIL_INITIAL_COUNT = 10;
+const NO_THREAD_KEYS: ReadonlySet = new Set();
const SETTLED_TAIL_PAGE_COUNT = 25;
const SETTLED_SHELF_EXPANDED_KEY = "t3code:sidebar:settled-expanded";
const SNOOZED_SHELF_EXPANDED_KEY = "t3code:sidebar:snoozed-expanded";
@@ -788,34 +785,6 @@ function partitionSidebarThreads(input: SidebarThreadPartitionInput) {
};
}
-function olderSettledFilterCounts(
- scopes: ReadonlyArray,
- olderOf: (environmentId: EnvironmentId) => OlderSettled | null,
- owners: FounderByEnvironmentId,
-): OlderSettledCounts {
- const counted = scopes.flatMap((scope) => {
- const older = olderOf(scope.environmentId);
- return older?.groups == null ? [] : [{ scope, older, groups: older.groups }];
- });
- return {
- groups: counted.flatMap(({ scope, groups }) =>
- (scope.projectIds ?? [...groups.keys()]).flatMap((projectId) =>
- (groups.get(projectId) ?? []).map((group) => ({
- environmentId: scope.environmentId,
- group,
- })),
- ),
- ),
- attributionOf: (environmentId, group) => attributionOfSender(group, owners[environmentId]),
- covers: (thread) =>
- counted.some(
- ({ scope, older }) =>
- scope.environmentId === thread.environmentId &&
- isOlderSettledThreadShell(thread.source, older.beforeMs),
- ),
- };
-}
-
/** The sidebar's scope per environment: the scoped projects there, or every project. */
function olderSettledScopes(
environmentIds: ReadonlyArray,
@@ -3148,7 +3117,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
- filterSidebarV2VisibleThreads(threads, scopedProjectKeys, delegatedUnderParent)
+ filterSidebarV2VisibleThreads(threads, scopedProjectKeys, NO_THREAD_KEYS)
}
olderSettled={() =>
olderSettledFilterCounts(
diff --git a/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx b/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
index 95a200058c008..73de563cdba85 100644
--- a/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
+++ b/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
@@ -31,11 +31,11 @@ import {
changedThreadListFilters,
EMPTY_THREAD_LIST_FILTER_BUCKETS,
inboxMenuOrder,
+ type olderSettledFilterCounts,
threadListFilterCounts,
threadListFilterOf,
toggleFilterOption,
toggleHiddenEnvironment,
- type OlderSettledCounts,
type ThreadListFilter,
type ThreadListFilterBucketCounts,
} from "./threadListFilter.logic";
@@ -47,7 +47,8 @@ const INBOX_LABELS: Record = {
shared: "Shared",
};
-type CountedThread = Parameters[0][number];
+type CountedThread = Parameters[0][number] &
+ Parameters["covers"]>[0];
const LAST_OPTION_NOTE = ", the last one shown, so it stays checked";
/** Chooses which inboxes and environments the thread list shows. Search still finds every thread. */
@@ -58,7 +59,7 @@ export function SidebarThreadFilterMenu({
}: {
/** Called only while the menu is open. */
countedThreads: () => ReadonlyArray;
- olderSettled: () => OlderSettledCounts;
+ olderSettled: () => ReturnType;
attributionOf: (thread: T) => ThreadAttribution;
}) {
const filter = useClientSettings(threadListFilterOf);
@@ -115,7 +116,7 @@ function SidebarThreadFilterOptions({
isChanged,
}: {
countedThreads: () => ReadonlyArray;
- olderSettled: () => OlderSettledCounts;
+ olderSettled: () => ReturnType;
attributionOf: (thread: T) => ThreadAttribution;
filter: ThreadListFilter;
owner: Founder | undefined;
@@ -124,12 +125,13 @@ function SidebarThreadFilterOptions({
}) {
const connectedEnvironmentIds = useConnectedEnvironmentIds();
const inboxOrder = inboxMenuOrder(owner);
+ const older = olderSettled();
const counts = threadListFilterCounts(
- countedThreads(),
+ countedThreads().filter((thread) => !older.covers(thread)),
filter,
attributionOf,
owner,
- olderSettled(),
+ older.groups,
);
const allInboxesShown = inboxOrder.every((inbox) => filter.inboxes.includes(inbox));
const shownAttributions = THREAD_ATTRIBUTIONS.filter(
@@ -243,7 +245,10 @@ function SidebarThreadFilterOptions({
{!allInboxesShown && counts.unclassified > 0
? `${counts.unclassified} thread${counts.unclassified === 1 ? " has" : "s have"} no inbox and ${counts.unclassified === 1 ? "shows" : "show"} only with every inbox checked. `
: null}
- Delegated and subagent threads are not counted here; open them from their parent thread.
+ {older.lowerBound
+ ? "Some servers send settled totals only, so settled counts are minimums. "
+ : null}
+ Subagent threads open from their parent and are not counted.
{isChanged ? (
<>
diff --git a/apps/web/src/components/sidebar/threadListFilter.logic.test.ts b/apps/web/src/components/sidebar/threadListFilter.logic.test.ts
index 05ed997a1e72a..ca4170986265c 100644
--- a/apps/web/src/components/sidebar/threadListFilter.logic.test.ts
+++ b/apps/web/src/components/sidebar/threadListFilter.logic.test.ts
@@ -1,10 +1,12 @@
-import { EnvironmentId, makeThreadInbox } from "@t3tools/contracts";
+import { EnvironmentId, ProjectId, ThreadId, makeThreadInbox } from "@t3tools/contracts";
+import * as DateTime from "effect/DateTime";
import { describe, expect, it } from "vite-plus/test";
import {
changedThreadListFilters,
inboxMenuOrder,
matchesThreadListFilter,
+ olderSettledFilterCounts,
threadListFilterBucket,
threadListFilterCounts,
threadListFilterOf,
@@ -260,12 +262,22 @@ describe("thread list filter", () => {
});
it("counts older settled threads from the servers' groups instead of the loaded rows", () => {
- const settledRow = (environmentId: EnvironmentId, older: boolean) => ({
+ const beforeMs = Date.parse("2026-11-18T00:00:00.000Z");
+ const lineage = {
+ relationshipToParent: null,
+ parentThreadId: null,
+ rootThreadId: ThreadId.make("root"),
+ };
+ const settledRow = (environmentId: EnvironmentId, settledAt: string) => ({
...thread(environmentId, kameron),
settledOverride: "settled" as const,
- older,
+ source: {
+ ...thread(environmentId, kameron).source,
+ lineage,
+ settledOverride: "settled" as const,
+ settledAt: DateTime.makeUnsafe(settledAt),
+ },
});
- const loaded = [settledRow(laptop, false), settledRow(laptop, true), settledRow(crown, true)];
const group = (inbox: "kameron" | "jeff" | null, count: number, agentCreated = false) => ({
inbox,
agentCreated,
@@ -273,21 +285,57 @@ describe("thread list filter", () => {
byAgent: false,
count,
});
+ const project = ProjectId.make("app");
+ const other = ProjectId.make("other");
+ const older = new Map([
+ [
+ laptop,
+ {
+ before: new Date(beforeMs).toISOString(),
+ beforeMs,
+ counts: new Map([
+ [project, 55],
+ [other, 9],
+ ]),
+ groups: new Map([
+ [
+ project,
+ [group("kameron", 40), group("jeff", 7), group(null, 5), group(null, 3, true)],
+ ],
+ [other, [group("kameron", 9)]],
+ ]),
+ },
+ ],
+ [
+ crown,
+ {
+ before: new Date(beforeMs).toISOString(),
+ beforeMs,
+ counts: new Map([[project, 12]]),
+ groups: null,
+ },
+ ],
+ ]);
+ const source = olderSettledFilterCounts(
+ [
+ { environmentId: laptop, projectIds: [project] },
+ { environmentId: crown, projectIds: null },
+ ],
+ (environmentId) => older.get(environmentId) ?? null,
+ {},
+ );
+ expect(source.lowerBound).toBe(true);
+ const loaded = [
+ settledRow(laptop, "2026-11-19T00:00:00.000Z"),
+ settledRow(laptop, "2026-11-17T00:00:00.000Z"),
+ settledRow(crown, "2026-11-17T00:00:00.000Z"),
+ ];
const counts = threadListFilterCounts(
- loaded,
+ loaded.filter((row) => !source.covers(row)),
threadListFilterOf({ founderInboxOwner: "kameron" }),
() => "kameron" as const,
"kameron",
- {
- groups: [
- { environmentId: laptop, group: group("kameron", 40) },
- { environmentId: laptop, group: group("jeff", 7) },
- { environmentId: laptop, group: group(null, 5) },
- { environmentId: laptop, group: group(null, 3, true) },
- ],
- attributionOf: () => "kameron",
- covers: (candidate) => candidate.environmentId === laptop && candidate.older,
- },
+ source.groups,
);
expect(counts.inboxes.get("kameron")?.settled).toBe(1 + 40 + 1);
expect(counts.inboxes.get("jeff")?.settled).toBe(7);
diff --git a/apps/web/src/components/sidebar/threadListFilter.logic.ts b/apps/web/src/components/sidebar/threadListFilter.logic.ts
index 5c936f0a08284..dd2bc6b3fc368 100644
--- a/apps/web/src/components/sidebar/threadListFilter.logic.ts
+++ b/apps/web/src/components/sidebar/threadListFilter.logic.ts
@@ -2,14 +2,20 @@ import {
matchesListedInboxes,
type ThreadListFilter,
} from "@t3tools/client-runtime/state/thread-list-filter";
+import {
+ attributionOfSender,
+ type FounderByEnvironmentId,
+} from "@t3tools/client-runtime/state/thread-attribution";
+import type { OlderSettled, OlderSettledScope } from "@t3tools/client-runtime/state/threads";
import {
effectiveInboxFilter,
+ isOlderSettledThreadShell,
founderInboxLane,
Founder,
InboxChoice,
primaryInbox,
type EnvironmentId,
- type OrchestrationV2OlderSettledGroup,
+ type OrchestrationV2ThreadShell,
type ThreadInbox,
} from "@t3tools/contracts";
import type { ThreadAttribution } from "@t3tools/contracts/settings";
@@ -66,16 +72,57 @@ export const EMPTY_THREAD_LIST_FILTER_BUCKETS: ThreadListFilterBucketCounts = {
settled: 0,
};
-export interface OlderSettledCounts {
- readonly groups: ReadonlyArray<{
- readonly environmentId: EnvironmentId;
- readonly group: OrchestrationV2OlderSettledGroup;
- }>;
- readonly attributionOf: (
- environmentId: EnvironmentId,
- group: OrchestrationV2OlderSettledGroup,
- ) => ThreadAttribution;
- readonly covers: (thread: T) => boolean;
+export interface OlderSettledGroupCount {
+ readonly environmentId: EnvironmentId;
+ readonly inbox: InboxChoice | null;
+ readonly agentCreated: boolean;
+ readonly attribution: ThreadAttribution;
+ readonly count: number;
+}
+
+export function olderSettledFilterCounts(
+ scopes: ReadonlyArray,
+ olderOf: (environmentId: EnvironmentId) => OlderSettled | null,
+ owners: FounderByEnvironmentId,
+) {
+ const grouped = scopes.flatMap((scope) => {
+ const older = olderOf(scope.environmentId);
+ return older?.groups == null ? [] : [{ scope, older, groups: older.groups }];
+ });
+ const groups: ReadonlyArray = grouped.flatMap(({ scope, groups }) =>
+ (scope.projectIds ?? [...groups.keys()]).flatMap((projectId) =>
+ (groups.get(projectId) ?? []).map((group) => ({
+ environmentId: scope.environmentId,
+ inbox: group.inbox,
+ agentCreated: group.agentCreated,
+ attribution: attributionOfSender(group, owners[scope.environmentId]),
+ count: group.count,
+ })),
+ ),
+ );
+ const lowerBound = scopes.some((scope) => {
+ const older = olderOf(scope.environmentId);
+ if (older === null || older.groups !== null) return false;
+ return (scope.projectIds ?? [...older.counts.keys()]).some(
+ (projectId) => (older.counts.get(projectId) ?? 0) > 0,
+ );
+ });
+ return {
+ groups,
+ lowerBound,
+ covers: (thread: {
+ readonly environmentId: EnvironmentId;
+ readonly source: Pick<
+ OrchestrationV2ThreadShell,
+ "lineage" | "settledOverride" | "settledAt"
+ >;
+ }) =>
+ grouped.some(
+ ({ scope, older }) =>
+ scope.environmentId === thread.environmentId &&
+ isOlderSettledThreadShell(thread.source, older.beforeMs),
+ ),
+ };
}
const activityStatus = (thread: FilterableThread) =>
@@ -185,7 +232,7 @@ export function threadListFilterCounts(
filter: ThreadListFilter,
attributionOf: (thread: T) => ThreadAttribution,
viewingFounder?: Founder,
- older?: OlderSettledCounts,
+ olderGroups: ReadonlyArray = [],
) {
const inboxes = new Map();
const environments = new Map();
@@ -220,7 +267,6 @@ export function threadListFilterCounts(
}
};
for (const thread of threads) {
- if (older?.covers(thread) === true) continue;
tally({
environmentId: thread.environmentId,
inbox: primaryInbox(thread.source.inbox),
@@ -230,15 +276,8 @@ export function threadListFilterCounts(
amount: 1,
});
}
- for (const { environmentId, group } of older?.groups ?? []) {
- tally({
- environmentId,
- inbox: group.inbox,
- agentCreated: group.agentCreated,
- attribution: older?.attributionOf(environmentId, group) ?? "unknown",
- bucket: "settled",
- amount: group.count,
- });
+ for (const group of olderGroups) {
+ tally({ ...group, bucket: "settled", amount: group.count });
}
return { inboxes, environments, from, unclassified };
}