Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🪁 fix: Prioritize Running Chats in Sidebar History (#16406)

lia-by-librechat[bot]26d5d0176769
diff --git a/client/src/components/Conversations/Conversations.tsx b/client/src/components/Conversations/Conversations.tsx
index f8fc368a5f..dae11862ef 100644
--- a/client/src/components/Conversations/Conversations.tsx
+++ b/client/src/components/Conversations/Conversations.tsx
@@ -25,6 +25,7 @@ import {
useUnpinDroppedConversation,
} from './dnd';
import { useLocalize, TranslationKeys, useElementSize, useOuterScrollWindow } from '~/hooks';
+import { groupConversationsWithRunning, RUNNING_CHATS_GROUP } from './running';
import { groupConversations, cn } from '~/utils';
import { useActiveJobs } from '~/data-provider';
import Convo from './Convo';
@@ -159,10 +160,14 @@ const DateLabel: FC<{ groupName: string; isFirst?: boolean; isAlphabetical?: boo
const displayName = localize(groupName as TranslationKeys) || groupName;
return (
<h2
- aria-label={localize(
- isAlphabetical ? 'com_a11y_chats_alpha_section' : 'com_a11y_chats_date_section',
- isAlphabetical ? { letter: displayName } : { date: displayName },
- )}
+ aria-label={
+ groupName === RUNNING_CHATS_GROUP
+ ? localize('com_a11y_chats_running_section')
+ : localize(
+ isAlphabetical ? 'com_a11y_chats_alpha_section' : 'com_a11y_chats_date_section',
+ isAlphabetical ? { letter: displayName } : { date: displayName },
+ )
+ }
className={cn('pl-1 pt-1 text-text-secondary', isFirst === true ? 'mt-0' : 'mt-2')}
style={{ fontSize: '0.7rem' }}
>
@@ -262,10 +267,17 @@ const Conversations: FC<ConversationsProps> = ({
// Fetch active job IDs for showing generation indicators
const { data: activeJobsData } = useActiveJobs();
- const activeJobIds = useMemo(
- () => new Set(activeJobsData?.activeJobIds ?? []),
- [activeJobsData?.activeJobIds],
- );
+ const activeJobIdsRef = useRef<Set<string> | null>(null);
+ const activeJobIds = useMemo(() => {
+ const ids = activeJobsData?.activeJobIds ?? [];
+ const next = new Set(ids);
+ const previous = activeJobIdsRef.current;
+ if (previous && next.size === previous.size && ids.every((id) => previous.has(id))) {
+ return previous;
+ }
+ activeJobIdsRef.current = next;
+ return next;
+ }, [activeJobsData?.activeJobIds]);
const filteredConversations = useMemo(
() => rawConversations.filter(Boolean) as TConversation[],
@@ -275,7 +287,7 @@ const Conversations: FC<ConversationsProps> = ({
/** The pinned section above carries pins, so they stay out of these groups — except in
* the archive, which that section does not cover: an archived pin would otherwise be
* absent from the sidebar entirely rather than merely further down it. */
- const groupedConversations = useMemo(
+ const datedConversations = useMemo(
() =>
groupConversations(filteredConversations, {
field: sort.field,
@@ -284,6 +296,15 @@ const Conversations: FC<ConversationsProps> = ({
}),
[filteredConversations, isArchivedView, sort.direction, sort.field],
);
+ const groupedConversations = useMemo(
+ () =>
+ groupConversationsWithRunning(datedConversations, activeJobIds, {
+ field: sort.field,
+ direction: sort.direction,
+ includePinned: isArchivedView,
+ }),
+ [datedConversations, activeJobIds, isArchivedView, sort.direction, sort.field],
+ );
/* Pins are stripped from the date groups. An all-pin page leaves the
virtual list with no rows, so onRowsRendered never fires and later
diff --git a/client/src/components/Conversations/__tests__/Conversations.test.tsx b/client/src/components/Conversations/__tests__/Conversations.test.tsx
index fe196f84d2..5916901cea 100644
--- a/client/src/components/Conversations/__tests__/Conversations.test.tsx
+++ b/client/src/components/Conversations/__tests__/Conversations.test.tsx
@@ -13,6 +13,7 @@ import store from '~/store';
/* The section resolves a conversation's project from the query cache, so the
* tree needs a client even though the data hooks themselves are mocked. */
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+let mockActiveJobIds: string[] = [];
jest.mock('react-virtualized', () => {
const actual = jest.requireActual('react-virtualized');
@@ -80,19 +81,21 @@ jest.mock('@librechat/client', () => ({
}));
jest.mock('~/data-provider', () => ({
- useActiveJobs: () => ({ data: undefined }),
+ useActiveJobs: () => ({ data: { activeJobIds: mockActiveJobIds } }),
useAssignConversationToProjectMutation: () => ({ mutate: jest.fn() }),
usePinConversationMutation: () => ({ mutate: jest.fn() }),
}));
jest.mock('~/utils', () => ({
- groupConversations: () => [],
+ groupConversations: jest.fn(jest.requireActual('~/utils/convos').groupConversations),
cn: (...args: unknown[]) => args.filter(Boolean).join(' '),
}));
jest.mock('../Convo', () => ({
__esModule: true,
- default: () => <div data-testid="convo" />,
+ default: ({ conversation }: { conversation: TConversation }) => (
+ <div data-testid="convo">{conversation.title}</div>
+ ),
}));
const pinnedConvo = {
@@ -104,6 +107,77 @@ const pinnedConvo = {
updatedAt: new Date().toISOString(),
} as TConversation;
+describe('Conversations: live running order', () => {
+ const containerRef = createRef<List>();
+ const newer = {
+ conversationId: 'newer',
+ title: 'Newer idle chat',
+ createdAt: '2026-09-26T00:00:00.000Z',
+ updatedAt: '2026-09-26T00:00:00.000Z',
+ } as TConversation;
+ const running = {
+ conversationId: 'running',
+ title: 'Older running chat',
+ createdAt: '2026-08-01T00:00:00.000Z',
+ updatedAt: '2026-08-01T00:00:00.000Z',
+ } as TConversation;
+
+ afterEach(() => {
+ mockActiveJobIds = [];
+ });
+
+ it('promotes and restores a chat without changing its paged input', () => {
+ const conversations = [newer, running];
+ const renderList = () => (
+ <QueryClientProvider client={queryClient}>
+ <DndProvider backend={HTML5Backend}>
+ <RecoilRoot>
+ <Conversations
+ conversations={conversations}
+ moveToTop={jest.fn()}
+ toggleNav={jest.fn()}
+ containerRef={containerRef}
+ loadMoreConversations={jest.fn()}
+ isLoading={false}
+ isSearchLoading={false}
+ isChatsExpanded={true}
+ setIsChatsExpanded={jest.fn()}
+ scrollViewport={null}
+ scrollContent={null}
+ />
+ </RecoilRoot>
+ </DndProvider>
+ </QueryClientProvider>
+ );
+ const rowOrder = () => screen.getAllByTestId('convo').map((row) => row.textContent);
+
+ const view = render(renderList());
+ const groupConversationsMock = jest.requireMock('~/utils').groupConversations as jest.Mock;
+ groupConversationsMock.mockClear();
+ expect(rowOrder()).toEqual(['Newer idle chat', 'Older running chat']);
+ expect(screen.queryByRole('heading', { name: 'com_a11y_chats_running_section' })).toBeNull();
+
+ mockActiveJobIds = ['running'];
+ view.rerender(renderList());
+ expect(
+ screen.getByRole('heading', { name: 'com_a11y_chats_running_section' }),
+ ).toBeInTheDocument();
+ expect(rowOrder()).toEqual(['Older running chat', 'Newer idle chat']);
+ expect(groupConversationsMock).not.toHaveBeenCalled();
+
+ mockActiveJobIds = ['running'];
+ view.rerender(renderList());
+ expect(groupConversationsMock).not.toHaveBeenCalled();
+ expect(rowOrder()).toEqual(['Older running chat', 'Newer idle chat']);
+
+ mockActiveJobIds = [];
+ view.rerender(renderList());
+ expect(screen.queryByRole('heading', { name: 'com_a11y_chats_running_section' })).toBeNull();
+ expect(rowOrder()).toEqual(['Newer idle chat', 'Older running chat']);
+ expect(conversations).toEqual([newer, running]);
+ });
+});
+
describe('Conversations: pinned chats live in PinnedSection', () => {
const containerRef = createRef<List>();
diff --git a/client/src/components/Conversations/__tests__/DateLabel.test.tsx b/client/src/components/Conversations/__tests__/DateLabel.test.tsx
index fc5fdb80a5..92857dc8a1 100644
--- a/client/src/components/Conversations/__tests__/DateLabel.test.tsx
+++ b/client/src/components/Conversations/__tests__/DateLabel.test.tsx
@@ -8,6 +8,8 @@ jest.mock('~/hooks', () => ({
const translations: Record<string, string> = {
com_a11y_chats_date_section: `Chats from ${params?.date ?? ''}`,
com_a11y_chats_alpha_section: `Chats with titles starting with ${params?.letter ?? ''}`,
+ com_a11y_chats_running_section: 'Running chats',
+ com_ui_running_chats: 'Running',
com_ui_date_today: 'Today',
com_ui_date_yesterday: 'Yesterday',
com_ui_date_previous_7_days: 'Previous 7 days',
@@ -22,6 +24,13 @@ describe('DateLabel', () => {
expect(screen.getByRole('heading', { level: 2, name: 'Chats from Today' })).toBeInTheDocument();
});
+ it('announces the running group without describing it as a date', () => {
+ render(<DateLabel groupName="com_ui_running_chats" />);
+ expect(screen.getByRole('heading', { level: 2, name: 'Running chats' })).toHaveTextContent(
+ 'Running',
+ );
+ });
+
it('uses the alphabetical accessible name for title groups', () => {
render(<DateLabel groupName="A" isAlphabetical />);
expect(
diff --git a/client/src/components/Conversations/__tests__/running.spec.ts b/client/src/components/Conversations/__tests__/running.spec.ts
new file mode 100644
index 0000000000..42996ed427
--- /dev/null
+++ b/client/src/components/Conversations/__tests__/running.spec.ts
@@ -0,0 +1,91 @@
+import type { TConversation } from 'librechat-data-provider';
+import type { ConversationGroupOptions } from '~/utils/convos';
+import { groupConversationsWithRunning as partitionGroups, RUNNING_CHATS_GROUP } from '../running';
+import { groupConversations } from '~/utils/convos';
+
+const convo = (conversationId: string, daysAgo: number, pinned = false): TConversation =>
+ ({
+ conversationId,
+ title: conversationId,
+ updatedAt: new Date(Date.now() - daysAgo * 86_400_000).toISOString(),
+ createdAt: new Date(Date.now() - 90 * 86_400_000).toISOString(),
+ pinned,
+ }) as TConversation;
+
+const ids = (groups: ReturnType<typeof groupConversations>) =>
+ groups.flatMap(([, conversations]) => conversations.map((c) => c.conversationId));
+
+const newestFirst = { field: 'updatedAt' as const, direction: 'desc' as const };
+const groupConversationsWithRunning = (
+ conversations: TConversation[],
+ activeJobIds: ReadonlySet<string>,
+ options: ConversationGroupOptions,
+) => partitionGroups(groupConversations(conversations, options), activeJobIds, options);
+
+describe('groupConversationsWithRunning', () => {
+ it('returns the same date groups when the polled jobs do not affect loaded rows', () => {
+ const dated = groupConversations([convo('idle', 1)], newestFirst);
+ expect(partitionGroups(dated, new Set(), newestFirst)).toBe(dated);
+ expect(partitionGroups(dated, new Set(['not-loaded']), newestFirst)).toBe(dated);
+ });
+ it('lifts loaded running chats above newer idle chats without changing the server rows', () => {
+ const newer = convo('newer', 0);
+ const running = convo('running', 45);
+ const older = convo('older', 60);
+ const conversations = [newer, running, older];
+ const snapshot = JSON.stringify(conversations);
+
+ const groups = groupConversationsWithRunning(
+ conversations,
+ new Set(['running', 'not-loaded']),
+ newestFirst,
+ );
+
+ expect(groups[0]).toEqual([RUNNING_CHATS_GROUP, [running]]);
+ expect(ids(groups)).toEqual(['running', 'newer', 'older']);
+ expect(JSON.stringify(conversations)).toBe(snapshot);
+ });
+
+ it('keeps multiple running chats in their fetched order and deduplicates overlapping pages', () => {
+ const older = convo('older', 70);
+ const recent = convo('recent', 2);
+ const pinned = convo('pinned', 1, true);
+ const groups = groupConversationsWithRunning(
+ [recent, pinned, older, recent, older],
+ new Set(['older', 'recent', 'pinned']),
+ newestFirst,
+ );
+
+ expect(groups).toEqual([[RUNNING_CHATS_GROUP, [recent, older]]]);
+ expect(ids(groups)).toEqual(['recent', 'older']);
+ });
+
+ it('restores date grouping as soon as a run finishes', () => {
+ const conversations = [convo('newer', 0), convo('running', 50)];
+ const running = groupConversationsWithRunning(conversations, new Set(['running']), newestFirst);
+ const finished = groupConversationsWithRunning(conversations, new Set(), newestFirst);
+
+ expect(running[0][0]).toBe(RUNNING_CHATS_GROUP);
+ expect(finished).toEqual(groupConversations(conversations, newestFirst));
+ expect(ids(finished)).toEqual(['newer', 'running']);
+ });
+
+ it.each([
+ { field: 'updatedAt' as const, direction: 'asc' as const },
+ { field: 'createdAt' as const, direction: 'desc' as const },
+ { field: 'title' as const, direction: 'asc' as const },
+ ])('respects the explicit $field $direction sort', (options) => {
+ const conversations = [convo('newer', 0), convo('running', 50)];
+ expect(groupConversationsWithRunning(conversations, new Set(['running']), options)).toEqual(
+ groupConversations(conversations, options),
+ );
+ });
+
+ it('keeps archive grouping untouched, including archived pinned rows', () => {
+ const conversations = [convo('newer', 0), convo('pinned', 50, true)];
+ const options = { ...newestFirst, includePinned: true };
+ expect(groupConversationsWithRunning(conversations, new Set(['pinned']), options)).toEqual(
+ groupConversations(conversations, options),
+ );
+ });
+});
diff --git a/client/src/components/Conversations/running.ts b/client/src/components/Conversations/running.ts
new file mode 100644
index 0000000000..9d874ec771
--- /dev/null
+++ b/client/src/components/Conversations/running.ts
@@ -0,0 +1,39 @@
+import type { TConversation, GroupedConversations } from 'librechat-data-provider';
+import type { ConversationGroupOptions } from '~/utils/convos';
+
+export const RUNNING_CHATS_GROUP = 'com_ui_running_chats';
+
+/** Partition the existing server-ordered groups without re-sorting them on every job update. */
+export function groupConversationsWithRunning(
+ groups: GroupedConversations,
+ activeJobIds: ReadonlySet<string>,
+ options: ConversationGroupOptions,
+): GroupedConversations {
+ if (
+ options.includePinned ||
+ options.field !== 'updatedAt' ||
+ options.direction !== 'desc' ||
+ activeJobIds.size === 0
+ ) {
+ return groups;
+ }
+
+ const running: TConversation[] = [];
+ const remaining: GroupedConversations = [];
+ for (const [groupName, conversations] of groups) {
+ const idle: TConversation[] = [];
+ for (const conversation of conversations) {
+ const id = conversation.conversationId;
+ if (id && activeJobIds.has(id)) {
+ running.push(conversation);
+ } else {
+ idle.push(conversation);
+ }
+ }
+ if (idle.length > 0) {
+ remaining.push([groupName, idle]);
+ }
+ }
+
+ return running.length === 0 ? groups : [[RUNNING_CHATS_GROUP, running], ...remaining];
+}
diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.json
index 2e17759197..a8cc3a24e3 100644
--- a/client/src/locales/en/translation.json
+++ b/client/src/locales/en/translation.json
@@ -92,6 +92,7 @@
"com_a11y_ai_composing": "The AI is still composing.",
"com_a11y_chats_date_section": "Chats from {{date}}",
"com_a11y_chats_alpha_section": "Chats with titles starting with {{letter}}",
+ "com_a11y_chats_running_section": "Running chats",
"com_a11y_end": "The AI has finished their reply.",
"com_a11y_selected": "selected",
"com_a11y_start": "The AI has started their reply.",
@@ -2126,6 +2127,7 @@
"com_ui_run_code": "Run Code",
"com_ui_run_code_error": "There was an error running the code",
"com_ui_running": "Running...",
+ "com_ui_running_chats": "Running",
"com_ui_running_command": "Running command",
"com_ui_running_n_actions": "Running {{0}} actions",
"com_ui_running_n_agents": "Running {{0}} agents",