π OpenHands: AI-Driven Development
fix: make sidebar "Load more" discover folders, not folder contents (#16179)
FraterCCCLXIII73434d688b8f
diff --git a/__tests__/components/features/conversation-panel/conversation-panel-list-helpers.test.ts b/__tests__/components/features/conversation-panel/conversation-panel-list-helpers.test.tsindex f9edaaeb6c..ad2fe58aa7 100644--- a/__tests__/components/features/conversation-panel/conversation-panel-list-helpers.test.ts+++ b/__tests__/components/features/conversation-panel/conversation-panel-list-helpers.test.ts@@ -4,6 +4,7 @@ import {applyGroupFolderOrder,collectAutomationNameFacets,getGroupConversationPreview,+ getGroupDiscoveryConversationIds,groupConversations,GROUP_CONVERSATIONS_PREVIEW_LIMIT,isAutomationConversation,@@ -259,6 +260,83 @@ describe("conversation-panel-list-helpers", () => {expect(GROUP_CONVERSATIONS_PREVIEW_LIMIT).toBe(5);});+ it("freezes discovery preview ids per folder and force-includes the active conversation", () => {+ // Later pages may still contain rows for already-visible folders; those+ // stay out of the collapsed discovery set so global Load more does not+ // mutate an exposed folder's preview. The active conversation is still+ // force-included even when it lands on a non-discovery page.+ const items = [+ {+ ...base,+ id: "none-1",+ title: "None 1",+ selected_workspace: null,+ },+ {+ ...base,+ id: "none-2",+ title: "None 2",+ selected_workspace: null,+ },+ {+ ...base,+ id: "alpha-1",+ title: "Alpha 1",+ selected_workspace: "/workspace/alpha",+ },+ ] as AppConversation[];+ const pageByConversationId = new Map([+ ["none-1", 0],+ ["none-2", 1],+ ["alpha-1", 1],+ ]);++ expect([+ ...getGroupDiscoveryConversationIds(+ items,+ pageByConversationId,+ "local",+ ),+ ]).toEqual(["none-1", "alpha-1"]);++ expect([+ ...getGroupDiscoveryConversationIds(items, pageByConversationId, "local", {+ forceIncludeConversationId: "none-2",+ }),+ ]).toEqual(["none-1", "alpha-1", "none-2"]);++ const grouped = groupConversations(items, "local", "updated", {+ emptyWorkspace: "No workspace",+ emptyRepository: "No repository",+ });+ const noneGroup = grouped.find((group) => group.id === "__none_workspace");+ expect(noneGroup?.conversations.map((c) => c.id)).toEqual([+ "none-1",+ "none-2",+ ]);++ const discoveryIds = getGroupDiscoveryConversationIds(+ items,+ pageByConversationId,+ "local",+ );+ const collapsed = getGroupConversationPreview(noneGroup!.conversations, {+ expanded: false,+ discoveryConversationIds: discoveryIds,+ });+ expect(collapsed.visibleConversations.map((c) => c.id)).toEqual(["none-1"]);+ expect(collapsed.isPreviewTruncated).toBe(true);++ const expanded = getGroupConversationPreview(noneGroup!.conversations, {+ expanded: true,+ discoveryConversationIds: discoveryIds,+ });+ expect(expanded.visibleConversations.map((c) => c.id)).toEqual([+ "none-1",+ "none-2",+ ]);+ });+it("resolvePinnedConversations preserves pin order and drops missing ids", () => {const conversations = [{ ...base, id: "a", title: "A" },diff --git a/__tests__/components/features/conversation-panel/conversation-panel.test.tsx b/__tests__/components/features/conversation-panel/conversation-panel.test.tsxindex d5851d6802..463f2ce169 100644--- a/__tests__/components/features/conversation-panel/conversation-panel.test.tsx+++ b/__tests__/components/features/conversation-panel/conversation-panel.test.tsx@@ -2025,6 +2025,195 @@ describe("ConversationPanel", () => {).not.toBeInTheDocument();});});++ it("keeps collapsed folder previews stable while still exposing later-page conversations on expand", async () => {+ useConversationPanelPreferencesStore.setState({+ organizeMode: "grouped",+ });+ const noWorkspaceConversations = Array.from({ length: 6 }, (_, index) =>+ createMockConversation({+ id: `no-workspace-${index + 1}`,+ title: `No workspace ${index + 1}`,+ }),+ );+ const searchSpy = vi+ .spyOn(AgentServerConversationService, "searchConversations")+ .mockResolvedValueOnce({+ items: noWorkspaceConversations,+ next_page_id: "page-2",+ })+ .mockResolvedValueOnce({+ items: [+ createMockConversation({+ id: "no-workspace-7",+ title: "No workspace 7",+ }),+ createMockConversation({+ id: "no-workspace-8",+ title: "No workspace 8",+ }),+ ],+ next_page_id: "page-3",+ })+ .mockResolvedValueOnce({+ items: [+ createMockConversation({+ id: "alpha",+ title: "Alpha conversation",+ selected_workspace: "/workspace/alpha",+ }),+ ],+ next_page_id: null,+ });++ const user = userEvent.setup();+ renderConversationPanel();++ const noWorkspaceFolder = await screen.findByTestId(+ "thread-folder-__none_workspace",+ );+ expect(+ within(noWorkspaceFolder).getAllByTestId("conversation-card"),+ ).toHaveLength(5);+ expect(+ within(noWorkspaceFolder).queryByText("No workspace 7"),+ ).not.toBeInTheDocument();++ // A single click walks past the deepen-only page 2 (its rows are hidden+ // from the collapsed preview, so they are not success) and keeps paging+ // until the brand-new folder on page 3 is discovered.+ await user.click(screen.getByTestId("load-more-conversations"));+ await screen.findByTestId("thread-folder-ws--workspace-alpha");+ expect(searchSpy).toHaveBeenCalledTimes(3);+ expect(+ within(noWorkspaceFolder).getAllByTestId("conversation-card"),+ ).toHaveLength(5);+ expect(+ within(noWorkspaceFolder).queryByText("No workspace 7"),+ ).not.toBeInTheDocument();++ // Collapsed preview stays frozen; expanding reveals every loaded row.+ expect(+ within(noWorkspaceFolder).getAllByTestId("conversation-card"),+ ).toHaveLength(5);+ await user.click(+ within(noWorkspaceFolder).getByTestId(+ "thread-folder-view-more-__none_workspace",+ ),+ );+ expect(+ within(noWorkspaceFolder).getAllByTestId("conversation-card"),+ ).toHaveLength(8);+ expect(+ within(noWorkspaceFolder).getByText("No workspace 7"),+ ).toBeInTheDocument();+ expect(+ within(noWorkspaceFolder).getByText("No workspace 8"),+ ).toBeInTheDocument();+ });++ it("caps a grouped load-more click at three pages when no new folder appears", async () => {+ useConversationPanelPreferencesStore.setState({+ organizeMode: "grouped",+ });+ const deepenOnlyPage = (page: number, nextPageId: string) => ({+ items: Array.from({ length: 2 }, (_, index) =>+ createMockConversation({+ id: `no-workspace-p${page}-${index + 1}`,+ title: `No workspace p${page}-${index + 1}`,+ }),+ ),+ next_page_id: nextPageId,+ });+ // Exactly four pages are queued: the drive must consume the initial page+ // plus MAX_PAGES_PER_LOAD_MORE_CLICK more and stop β a fetch beyond the+ // cap would find no queued response and fail the test loudly.+ const searchSpy = vi+ .spyOn(AgentServerConversationService, "searchConversations")+ .mockResolvedValueOnce(deepenOnlyPage(1, "page-2"))+ .mockResolvedValueOnce(deepenOnlyPage(2, "page-3"))+ .mockResolvedValueOnce(deepenOnlyPage(3, "page-4"))+ .mockResolvedValueOnce(deepenOnlyPage(4, "page-5"));++ const user = userEvent.setup();+ renderConversationPanel();++ await screen.findByTestId("thread-folder-__none_workspace");+ expect(searchSpy).toHaveBeenCalledTimes(1);++ // Every remaining page only deepens the existing folder, so the driver+ // must stop at the per-click page cap instead of draining the cursor.+ await user.click(screen.getByTestId("load-more-conversations"));+ await waitFor(() => {+ expect(searchSpy).toHaveBeenCalledTimes(4);+ });+ // The drive has ended: the control is idle again and no further page+ // was requested beyond the cap.+ await waitFor(() => {+ expect(+ screen.getByTestId("load-more-conversations"),+ ).toBeInTheDocument();+ });+ expect(searchSpy).toHaveBeenCalledTimes(4);+ });++ it("force-includes the active conversation in a folder preview even when it arrived on a later page", async () => {+ useConversationPanelPreferencesStore.setState({+ organizeMode: "grouped",+ });+ vi.spyOn(AgentServerConversationService, "searchConversations")+ .mockResolvedValueOnce({+ items: Array.from({ length: 5 }, (_, index) =>+ createMockConversation({+ id: `alpha-${index + 1}`,+ title: `Alpha ${index + 1}`,+ selected_workspace: "/workspace/alpha",+ }),+ ),+ next_page_id: "page-2",+ })+ .mockResolvedValueOnce({+ items: [+ createMockConversation({+ id: "alpha-active",+ title: "Alpha Active",+ selected_workspace: "/workspace/alpha",+ }),+ ],+ next_page_id: null,+ });++ const user = userEvent.setup();+ renderConversationPanel({+ navigation: {+ conversationId: "alpha-active",+ currentPath: "/conversations/alpha-active",+ },+ });++ const alphaFolder = await screen.findByTestId(+ "thread-folder-ws--workspace-alpha",+ );+ expect(+ within(alphaFolder).queryByText("Alpha Active"),+ ).not.toBeInTheDocument();++ await user.click(screen.getByTestId("load-more-conversations"));++ await waitFor(() => {+ expect(+ within(+ screen.getByTestId("thread-folder-ws--workspace-alpha"),+ ).getByText("Alpha Active"),+ ).toBeInTheDocument();+ });+ // Still a collapsed preview (limit 5), not the full expanded list.+ expect(+ within(+ screen.getByTestId("thread-folder-ws--workspace-alpha"),+ ).getAllByTestId("conversation-card"),+ ).toHaveLength(5);+ });});it("reorders grouped folders via drag and drop", async () => {diff --git a/src/components/features/conversation-panel/conversation-group-folder-list.tsx b/src/components/features/conversation-panel/conversation-group-folder-list.tsxindex e71549b4f6..7c15ff8e83 100644--- a/src/components/features/conversation-panel/conversation-group-folder-list.tsx+++ b/src/components/features/conversation-panel/conversation-group-folder-list.tsx@@ -30,6 +30,7 @@ interface ConversationGroupFolderListProps {setGroupFolderOrder: (order: readonly string[]) => void;collapsedGroupIds: ReadonlySet<string>;expandedGroupPreviewIds: ReadonlySet<string>;+ discoveryConversationIds: ReadonlySet<string> | null;onToggleGroupCollapsed: (groupId: string) => void;onToggleGroupPreviewExpanded: (groupId: string) => void;isCreatingConversationFlow: boolean;@@ -45,6 +46,7 @@ export function ConversationGroupFolderList({setGroupFolderOrder,collapsedGroupIds,expandedGroupPreviewIds,+ discoveryConversationIds,onToggleGroupCollapsed,onToggleGroupPreviewExpanded,isCreatingConversationFlow,@@ -151,6 +153,7 @@ export function ConversationGroupFolderList({animateLayout={animateLayout}isCreatingConversationFlow={isCreatingConversationFlow}activeConversationId={activeConversationId}+ discoveryConversationIds={discoveryConversationIds}onToggleExpanded={() => onToggleGroupCollapsed(group.id)}onDragStart={() => {setAnimateLayout(true);diff --git a/src/components/features/conversation-panel/conversation-group-folder-row.tsx b/src/components/features/conversation-panel/conversation-group-folder-row.tsxindex edff1e42bf..db72f939ae 100644--- a/src/components/features/conversation-panel/conversation-group-folder-row.tsx+++ b/src/components/features/conversation-panel/conversation-group-folder-row.tsx@@ -27,6 +27,7 @@ interface ConversationGroupFolderRowProps {animateLayout: boolean;isCreatingConversationFlow: boolean;activeConversationId?: string | null;+ discoveryConversationIds?: ReadonlySet<string> | null;onToggleExpanded: () => void;onDragStart: () => void;onDragEnd: () => void;@@ -47,6 +48,7 @@ export function ConversationGroupFolderRow({animateLayout,isCreatingConversationFlow,activeConversationId,+ discoveryConversationIds,onToggleExpanded,onDragStart,onDragEnd,@@ -65,6 +67,7 @@ export function ConversationGroupFolderRow({getGroupConversationPreview(group.conversations, {expanded: previewExpanded,activeConversationId,+ discoveryConversationIds: discoveryConversationIds ?? undefined,});return (diff --git a/src/components/features/conversation-panel/conversation-panel-list-helpers.ts b/src/components/features/conversation-panel/conversation-panel-list-helpers.tsindex 362fb0512a..b2bc2a61dd 100644--- a/src/components/features/conversation-panel/conversation-panel-list-helpers.ts+++ b/src/components/features/conversation-panel/conversation-panel-list-helpers.ts@@ -21,6 +21,50 @@ interface GroupConversationPreviewOptions {limit?: number;expanded: boolean;activeConversationId?: string | null;+ /**+ * When set, the collapsed preview is drawn only from these conversation IDs+ * (plus the active conversation when it belongs to the group). Expanding+ * still reveals every loaded conversation in `conversations`.+ */+ discoveryConversationIds?: ReadonlySet<string>;+}++/**+ * Builds the frozen collapsed-preview pool for a folder.+ *+ * Global "Load more" may fetch later pages that add conversations to an+ * already-visible folder; those rows stay out of the collapsed preview so the+ * folder's first impression stays stable until the user expands it.+ */+function resolveCollapsedPreviewPool(+ conversations: readonly AppConversation[],+ discoveryConversationIds: ReadonlySet<string> | undefined,+ activeConversationId: string | null | undefined,+): AppConversation[] {+ if (!discoveryConversationIds) {+ return [...conversations];+ }++ const pool = conversations.filter((conversation) =>+ discoveryConversationIds.has(conversation.id),+ );++ // The load-bearing active-conversation guarantee lives in+ // `getGroupDiscoveryConversationIds` (`forceIncludeConversationId`); this+ // fallback only covers callers that pass a discovery set built without it.+ if (+ activeConversationId != null &&+ !pool.some((conversation) => conversation.id === activeConversationId)+ ) {+ const activeConversation = conversations.find(+ (conversation) => conversation.id === activeConversationId,+ );+ if (activeConversation) {+ pool.push(activeConversation);+ }+ }++ return pool;}export function getGroupConversationPreview(@@ -32,36 +76,45 @@ export function getGroupConversationPreview(isShowingAll: boolean;} {const limit = options.limit ?? GROUP_CONVERSATIONS_PREVIEW_LIMIT;+ const pool = resolveCollapsedPreviewPool(+ conversations,+ options.discoveryConversationIds,+ options.activeConversationId,+ );- if (options.expanded || conversations.length <= limit) {- return {- visibleConversations: [...conversations],- isPreviewTruncated: conversations.length > limit,- isShowingAll: true,- };+ let collapsedVisible: AppConversation[];+ if (pool.length <= limit) {+ collapsedVisible = pool;+ } else {+ const activeIndex =+ options.activeConversationId != null+ ? pool.findIndex(+ (conversation) => conversation.id === options.activeConversationId,+ )+ : -1;++ if (activeIndex >= limit) {+ collapsedVisible = [...pool.slice(0, limit - 1), pool[activeIndex]];+ } else {+ collapsedVisible = pool.slice(0, limit);+ }}- const activeIndex =- options.activeConversationId != null- ? conversations.findIndex((c) => c.id === options.activeConversationId)- : -1;+ const collapsedHidesSomething =+ collapsedVisible.length < conversations.length;- if (activeIndex >= limit) {- const activeConversation = conversations[activeIndex];+ if (options.expanded) {return {- visibleConversations: [- ...conversations.slice(0, limit - 1),- activeConversation,- ],- isPreviewTruncated: true,- isShowingAll: false,+ visibleConversations: [...conversations],+ isPreviewTruncated: collapsedHidesSomething,+ isShowingAll: true,};}return {- visibleConversations: conversations.slice(0, limit),- isPreviewTruncated: conversations.length > limit,- isShowingAll: false,+ visibleConversations: collapsedVisible,+ isPreviewTruncated: collapsedHidesSomething,+ isShowingAll: !collapsedHidesSomething,};}@@ -285,6 +338,82 @@ function repositoryGroup(conversation: AppConversation): {return { id: `repo:${normalized}`, label };}+/**+ * Resolves the stable folder identity used by grouped conversation views.+ *+ * Keeping this shared with `groupConversations` lets pagination reason about+ * folder discovery without duplicating workspace/repository normalization.+ */+function getConversationGroupIdentity(+ conversation: AppConversation,+ backendKind: BackendKind,+): { id: string; label: string } {+ return backendKind === "local"+ ? workspaceGroup(conversation)+ : repositoryGroup(conversation);+}++/**+ * Max backend pages fetched for a single grouped "Load more" click. The+ * driver walks past pages that only deepen already-visible folders looking+ * for a new folder, and this cap prevents one click from walking the entire+ * remaining cursor when no undiscovered folder exists. Chronological mode is+ * not capped β it keeps its pre-existing fetch-until-visible behavior.+ */+export const MAX_PAGES_PER_LOAD_MORE_CLICK = 3;++/**+ * Conversation IDs that belong on each folder's discovery page β the first+ * backend page where that folder appeared.+ *+ * Global "Load more" still discovers folders from later pages, but the+ * collapsed preview for an already-visible folder stays frozen to this set.+ * Expanding the folder reads the full grouped `conversations` array instead.+ * `forceIncludeConversationId` keeps the active thread in the preview even+ * when it landed on a non-discovery page.+ */+export function getGroupDiscoveryConversationIds(+ items: readonly AppConversation[],+ pageByConversationId: ReadonlyMap<string, number>,+ backendKind: BackendKind,+ options?: { forceIncludeConversationId?: string | null },+): Set<string> {+ // Resolve each conversation's folder identity exactly once; both passes+ // below (finding each folder's discovery page, then collecting the ids on+ // that page) read from this record instead of re-running the+ // workspace/repository normalization.+ const resolved = items.map((conversation) => ({+ conversationId: conversation.id,+ groupId: getConversationGroupIdentity(conversation, backendKind).id,+ page: pageByConversationId.get(conversation.id) ?? 0,+ }));++ const discoveryPageByGroupId = new Map<string, number>();+ for (const { groupId, page } of resolved) {+ const currentDiscoveryPage = discoveryPageByGroupId.get(groupId);+ if (currentDiscoveryPage === undefined || page < currentDiscoveryPage) {+ discoveryPageByGroupId.set(groupId, page);+ }+ }++ const discoveryIds = new Set<string>();+ for (const { conversationId, groupId, page } of resolved) {+ if (page === discoveryPageByGroupId.get(groupId)) {+ discoveryIds.add(conversationId);+ }+ }++ const forceIncludeId = options?.forceIncludeConversationId;+ if (+ forceIncludeId != null &&+ items.some((conversation) => conversation.id === forceIncludeId)+ ) {+ discoveryIds.add(forceIncludeId);+ }++ return discoveryIds;+}+export function groupConversations(items: readonly AppConversation[],backendKind: BackendKind,@@ -302,8 +431,10 @@ export function groupConversations(>();for (const c of items) {- const { id, label: rawLabel } =- backendKind === "local" ? workspaceGroup(c) : repositoryGroup(c);+ const { id, label: rawLabel } = getConversationGroupIdentity(+ c,+ backendKind,+ );const label =id === "__none_workspace"? labels.emptyWorkspacediff --git a/src/components/features/conversation-panel/conversation-panel.tsx b/src/components/features/conversation-panel/conversation-panel.tsxindex c3de9420cf..61889311b3 100644--- a/src/components/features/conversation-panel/conversation-panel.tsx+++ b/src/components/features/conversation-panel/conversation-panel.tsx@@ -40,7 +40,9 @@ import {applyGroupFolderOrder,collectAutomationNameFacets,filterOutPinnedConversations,+ getGroupDiscoveryConversationIds,groupConversations,+ MAX_PAGES_PER_LOAD_MORE_CLICK,resolvePinnedConversations,sortConversationsByField,type ConversationGroupLaunch,@@ -300,6 +302,28 @@ export function ConversationPanel({});}, [data]);+ // Grouped pagination is folder-oriented. Record the first backend page for+ // every conversation so later pages can introduce new folders without+ // mutating the contents of folders that are already visible.+ //+ // Known limitation: the mapping is recomputed from `data.pages` on the 10s+ // background refetch, so a conversation whose `updated_at` shifts can move+ // to an earlier page and change its recorded discovery page. The blast+ // radius is only which rows a collapsed preview shows (expanding a folder+ // always reveals every loaded conversation); pinning discovery pages across+ // refetches is not worth the extra bookkeeping today.+ const conversationPageById = React.useMemo(() => {+ const pageById = new Map<string, number>();+ data?.pages.forEach((page, pageIndex) => {+ page.items.forEach((conversation) => {+ if (!pageById.has(conversation.id)) {+ pageById.set(conversation.id, pageIndex);+ }+ });+ });+ return pageById;+ }, [data]);+// Display collection: same loaded pages, with archived rows filtered out// unless the user has opted into "Show archived".const conversations = React.useMemo(() => {@@ -403,32 +427,57 @@ export function ConversationPanel({[t],);- const conversationGroups = React.useMemo(() => {+ const groupedSourceConversations = React.useMemo(() => {if (compact || organizeMode !== "grouped") {return null;}// Use the unsorted partitions: groupConversations sorts each bucket// internally by `sortField`, so pre-sorting the merged input is wasted// work in grouped mode (the per-group sort overrides any global order).- const merged = [- ...recentScoped,- ...(showOlderConversations ? olderScoped : []),- ];+ return [...recentScoped, ...(showOlderConversations ? olderScoped : [])];+ }, [+ compact,+ olderScoped,+ organizeMode,+ recentScoped,+ showOlderConversations,+ ]);++ const conversationGroups = React.useMemo(() => {+ if (!groupedSourceConversations) {+ return null;+ }+ // Keep every loaded conversation in the group model. Folder discovery only+ // freezes the collapsed preview β expanding a folder must reach later-page+ // rows for that same workspace/repo.return groupConversations(- merged,+ groupedSourceConversations,activeBackend.kind,conversationSort,groupLabels,);}, [activeBackend.kind,- compact,conversationSort,groupLabels,- olderScoped,- organizeMode,- recentScoped,- showOlderConversations,+ groupedSourceConversations,+ ]);++ const groupDiscoveryConversationIds = React.useMemo(() => {+ if (!groupedSourceConversations) {+ return null;+ }+ return getGroupDiscoveryConversationIds(+ groupedSourceConversations,+ conversationPageById,+ activeBackend.kind,+ { forceIncludeConversationId: currentConversationId },+ );+ }, [+ activeBackend.kind,+ conversationPageById,+ currentConversationId,+ groupedSourceConversations,]);const orderedConversationGroups = React.useMemo(() => {@@ -472,8 +521,11 @@ export function ConversationPanel({conversations.length > 0 &&automationFilteredConversations.length === 0;- // Number of conversations actually rendered in the list right now, in the- // current organize mode. "Load more" succeeds only when this number grows.+ // Grouped pagination prefers discovering another folder; chronological+ // pagination succeeds when another row appears. Pages that only deepen+ // already-visible folders are not success for the grouped control β the+ // driver walks past them (bounded by the per-click page cap) so a single+ // click can still reach a folder hiding behind deepen-only pages.const visibleCount =organizeMode === "grouped" && !compact? visibleGroupCount@@ -496,18 +548,29 @@ export function ConversationPanel({// two reasons: (1) `fetchNextPage()` is silently dropped while the 10s// background refetch is in flight, and (2) a fetched page can yield zero// *visible* rows (filtered out by the active scope, or deduped as overlap),- // so the list does not appear to grow. We capture the visible count at click- // time and keep fetching pages β once the query is idle β until the visible- // count actually increases or there are no more pages. `loadedPageCount`- // keeps the driver advancing when a grouped page contains only folders that- // were already discovered, leaving every other effect dependency unchanged.+ // so the list does not appear to grow. We capture floors at click time and+ // keep fetching β once idle β until the visible count grows, the grouped+ // per-click page cap is hit, or pages run out. `loadedPageCount` keeps the+ // driver advancing when a fetched page contains only folders that were+ // already discovered.const [loadMoreFloor, setLoadMoreFloor] = React.useState<number | null>(null);+ const [loadMorePageFloor, setLoadMorePageFloor] = React.useState<+ number | null+ >(null);const visibleCountRef = React.useRef(visibleCount);visibleCountRef.current = visibleCount;+ const loadedPageCountRef = React.useRef(loadedPageCount);+ loadedPageCountRef.current = loadedPageCount;++ const clearLoadMoreRequest = React.useCallback(() => {+ setLoadMoreFloor(null);+ setLoadMorePageFloor(null);+ }, []);const requestLoadMore = React.useCallback(() => {if (hasNextPage) {setLoadMoreFloor(visibleCountRef.current);+ setLoadMorePageFloor(loadedPageCountRef.current);}}, [hasNextPage]);@@ -517,7 +580,21 @@ export function ConversationPanel({}// Goal met: the visible list grew past where it was when the user clicked.if (visibleCount > loadMoreFloor) {- setLoadMoreFloor(null);+ clearLoadMoreRequest();+ return;+ }+ // Hard cap (grouped only): pages that merely deepen already-visible+ // folders are walked past β a new folder may sit right behind them β but+ // never unbounded many, so one click cannot drain the whole cursor.+ // Chronological mode keeps its pre-existing behavior: fetch until a+ // visible row appears or pages run out.+ if (+ organizeMode === "grouped" &&+ !compact &&+ loadMorePageFloor != null &&+ loadedPageCount >= loadMorePageFloor + MAX_PAGES_PER_LOAD_MORE_CLICK+ ) {+ clearLoadMoreRequest();return;}// Wait for any in-flight fetch (including the background refetch) to settle@@ -528,14 +605,18 @@ export function ConversationPanel({}// Nothing more to fetch β stop waiting even if the list did not grow.if (!hasNextPage) {- setLoadMoreFloor(null);+ clearLoadMoreRequest();return;}fetchNextPage();}, [+ clearLoadMoreRequest,+ compact,loadMoreFloor,+ loadMorePageFloor,visibleCount,loadedPageCount,+ organizeMode,hasNextPage,isFetching,isFetchingNextPage,@@ -1025,6 +1106,7 @@ export function ConversationPanel({setGroupFolderOrder={setGroupFolderOrder}collapsedGroupIds={collapsedGroupIds}expandedGroupPreviewIds={expandedGroupPreviewIds}+ discoveryConversationIds={groupDiscoveryConversationIds}onToggleGroupCollapsed={toggleGroupCollapsed}onToggleGroupPreviewExpanded={toggleGroupPreviewExpanded}isCreatingConversationFlow={isCreatingConversationFlow}