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: Keep Manual Compactions on the Active Branch (#16386)

lia-by-librechat[bot]84e3ea9ed99d
diff --git a/client/src/hooks/SSE/__tests__/useStepHandler.spec.ts b/client/src/hooks/SSE/__tests__/useStepHandler.spec.ts
index 4a712d1095..1d9f2de926 100644
--- a/client/src/hooks/SSE/__tests__/useStepHandler.spec.ts
+++ b/client/src/hooks/SSE/__tests__/useStepHandler.spec.ts
@@ -50,6 +50,7 @@ type TSubmissionForTest = {
isTemporary: boolean;
messages: TMessage[];
isRegenerate?: boolean;
+ compact?: boolean;
conversation: Partial<TConversation>;
endpointOption: TEndpointOption;
initialResponse: TMessage;
@@ -212,6 +213,40 @@ describe('useStepHandler', () => {
);
});
+ it('keeps an assistant compaction anchor when the response receives its durable ID', () => {
+ const userMessage = createUserMessage();
+ const anchor = createResponseMessage({ messageId: 'anchor-response' });
+ const initialResponse = createResponseMessage({
+ messageId: 'anchor-response_',
+ parentMessageId: anchor.messageId,
+ });
+ const submission = createSubmission({
+ userMessage: { ...anchor, text: '' },
+ messages: [userMessage, anchor],
+ initialResponse,
+ isRegenerate: true,
+ compact: true,
+ });
+ const runStep = createRunStep({ runId: 'summary-response' });
+
+ const { result } = renderHook(() => useStepHandler(createHookParams()));
+ act(() => {
+ result.current.stepHandler({ event: StepEvents.ON_RUN_STEP, data: runStep }, submission);
+ });
+
+ const messages = mockSetMessages.mock.calls.at(-1)?.[0] as TMessage[];
+ expect(messages.map(({ messageId }) => messageId)).toEqual([
+ userMessage.messageId,
+ anchor.messageId,
+ 'summary-response',
+ ]);
+ expect(messages[1]).toBe(anchor);
+ expect(messages[2]).toMatchObject({
+ messageId: 'summary-response',
+ parentMessageId: anchor.messageId,
+ });
+ });
+
it('should warn and return early when no responseMessageId', () => {
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
diff --git a/client/src/hooks/SSE/useStepHandler.ts b/client/src/hooks/SSE/useStepHandler.ts
index f97c5b603a..a8d4bc71d4 100644
--- a/client/src/hooks/SSE/useStepHandler.ts
+++ b/client/src/hooks/SSE/useStepHandler.ts
@@ -719,6 +719,11 @@ export default function useStepHandler({
const shouldRemoveRegenerateResponse = (message: TMessage, responseMessageId: string) =>
submission.isRegenerate &&
!message.isCreatedByUser &&
+ /** A compaction's preliminary response is `${anchorId}_`. The ordinary
+ * regenerate alias set strips that suffix, but here the base ID is the
+ * assistant ANCHOR, not a response being replaced. Keep it so the
+ * summary remains its child instead of becoming an orphan root. */
+ (submission.compact !== true || message.messageId !== userMessage.messageId) &&
getRegenerateResponseIds(responseMessageId).has(message.messageId);
const shouldRemoveInitialResponse = (message: TMessage, responseMessageId: string) => {
const initialResponseId = submission.initialResponse?.messageId;
diff --git a/e2e/specs/mock/thread-fold.spec.ts b/e2e/specs/mock/thread-fold.spec.ts
index c25bd8702d..83ba3c5e9a 100644
--- a/e2e/specs/mock/thread-fold.spec.ts
+++ b/e2e/specs/mock/thread-fold.spec.ts
@@ -190,6 +190,58 @@ test.describe('thread fold regressions', () => {
await expect(siblingCounter(page)).toHaveText('2 / 2');
});
+ /** A manual compaction is a new assistant turn under the current leaf, not a
+ * regenerated sibling of that leaf. Keep the summarizer open long enough to
+ * assert the live tree: the complete transcript stays visible and no sibling
+ * navigation appears beside the "Summarizing..." row. */
+ test('a live manual compaction stays below the turn it summarizes', async ({ page, request }) => {
+ test.setTimeout(120000);
+ const label = uniqueLabel('fold-live-compact');
+ const setupPrompt = replyPrompt(`${label}-setup`);
+ const setupReply = replyText(`${label}-setup`);
+ const latestPrompt = replyPrompt(`${label}-latest`);
+ const latestReply = replyText(`${label}-latest`);
+
+ await openMockChat(page);
+ await sendAndExpectReply(page, setupPrompt, setupReply);
+ await sendAndExpectReply(page, latestPrompt, latestReply);
+ await expect(page).toHaveURL(/\/c\/[0-9a-fA-F-]{36}$/, { timeout: 15000 });
+
+ const behavior = await request.post(`${LABEL_SERVER}/__e2e/behavior`, {
+ data: { delayMs: 10000 },
+ });
+ expect(behavior.ok()).toBeTruthy();
+
+ await page.getByTestId('token-usage').click();
+ await page.getByRole('button', { name: 'Compact context' }).click();
+
+ await expect(messagesView(page).getByText('Summarizing...')).toBeVisible({ timeout: 30000 });
+ await expect(messagesView(page).getByText(setupPrompt)).toBeVisible();
+ await expect(messagesView(page).getByText(setupReply)).toBeVisible();
+ await expect(messagesView(page).getByText(latestPrompt)).toBeVisible();
+ await expect(messagesView(page).getByText(latestReply)).toBeVisible();
+ await expect(messageTurns(page)).toHaveCount(5);
+ await expect(messageTurns(page).nth(3)).toContainText(latestReply);
+ await expect(messageTurns(page).nth(4)).toContainText('Summarizing...');
+ await expect(page.getByRole('navigation', { name: 'Sibling message navigation' })).toHaveCount(
+ 0,
+ );
+
+ await expect(messagesView(page).getByText('You compacted the context')).toBeVisible({
+ timeout: 60000,
+ });
+ await expect(messagesView(page).getByText(setupPrompt)).toBeVisible();
+ await expect(messagesView(page).getByText(setupReply)).toBeVisible();
+ await expect(messagesView(page).getByText(latestPrompt)).toBeVisible();
+ await expect(messagesView(page).getByText(latestReply)).toBeVisible();
+ await expect(messageTurns(page)).toHaveCount(5);
+ await expect(messageTurns(page).nth(3)).toContainText(latestReply);
+ await expect(messageTurns(page).nth(4)).toContainText('You compacted the context');
+ await expect(page.getByRole('navigation', { name: 'Sibling message navigation' })).toHaveCount(
+ 0,
+ );
+ });
+
/**
* A manual compaction submits no user turn: it hangs a summarize-only response
* off the branch's leaf and puts that leaf in the submission's user-message