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
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
fix: Preserve Unread Intent Across Mixed Backend Versions
Lia4bc9c9e5c076
diff --git a/client/src/components/Conversations/__tests__/Convo.status.spec.tsx b/client/src/components/Conversations/__tests__/Convo.status.spec.tsxindex d24dfaca01..f02f4e92e6 100644--- a/client/src/components/Conversations/__tests__/Convo.status.spec.tsx+++ b/client/src/components/Conversations/__tests__/Convo.status.spec.tsx@@ -39,7 +39,10 @@ jest.mock('recoil', () => ({jest.mock('~/store', () => ({__esModule: true,- default: { allConversationsSelector: 'allConversationsSelector' },+ default: {+ allConversationsSelector: 'allConversationsSelector',+ conversationIdByIndex: () => 'conversationIdByIndex',+ },}));jest.mock('~/utils', () => ({diff --git a/client/src/components/Conversations/__tests__/running.spec.ts b/client/src/components/Conversations/__tests__/running.spec.tsindex b226a5a018..228f065390 100644--- a/client/src/components/Conversations/__tests__/running.spec.ts+++ b/client/src/components/Conversations/__tests__/running.spec.ts@@ -1,3 +1,4 @@+import { UNSEEN_REPLY_WATERMARK } from 'librechat-data-provider';import type { TConversation } from 'librechat-data-provider';import type { ConversationGroupOptions } from '~/utils/convos';import {@@ -208,6 +209,7 @@ describe('groupConversationsByStatus finished chats', () => {...convo(conversationId, daysAgo),lastResponseAt: new Date(Date.now() - daysAgo * 86_400_000).toISOString(),isMarkedUnread: false,+ lastSeenAt: UNSEEN_REPLY_WATERMARK,...read,}) as TConversation;@@ -275,6 +277,23 @@ describe('groupConversationsByStatus finished chats', () => {},);+ it('keeps a reminder written by an older replica in its date group', () => {+ const confirmed = replied('mixed-replica', 1);+ expect(partitionGroups([['Today', [confirmed]]], new Set(), newestFirst)[0][0]).toBe(+ FINISHED_CHATS_GROUP,+ );+ const seen = { ...confirmed, lastSeenAt: new Date().toISOString() };+ const unread = { ...seen, lastSeenAt: undefined };+ const restored = JSON.parse(JSON.stringify(unread)) as TConversation;+ expect(restored.isMarkedUnread).toBe(false);+ const dated = groupConversations([restored], newestFirst);+ expect(partitionGroups(dated, new Set(), newestFirst)).toBe(dated);+ const nextReply = { ...restored, lastSeenAt: UNSEEN_REPLY_WATERMARK };+ expect(partitionGroups([['Today', [nextReply]]], new Set(), newestFirst)[0][0]).toBe(+ FINISHED_CHATS_GROUP,+ );+ });+it('shows a new confirmed reply after an unknown legacy reminder', () => {const legacy = replied('legacy', 1, { isMarkedUnread: undefined });const confirmed = replied('confirmed', 0);diff --git a/client/src/components/Conversations/running.ts b/client/src/components/Conversations/running.tsindex f047a0fc44..e0cb265a16 100644--- a/client/src/components/Conversations/running.ts+++ b/client/src/components/Conversations/running.ts@@ -1,3 +1,4 @@+import { UNSEEN_REPLY_WATERMARK } from 'librechat-data-provider';import type { TConversation, GroupedConversations } from 'librechat-data-provider';import type { ConversationGroupOptions } from '~/utils/convos';import { isTemporaryConversation } from '~/utils/conversation';@@ -23,6 +24,7 @@ function showsStatusGroups(options: ConversationGroupOptions): boolean {function isFinishedUnseen(conversation: TConversation): boolean {return (conversation.isMarkedUnread === false &&+ conversation.lastSeenAt === UNSEEN_REPLY_WATERMARK &&conversation.lastResponseIsManual !== true &&isConversationUnseen(conversation));diff --git a/client/src/utils/convos.spec.ts b/client/src/utils/convos.spec.tsindex c0565d59b1..6e8376da00 100644--- a/client/src/utils/convos.spec.ts+++ b/client/src/utils/convos.spec.ts@@ -1,5 +1,5 @@-import { EModelEndpoint } from 'librechat-data-provider';import { QueryClient, InfiniteData } from '@tanstack/react-query';+import { EModelEndpoint, UNSEEN_REPLY_WATERMARK } from 'librechat-data-provider';import type { TConversation } from 'librechat-data-provider';import type { ConversationCursorData } from './convos';import {@@ -1236,6 +1236,7 @@ describe('Conversation Utilities', () => {lastResponseMessageId: 'new',});expect(findConvoInAllQueries(queryClient, 'a')?.isMarkedUnread).toBe(false);+ expect(findConvoInAllQueries(queryClient, 'a')?.lastSeenAt).toBe(UNSEEN_REPLY_WATERMARK);});it('updateConvoInAllQueries lets an explicit lastSeenAt win over the cached one', () => {diff --git a/client/src/utils/convos.ts b/client/src/utils/convos.tsindex c18306a093..e5ead459fd 100644--- a/client/src/utils/convos.ts+++ b/client/src/utils/convos.ts@@ -1,5 +1,5 @@import { QueryClient } from '@tanstack/react-query';-import { LocalStorageKeys, QueryKeys } from 'librechat-data-provider';+import { LocalStorageKeys, QueryKeys, UNSEEN_REPLY_WATERMARK } from 'librechat-data-provider';import {format,isToday,@@ -1213,7 +1213,7 @@ export function completeMessagesReplyFetch(* of the list while this one streamed, so the row is carried to its new position rather than* left at the date and place its run started with.*- * A stamp that genuinely advances also clears the catch-up it outranks, mirroring the write the+ * An advancing stamp resets catch-up to the unseen watermark, mirroring the write the* server made: a cached acknowledgement dated ahead of the new reply, which replica clock skew* can produce, would otherwise classify a reply nobody has read as seen, and the completion* watcher skips its own fetch precisely because this handler already moved the stamp.@@ -1241,7 +1241,7 @@ export function applyServerReplyStamp(lastResponseMessageId: lastResponseMessageId ?? convo.lastResponseMessageId,lastResponseIsManual: undefined,isMarkedUnread: advances ? false : convo.isMarkedUnread,- lastSeenAt: advances ? undefined : convo.lastSeenAt,+ lastSeenAt: advances ? UNSEEN_REPLY_WATERMARK : convo.lastSeenAt,updatedAt: updatedAt ?? convo.updatedAt,}),updatedAt != null && updatedAt > (cached?.updatedAt ?? ''),diff --git a/e2e/specs/mock/bookmarks.spec.ts b/e2e/specs/mock/bookmarks.spec.tsindex eef6cb1192..7bc73be057 100644--- a/e2e/specs/mock/bookmarks.spec.ts+++ b/e2e/specs/mock/bookmarks.spec.ts@@ -1,4 +1,5 @@import { randomUUID } from 'node:crypto';+import { UNSEEN_REPLY_WATERMARK } from 'librechat-data-provider';import { expect, test } from '@playwright/test';import type { Locator, Page } from '@playwright/test';import {@@ -124,7 +125,7 @@ test.describe('bookmark counts', () => {{$set: {lastResponseAt: previous,- lastSeenAt: new Date(previous.getTime() - 1000),+ lastSeenAt: new Date(UNSEEN_REPLY_WATERMARK),isMarkedUnread: false,},},diff --git a/e2e/specs/mock/mcp-apps.spec.ts b/e2e/specs/mock/mcp-apps.spec.tsindex 25e76bd81f..b36ab7bc77 100644--- a/e2e/specs/mock/mcp-apps.spec.ts+++ b/e2e/specs/mock/mcp-apps.spec.ts@@ -684,7 +684,7 @@ test.describe('MCP Apps full integration', () => {(await readEvents(page)).filter((event) => event.method === 'resources/read:show_link_app'),).toHaveLength(1);- const legacyGeneration = await sendMessage(page, `E2E_MCP_LEGACY:${label}`);+ const legacyGeneration = await sendMessageAndWaitForCompletion(page, `E2E_MCP_LEGACY:${label}`);expect(legacyGeneration.ok()).toBeTruthy();const legacyFrameElement = page.locator(`iframe[title="${LEGACY_FRAME_TITLE}"]`);await expect(legacyFrameElement).toHaveCount(1);@@ -692,6 +692,7 @@ test.describe('MCP Apps full integration', () => {await expect(legacyFrame.getByTestId('legacy-status')).toHaveText('legacy-ready');await expect(legacyFrameElement).toHaveCSS('height', '120px');+ await expect(page.getByTestId('stop-generation-button')).toHaveCount(0);const legacyActionGeneration = page.waitForResponse((response) =>response.request().method() === 'POST' &&diff --git a/e2e/specs/mock/scenarios/reply-read-state.spec.ts b/e2e/specs/mock/scenarios/reply-read-state.spec.tsindex b42d2177fc..b177f7c898 100644--- a/e2e/specs/mock/scenarios/reply-read-state.spec.ts+++ b/e2e/specs/mock/scenarios/reply-read-state.spec.ts@@ -1,3 +1,4 @@+import { UNSEEN_REPLY_WATERMARK } from 'librechat-data-provider';import fs from 'node:fs';import { randomUUID } from 'node:crypto';import mongoose from 'mongoose';@@ -177,7 +178,7 @@ test('later visible read wins over a delayed unread response, and stale seen canbody: { arg: { conversationId, lastResponseAt: initialStamp } },});expect(stale.modified).toBe(false);- expect((await readState(conversationId))?.lastSeenAt).toBeUndefined();+ expect((await readState(conversationId))?.lastSeenAt?.toISOString()).toBe(UNSEEN_REPLY_WATERMARK);const read = await requestJson<MutationResult>(page, {path: '/api/convos/seen',token,@@ -266,7 +267,7 @@ test('a hidden sibling reply stays unread until its actual branch is rendered @sawait promise;});expect(seenRequests).toBe(0);- expect((await readState(conversationId))?.lastSeenAt).toBeUndefined();+ expect((await readState(conversationId))?.lastSeenAt?.toISOString()).toBe(UNSEEN_REPLY_WATERMARK);await page.screenshot({ path: testInfo.outputPath('reply-hidden.png') });await visibleRow.hover();diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.tsindex 560e5f3da2..0952704775 100644--- a/packages/data-provider/src/config.ts+++ b/packages/data-provider/src/config.ts@@ -77,6 +77,9 @@ export {MAX_CHAT_PROJECT_INSTRUCTIONS_LENGTH_CEILING,} from './limits';+/** Legacy mark-unread writers remove this catch-up watermark too. */+export const UNSEEN_REPLY_WATERMARK = '1970-01-01T00:00:00.000Z' as const;+export const defaultSocialLogins = ['google', 'facebook', 'openid', 'github', 'discord', 'saml'];export const TWO_FACTOR_ENROLLMENT_REQUIRED_CODE = 'TWO_FACTOR_ENROLLMENT_REQUIRED' as const;diff --git a/packages/data-provider/src/schemas.ts b/packages/data-provider/src/schemas.tsindex 1830da048b..cc2d11e708 100644--- a/packages/data-provider/src/schemas.ts+++ b/packages/data-provider/src/schemas.ts@@ -1257,7 +1257,7 @@ export const tConversationSchema = z.object({lastResponseIsManual: z.boolean().optional(),/** True: manual reminder; false: real reply; absent: legacy/unknown intent. */isMarkedUnread: z.boolean().optional(),- /** Set when the user has the newest message on screen; compared against `lastResponseAt`. */+ /** Read acknowledgement; epoch is the explicit unseen-reply watermark. */lastSeenAt: z.string().optional(),/* Files */resendFiles: z.boolean().optional(),diff --git a/packages/data-schemas/src/methods/conversation.spec.ts b/packages/data-schemas/src/methods/conversation.spec.tsindex 711e152df7..60d3b37f49 100644--- a/packages/data-schemas/src/methods/conversation.spec.ts+++ b/packages/data-schemas/src/methods/conversation.spec.ts@@ -1,7 +1,7 @@import { v4 as uuidv4 } from 'uuid';import mongoose, { type FilterQuery } from 'mongoose';import { MongoMemoryServer } from 'mongodb-memory-server';-import { EModelEndpoint, RetentionMode } from 'librechat-data-provider';+import { EModelEndpoint, RetentionMode, UNSEEN_REPLY_WATERMARK } from 'librechat-data-provider';import type {Document,Filter,@@ -387,7 +387,7 @@ describe('Conversation Operations', () => {});expect(convo?.lastResponseAt).toBeInstanceOf(Date);expect(convo?.lastResponseAt?.getTime()).toBeGreaterThanOrEqual(before.getTime());- expect(convo?.lastSeenAt == null).toBe(true);+ expect(convo?.lastSeenAt?.toISOString()).toBe(UNSEEN_REPLY_WATERMARK);});it('returns the durable conversation when the optional reply stamp fails', async () => {@@ -438,7 +438,7 @@ describe('Conversation Operations', () => {conversationId: mockConversationData.conversationId,});expect(convo?.lastResponseAt?.getTime()).toBeGreaterThan(newer.getTime());- expect(convo?.lastSeenAt).toBeUndefined();+ expect(convo?.lastSeenAt?.toISOString()).toBe(UNSEEN_REPLY_WATERMARK);});it('leaves the reply stamp alone for a save that does not carry one', async () => {@@ -3103,7 +3103,7 @@ describe('Conversation Operations', () => {}).lean<IConversation>();expect(convo?.lastResponseAt).toBeInstanceOf(Date);expect(convo?.lastResponseIsManual).toBeUndefined();- expect(convo?.lastSeenAt == null).toBe(true);+ expect(convo?.lastSeenAt?.toISOString()).toBe(UNSEEN_REPLY_WATERMARK);});it('advances past a future reply stamp when this host clock is behind', async () => {const newer = new Date(Date.now() + 60_000);@@ -3122,7 +3122,7 @@ describe('Conversation Operations', () => {conversationId: mockConversationData.conversationId,}).lean<IConversation>();expect(convo?.lastResponseAt?.getTime()).toBeGreaterThan(newer.getTime());- expect(convo?.lastSeenAt).toBeUndefined();+ expect(convo?.lastSeenAt?.toISOString()).toBe(UNSEEN_REPLY_WATERMARK);});it('does not stamp another user’s conversation', async () => {@@ -3349,6 +3349,44 @@ describe('Conversation Operations', () => {expect(reloaded?.lastResponseMessageId).toBe('confirmed-reply');});+ it('keeps legacy replica seen/unread writes distinguishable after an upgraded reply', async () => {+ await Conversation.create({+ conversationId: mockConversationData.conversationId,+ user: 'user123',+ endpoint: EModelEndpoint.openAI,+ });+ await methods.stampConvoLastResponse(+ 'user123',+ mockConversationData.conversationId,+ 'upgraded-reply',+ );+ let stored = await getConvo('user123', mockConversationData.conversationId);+ expect(stored?.lastSeenAt?.toISOString()).toBe(UNSEEN_REPLY_WATERMARK);+ expect(stored?.isMarkedUnread).toBe(false);+ /* Exact operators used by the pre-upgrade backend. */+ await Conversation.updateOne(+ { conversationId: mockConversationData.conversationId, user: 'user123' },+ { $set: { lastSeenAt: new Date() } },+ { timestamps: false },+ );+ await Conversation.findOneAndUpdate(+ { conversationId: mockConversationData.conversationId, user: 'user123' },+ { $unset: { lastSeenAt: '' } },+ { timestamps: false, new: true },+ );+ const { conversations } = await getConvosByCursor('user123');+ expect(conversations[0].isMarkedUnread).toBe(false);+ expect(conversations[0].lastSeenAt).toBeUndefined();+ await methods.stampConvoLastResponse(+ 'user123',+ mockConversationData.conversationId,+ 'next-upgraded-reply',+ );+ stored = await getConvo('user123', mockConversationData.conversationId);+ expect(stored?.lastSeenAt?.toISOString()).toBe(UNSEEN_REPLY_WATERMARK);+ expect(stored?.lastResponseMessageId).toBe('next-upgraded-reply');+ });+it('is cleared only by an acknowledgement of the current reply', async () => {const responseAt = new Date('2026-08-16T10:00:00.000Z');await Conversation.create({diff --git a/packages/data-schemas/src/methods/conversation.ts b/packages/data-schemas/src/methods/conversation.tsindex f58ea63f50..d151393bee 100644--- a/packages/data-schemas/src/methods/conversation.ts+++ b/packages/data-schemas/src/methods/conversation.ts@@ -1,5 +1,9 @@import { Buffer } from 'node:buffer';-import { RetentionMode, isForcedTemporaryRetention } from 'librechat-data-provider';+import {+ RetentionMode,+ isForcedTemporaryRetention,+ UNSEEN_REPLY_WATERMARK,+} from 'librechat-data-provider';import type {AnyBulkWriteOperation,DeleteResult,@@ -657,8 +661,9 @@ export function createConversationMethods(lastResponseAt: stamp,lastResponseMessageId: responseMessageId,isMarkedUnread: false,+ lastSeenAt: new Date(UNSEEN_REPLY_WATERMARK),},- $unset: { lastSeenAt: '', lastResponseIsManual: '' },+ $unset: { lastResponseIsManual: '' },$max: { updatedAt: stamp },},{ new: true, projection, timestamps: false },@@ -2573,7 +2578,11 @@ export function createConversationMethods(* DocumentDB targets rule out. */if (setFields.lastResponseAt instanceof Date) {const { lastResponseAt, ...withoutReplyStamp } = setFields;- operation.$set = { ...withoutReplyStamp, isMarkedUnread: false };+ operation.$set = {+ ...withoutReplyStamp,+ isMarkedUnread: false,+ lastSeenAt: new Date(UNSEEN_REPLY_WATERMARK),+ };operation.$max = { lastResponseAt };operation.$unset = { lastResponseIsManual: '' };}@@ -2728,7 +2737,7 @@ export function createConversationMethods(}}- /* Advance the version and clear the previous catch-up atomically. The database CAS orders+ /* Advance the version and reset catch-up atomically. The database CAS orders* concurrent replies even when their application hosts disagree about wall-clock time. */let replyStampApplied = false;if (metadata?.stampReply === true) {@@ -2744,6 +2753,7 @@ export function createConversationMethods(lastResponseMessageId: 1,lastResponseIsManual: 1,isMarkedUnread: 1,+ lastSeenAt: 1,updatedAt: 1,},);@@ -2755,7 +2765,7 @@ export function createConversationMethods(conversation.lastResponseMessageId = stamped.conversation.lastResponseMessageId;conversation.lastResponseIsManual = stamped.conversation.lastResponseIsManual;conversation.isMarkedUnread = stamped.conversation.isMarkedUnread;- conversation.lastSeenAt = undefined;+ conversation.lastSeenAt = stamped.conversation.lastSeenAt;if (stamped.conversation.updatedAt) {conversation.updatedAt = stamped.conversation.updatedAt;}diff --git a/packages/data-schemas/src/types/convo.ts b/packages/data-schemas/src/types/convo.tsindex 98d1d5b6df..ed2a5bd713 100644--- a/packages/data-schemas/src/types/convo.ts+++ b/packages/data-schemas/src/types/convo.ts@@ -348,6 +348,6 @@ export interface IConversation extends Document {lastResponseIsManual?: boolean;/** True: manual reminder; false: real reply; absent: legacy/unknown intent. */isMarkedUnread?: boolean;- /** Set when the user has the newest message on screen; compared against `lastResponseAt`. */+ /** Read acknowledgement; epoch is the explicit unseen-reply watermark. */lastSeenAt?: Date;}