Skip to content

Commit b81219a

Browse files
committed
use pending model for auto compact check
1 parent 1726268 commit b81219a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/browser/components/AIView.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { QueuedMessage } from "./Messages/QueuedMessage";
3838
import { CompactionWarning } from "./CompactionWarning";
3939
import { shouldAutoCompact } from "@/browser/utils/compaction/autoCompactionCheck";
4040
import { useProviderOptions } from "@/browser/hooks/useProviderOptions";
41+
import { useSendMessageOptions } from "@/browser/hooks/useSendMessageOptions";
4142

4243
interface AIViewProps {
4344
workspaceId: string;
@@ -328,8 +329,14 @@ const AIViewInner: React.FC<AIViewProps> = ({
328329
// Get active stream message ID for token counting
329330
const activeStreamMessageId = aggregator.getActiveStreamMessageId();
330331

331-
const autoCompactionCheck = currentModel
332-
? shouldAutoCompact(workspaceUsage, currentModel, use1M)
332+
// Use pending send model for auto-compaction check, not the last stream's model.
333+
// This ensures the threshold is based on the model the user will actually send with,
334+
// preventing context-length errors when switching from a large-context to smaller model.
335+
const pendingSendOptions = useSendMessageOptions(workspaceId);
336+
const pendingModel = pendingSendOptions.model;
337+
338+
const autoCompactionCheck = pendingModel
339+
? shouldAutoCompact(workspaceUsage, pendingModel, use1M)
333340
: { shouldShowWarning: false, usagePercentage: 0, thresholdPercentage: 70 };
334341

335342
// Show warning when: shouldShowWarning flag is true AND not currently compacting

0 commit comments

Comments
 (0)