🎯 fix: Load Pull Request Status Only for Code Conversations (#16885)

This commit is contained in:
Marco Beretta 2026-10-08 12:21:57 +02:00 • committed by GitHub
parent 85931bece3
commit deb91dfd1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 174 additions and 10 deletions

View file

@ -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')}>

View file

@ -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
);
}

View file

@ -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();
});
});

View file

@ -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);

View file

@ -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();

View file

@ -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);
});
});

View file

@ -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
);
}

View file

@ -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: z

View file

@ -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 = {

View file

@ -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'] }];

View file

@ -3862,7 +3862,7 @@ export function createConversationMethods(
the sidebar lists archived and unarchived chats in the same session, and the
active 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);

View file

@ -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;