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: Load Pull Request Status Only for Code Conversations (#16885)
Marco Berettadeb91dfd1de8
diff --git a/client/src/components/Chat/Header.tsx b/client/src/components/Chat/Header.tsxindex d41a0149a1..795b4ffbb1 100644--- a/client/src/components/Chat/Header.tsx+++ b/client/src/components/Chat/Header.tsx@@ -13,12 +13,14 @@ import { TemporaryChat, TemporaryChatIndicator } from './TemporaryChat';import useDrawerViewport from '~/hooks/Nav/useDrawerViewport';import ModelSelector from './Menus/Endpoints/ModelSelector';import { BackgroundTasksButton } from './BackgroundTasks';+import { isCodeConversation } from './PullRequest/code';import { TraceButton, useTraceControl } from './Trace';import { useGetStartupConfig } from '~/data-provider';import ExportAndShareMenu from './ExportAndShareMenu';import SubagentThreadLink from './SubagentThreadLink';import { PullRequestChip } from './PullRequest';import BookmarkMenu from './Menus/BookmarkMenu';+import { useChatContext } from '~/Providers';import AddMultiConvo from './AddMultiConvo';import { useHasAccess } from '~/hooks';import { cn } from '~/utils';@@ -45,6 +47,14 @@ function Header({* conversation has no id in the route yet, so absence counts as new too. */const { conversationId: routeConversationId } = useParams();const isNewChat = routeConversationId == null || routeConversationId === Constants.NEW_CONVO;+ /** The context conversation can still be the previous chat for a render, so it counts only+ * once it is the routed one. Only a code conversation can have a pull request. */+ const { conversation } = useChatContext();+ const showPullRequest =+ !isNewChat &&+ parentConversationId == null &&+ conversation?.conversationId === routeConversationId &&+ isCodeConversation(conversation);const interfaceConfig = useMemo(() => startupConfig?.interface ?? defaultInterface,@@ -115,7 +125,7 @@ function Header({)}{/* Desktop only: its details open to the right, into the room this cluster leaves free.Small screens reach the same card from the overflow menu. */}- {!isSmallScreen && !isNewChat && parentConversationId == null && (+ {!isSmallScreen && showPullRequest && (<PullRequestChip key={`pr-${routeConversationId}`} conversationId={routeConversationId} />)}</div>@@ -134,9 +144,7 @@ function Header({startupConfig={startupConfig}trace={trace}readOnly={readOnly}- pullRequestConversationId={- isNewChat || parentConversationId != null ? undefined : routeConversationId- }+ pullRequestConversationId={showPullRequest ? routeConversationId : undefined}className={isSmallScreen ? undefined : 'hidden'}/><div className={cn('items-center gap-2', isSmallScreen ? 'hidden' : 'flex')}>diff --git a/client/src/components/Chat/PullRequest/code.ts b/client/src/components/Chat/PullRequest/code.tsnew file mode 100644index 0000000000..4bcef64c05--- /dev/null+++ b/client/src/components/Chat/PullRequest/code.ts@@ -0,0 +1,16 @@+import type { TConversation } from 'librechat-data-provider';++/**+ * Only a conversation that ran against an attached code workspace can have a pull request: the+ * workspace is what reports the branch. Everything else never asks, so ordinary chats cost no+ * lookups and show no pull request state at all.+ */+export function isCodeConversation(+ conversation: Pick<TConversation, 'codeEnvironmentMode' | 'codeWorkspaces'> | null | undefined,+): boolean {+ if (conversation == null) return false;+ return (+ conversation.codeEnvironmentMode === 'attached' ||+ (conversation.codeWorkspaces?.length ?? 0) > 0+ );+}diff --git a/client/src/components/Chat/__tests__/Header.stacking.spec.tsx b/client/src/components/Chat/__tests__/Header.stacking.spec.tsxindex af37499485..220f1139db 100644--- a/client/src/components/Chat/__tests__/Header.stacking.spec.tsx+++ b/client/src/components/Chat/__tests__/Header.stacking.spec.tsx@@ -5,6 +5,14 @@ import Header from '../Header';const mockEndpoint = { current: 'agents' };const mockSmallScreen = { current: false };+const codeConversation = {+ conversationId: 'convo-1',+ codeEnvironmentMode: 'attached',+ codeWorkspaces: [{ environmentId: 'env', workspaceId: 'ws' }],+};+const mockConversation: { current: Record<string, unknown> | null } = {+ current: codeConversation,+};jest.mock('react-router-dom', () => ({useParams: () => ({ conversationId: 'convo-1' }),@@ -24,6 +32,9 @@ jest.mock('librechat-data-provider', () => ({}));jest.mock('~/data-provider', () => ({ useGetStartupConfig: () => ({ data: undefined }) }));jest.mock('~/hooks', () => ({ useHasAccess: () => false }));+jest.mock('~/Providers', () => ({+ useChatContext: () => ({ conversation: mockConversation.current }),+}));jest.mock('~/hooks/Nav/useDrawerViewport', () => () => mockSmallScreen.current);jest.mock('~/store', () => ({__esModule: true,@@ -71,6 +82,7 @@ describe('Header stacking', () => {headerMenu.mockClear();mockEndpoint.current = 'agents';mockSmallScreen.current = false;+ mockConversation.current = codeConversation;});test('keeps header controls above the z-10 composer approval review', () => {@@ -121,4 +133,26 @@ describe('Header stacking', () => {render(<Header parentConversationId="parent" />);expect(headerMenu.mock.calls[0][0].pullRequestConversationId).toBeUndefined();});++ test('does not mount the pull request chip for an ordinary conversation', () => {+ mockConversation.current = { conversationId: 'convo-1' };+ render(<Header />);+ expect(pullRequestChip).not.toHaveBeenCalled();+ });++ test('does not mount the chip while the context still holds the previous chat', () => {+ mockConversation.current = { ...codeConversation, conversationId: 'other' };+ render(<Header />);+ expect(pullRequestChip).not.toHaveBeenCalled();+ });++ test('offers the overflow menu no pull request for an ordinary conversation', () => {+ mockSmallScreen.current = true;+ mockConversation.current = {+ conversationId: 'convo-1',+ codeEnvironmentMode: 'without_attached',+ };+ render(<Header />);+ expect(headerMenu.mock.calls[0][0].pullRequestConversationId).toBeUndefined();+ });});diff --git a/client/src/components/Conversations/Convo.tsx b/client/src/components/Conversations/Convo.tsxindex 0276748919..72a6fa0c7f 100644--- a/client/src/components/Conversations/Convo.tsx+++ b/client/src/components/Conversations/Convo.tsx@@ -17,6 +17,7 @@ import {useUpdateConversationMutation,} from '~/data-provider';import { cn, logger, setDocumentTitle, isConversationUnseen, hasRealTitle } from '~/utils';+import { isCodeConversation } from '~/components/Chat/PullRequest/code';import PullRequestRowMark from '~/components/Chat/PullRequest/RowMark';import { useNavigateToConvo, useLocalize, useShiftKey } from '~/hooks';import ConversationEndpointIcon from './ConversationEndpointIcon';@@ -81,6 +82,10 @@ function Conversation({const showPullRequest =startupConfig?.pullRequestsEnabled === true &&startupConfig.pullRequestsBatchVersion === PULL_REQUEST_BATCH_VERSION &&+ /* A row the listing replica stamped carries its code decision, so only code conversations+ ask. One without the stamp (an older replica, a row inserted from the cache) cannot be+ told apart from an ordinary chat and keeps asking, as before. */+ (conversation.codeDecisionListed !== true || isCodeConversation(conversation)) &&!isGenerating;const projectBadgeProjectId = showProjectBadge ? conversation.chatProjectId : undefined;const isUnseen = isConversationUnseen(conversation);diff --git a/client/src/components/Conversations/__tests__/Convo.pullRequest.spec.tsx b/client/src/components/Conversations/__tests__/Convo.pullRequest.spec.tsxindex fde5eb708d..731f762dad 100644--- a/client/src/components/Conversations/__tests__/Convo.pullRequest.spec.tsx+++ b/client/src/components/Conversations/__tests__/Convo.pullRequest.spec.tsx@@ -5,7 +5,10 @@ import { render, screen } from '@testing-library/react';import type { TConversation } from 'librechat-data-provider';const mockStartup: {- current: { pullRequestsEnabled?: boolean; pullRequestsBatchVersion?: number };+ current: {+ pullRequestsEnabled?: boolean;+ pullRequestsBatchVersion?: number;+ };} = {current: { pullRequestsEnabled: true, pullRequestsBatchVersion: 1 },};@@ -86,13 +89,21 @@ import Conversation from '../Convo';const conversation = {conversationId: 'convo-1',title: 'Tool Approval UI',+ codeDecisionListed: true,+ codeEnvironmentMode: 'attached',+ codeWorkspaces: [{ environmentId: 'env', workspaceId: 'ws' }],+} as TConversation;+const ordinary = {+ conversationId: 'convo-1',+ title: 'Tool Approval UI',+ codeDecisionListed: true,} as TConversation;-const renderRow = (props: { isGenerating?: boolean } = {}) =>+const renderRow = (props: { isGenerating?: boolean; convo?: TConversation } = {}) =>render(<DndProvider backend={HTML5Backend}><Conversation- conversation={conversation}+ conversation={props.convo ?? conversation}retainView={jest.fn()}toggleNav={jest.fn()}isGenerating={props.isGenerating}@@ -106,7 +117,10 @@ describe('Conversation row pull request', () => {beforeEach(() => {mockMarkProps.length = 0;mockMarkState.described = true;- mockStartup.current = { pullRequestsEnabled: true, pullRequestsBatchVersion: 1 };+ mockStartup.current = {+ pullRequestsEnabled: true,+ pullRequestsBatchVersion: 1,+ };});it("keeps the title the conversation's own and puts the pull request beside it, outside the row button", () => {@@ -168,6 +182,24 @@ describe('Conversation row pull request', () => {expect(rowButton().getAttribute('aria-describedby')).toBeNull();});+ it.each([+ ['has no code decision', ordinary],+ [+ 'runs without an attached workspace',+ { ...ordinary, codeEnvironmentMode: 'without_attached' },+ ],+ ])('never asks for a chat that %s, so ordinary chats cost no lookup', (_label, convo) => {+ renderRow({ convo: convo as TConversation });+ expect(screen.queryByTestId('convo-pull-request')).not.toBeInTheDocument();+ expect(mockMarkProps).toHaveLength(0);+ expect(rowButton().getAttribute('aria-describedby')).toBeNull();+ });++ it('keeps asking for a row its replica did not stamp, since it cannot be told from an ordinary chat', () => {+ renderRow({ convo: { ...ordinary, codeDecisionListed: undefined } as TConversation });+ expect(screen.getByTestId('convo-pull-request')).toBeInTheDocument();+ });+it('leaves the mark out while the chat runs, so the ring is the only status', () => {renderRow({ isGenerating: true });expect(screen.queryByTestId('convo-pull-request')).not.toBeInTheDocument();diff --git a/client/src/components/Conversations/__tests__/sharedBadge.test.ts b/client/src/components/Conversations/__tests__/sharedBadge.test.tsindex af0ed3ddce..dae6bea423 100644--- a/client/src/components/Conversations/__tests__/sharedBadge.test.ts+++ b/client/src/components/Conversations/__tests__/sharedBadge.test.ts@@ -29,4 +29,34 @@ describe('conversation list memoization of the shared badge', () => {expect(areConversationListItemFieldsEqual(first, second)).toBe(true);});++ it('treats a workspace detach as a re-render, since the row decides its pull request mark from it', () => {+ const attached = {+ ...baseConversation,+ codeEnvironmentMode: 'attached',+ codeWorkspaces: [{ environmentId: 'env', workspaceId: 'ws' }],+ } as TConversation;+ const detached = {+ ...baseConversation,+ codeEnvironmentMode: 'without_attached',+ } as TConversation;++ expect(areConversationListItemFieldsEqual(attached, detached)).toBe(false);+ });++ it('treats a newly attached workspace as a re-render', () => {+ const attached = {+ ...baseConversation,+ codeEnvironmentMode: 'attached',+ codeWorkspaces: [{ environmentId: 'env', workspaceId: 'ws' }],+ } as TConversation;++ expect(areConversationListItemFieldsEqual(baseConversation, attached)).toBe(false);+ });++ it('treats the listing replica stamping the decision as a re-render', () => {+ const stamped = { ...baseConversation, codeDecisionListed: true } as TConversation;++ expect(areConversationListItemFieldsEqual(baseConversation, stamped)).toBe(false);+ });});diff --git a/client/src/components/Conversations/utils.ts b/client/src/components/Conversations/utils.tsindex e9c2dd69a7..502f2e81c4 100644--- a/client/src/components/Conversations/utils.ts+++ b/client/src/components/Conversations/utils.ts@@ -45,7 +45,12 @@ export function areConversationListItemFieldsEqual(prevConversation.lastResponseAt === nextConversation.lastResponseAt &&prevConversation.lastResponseIsManual === nextConversation.lastResponseIsManual &&prevConversation.isMarkedUnread === nextConversation.isMarkedUnread &&- prevConversation.lastSeenAt === nextConversation.lastSeenAt+ prevConversation.lastSeenAt === nextConversation.lastSeenAt &&+ /* Attaching or detaching a workspace changes nothing else on the row, but it decides whether+ the row asks for a pull request, so it has to reach the render. */+ prevConversation.codeDecisionListed === nextConversation.codeDecisionListed &&+ prevConversation.codeEnvironmentMode === nextConversation.codeEnvironmentMode &&+ prevConversation.codeWorkspaces?.length === nextConversation.codeWorkspaces?.length);}diff --git a/packages/data-provider/src/schemas.ts b/packages/data-provider/src/schemas.tsindex 375de52efa..8a45898068 100644--- a/packages/data-provider/src/schemas.ts+++ b/packages/data-provider/src/schemas.ts@@ -1195,6 +1195,8 @@ export const tConversationSchema = z.object({pinned: z.boolean().optional(),/** Server-derived: an active shared link exists for this conversation. Not persisted. */isShared: z.boolean().optional(),+ /** Server-derived on list rows: the listing replica returned the code decision. Not persisted. */+ codeDecisionListed: z.boolean().optional(),codeApprovalMode: z.enum(CODE_APPROVAL_MODES).optional(),codeEnvironmentMode: z.enum(CODE_ENVIRONMENT_MODES).optional(),codeWorkspaces: zdiff --git a/packages/data-provider/src/types/queries.ts b/packages/data-provider/src/types/queries.tsindex c46750374a..ac7947800e 100644--- a/packages/data-provider/src/types/queries.ts+++ b/packages/data-provider/src/types/queries.ts@@ -57,6 +57,10 @@ export type MinimalConversation = Pick<| 'lastResponseIsManual'| 'isMarkedUnread'| 'lastSeenAt'+ /** Lets a row tell a code conversation, the only kind that can have a pull request. */+ | 'codeEnvironmentMode'+ | 'codeWorkspaces'+ | 'codeDecisionListed'>;export type ConversationListResponse = {diff --git a/packages/data-schemas/src/methods/conversation.spec.ts b/packages/data-schemas/src/methods/conversation.spec.tsindex ee5a4edeae..b1241e93ee 100644--- a/packages/data-schemas/src/methods/conversation.spec.ts+++ b/packages/data-schemas/src/methods/conversation.spec.ts@@ -1493,6 +1493,25 @@ describe('Conversation Operations', () => {},);+ it('lists the code decision, so a row can tell a code conversation from an ordinary one', async () => {+ const conversationId = uuidv4();+ const plainId = uuidv4();+ const codeWorkspaces = [mac];+ await saveConvo(+ { userId },+ { conversationId, codeEnvironmentMode: 'attached', codeWorkspaces },+ );+ await saveConvo({ userId }, { conversationId: plainId });+ const { conversations } = await getConvosByCursor(userId);+ expect(conversations.find((row) => row.conversationId === conversationId)).toEqual(+ expect.objectContaining({ codeEnvironmentMode: 'attached', codeWorkspaces }),+ );+ expect(conversations.find((row) => row.conversationId === plainId)).not.toHaveProperty(+ 'codeEnvironmentMode',+ );+ expect(conversations.every((row) => row.codeDecisionListed === true)).toBe(true);+ });+it('preserves explicit agent ownership through save, reload and a stale ordinary save', async () => {const conversationId = uuidv4();const codeWorkspaces = [{ ...mac, agentIds: ['primary', 'reviewer'] }];diff --git a/packages/data-schemas/src/methods/conversation.ts b/packages/data-schemas/src/methods/conversation.tsindex 0bfbcf7928..107b7e0211 100644--- a/packages/data-schemas/src/methods/conversation.ts+++ b/packages/data-schemas/src/methods/conversation.ts@@ -3862,7 +3862,7 @@ export function createConversationMethods(the sidebar lists archived and unarchived chats in the same session, and theactive list also carries the unarchived pins beside them. */.select(- 'conversationId endpoint title titleSetByUser titleRevision createdAt updatedAt archivedAt isArchived user model agent_id assistant_id spec iconURL chatProjectId pinned lastResponseAt lastResponseMessageId lastResponseIsManual isMarkedUnread lastSeenAt',+ 'conversationId endpoint title titleSetByUser titleRevision createdAt updatedAt archivedAt isArchived user model agent_id assistant_id spec iconURL chatProjectId pinned lastResponseAt lastResponseMessageId lastResponseIsManual isMarkedUnread lastSeenAt codeEnvironmentMode codeWorkspaces',).sort(sortObj).limit(pageSize + 1)@@ -3900,6 +3900,12 @@ export function createConversationMethods(nextCursor = Buffer.from(JSON.stringify(composite)).toString('base64');}+ /* Stamped by the replica that selected the decision, so a row from one that predates it+ is told apart from an ordinary chat, which carries no decision either. */+ for (const convo of convos) {+ convo.codeDecisionListed = true;+ }+if (sharedIds != null) {for (const convo of convos) {convo.isShared = sharedIds.has(convo.conversationId);diff --git a/packages/data-schemas/src/types/convo.ts b/packages/data-schemas/src/types/convo.tsindex fe0d4938c4..6279fd0c59 100644--- a/packages/data-schemas/src/types/convo.ts+++ b/packages/data-schemas/src/types/convo.ts@@ -334,6 +334,9 @@ export interface IConversation extends Document {pinned?: boolean;/** Derived per request from the shared-links collection; never persisted on the conversation. */isShared?: boolean;+ /** Derived per list request: this replica listed the row's code decision, so an absent decision+ * means an ordinary chat rather than a server that does not say. Never persisted. */+ codeDecisionListed?: boolean;iconURL?: string;greeting?: string;spec?: string;