From 666393fbf57a6ed94239b2084e0bd115387da50b Mon Sep 17 00:00:00 2001 From: ethan Date: Fri, 28 Nov 2025 14:53:12 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20fix:=20restore=20auto-compaction?= =?UTF-8?q?=20trigger=20deleted=20by=20ORPC=20migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ORPC migration PR (#763) inadvertently deleted the auto-compaction trigger logic when sending messages. This restores: - Check if usage >= threshold before sending regular messages - Execute compaction with continueMessage instead of direct send - Show 'Context threshold reached - auto-compacting...' toast - Proper error handling with input/image restoration The supporting infrastructure (checkAutoCompaction, CompactionWarning, settings UI) remained intact - only the trigger logic was missing. _Generated with `mux`_ --- src/browser/components/ChatInput/index.tsx | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/browser/components/ChatInput/index.tsx b/src/browser/components/ChatInput/index.tsx index 57d8db3d07..862eff232f 100644 --- a/src/browser/components/ChatInput/index.tsx +++ b/src/browser/components/ChatInput/index.tsx @@ -31,6 +31,7 @@ import { handleCompactCommand, forkWorkspace, prepareCompactionMessage, + executeCompaction, type CommandHandlerContext, } from "@/browser/utils/chatCommands"; import { CUSTOM_EVENTS } from "@/common/constants/events"; @@ -699,6 +700,70 @@ export const ChatInput: React.FC = (props) => { }; }); + // Auto-compaction check (workspace variant only) + // Check if we should auto-compact before sending this message + // Result is computed in parent (AIView) and passed down to avoid duplicate calculation + const shouldAutoCompact = + props.autoCompactionCheck && + props.autoCompactionCheck.usagePercentage >= + props.autoCompactionCheck.thresholdPercentage && + !isCompacting; // Skip if already compacting to prevent double-compaction queue + + if (variant === "workspace" && !editingMessage && shouldAutoCompact) { + try { + const result = await executeCompaction({ + client, + workspaceId: props.workspaceId, + continueMessage: { + text: messageText, + imageParts, + model: sendMessageOptions.model, + }, + sendMessageOptions, + }); + + if (!result.success) { + // Restore on error + setInput(messageText); + setImageAttachments(previousImageAttachments); + setToast({ + id: Date.now().toString(), + type: "error", + title: "Auto-Compaction Failed", + message: result.error ?? "Failed to start auto-compaction", + }); + } else { + // Clear input and images on success + setInput(""); + setImageAttachments([]); + if (inputRef.current) { + inputRef.current.style.height = "36px"; + } + setToast({ + id: Date.now().toString(), + type: "success", + message: "Context threshold reached - auto-compacting...", + }); + props.onMessageSent?.(); + } + } catch (error) { + // Restore on unexpected error + setInput(messageText); + setImageAttachments(previousImageAttachments); + setToast({ + id: Date.now().toString(), + type: "error", + title: "Auto-Compaction Failed", + message: + error instanceof Error ? error.message : "Unexpected error during auto-compaction", + }); + } finally { + setIsSending(false); + } + + return; // Skip normal send + } + // When editing a /compact command, regenerate the actual summarization request let actualMessageText = messageText; let muxMetadata: MuxFrontendMetadata | undefined;