Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/browser/contexts/ProviderOptionsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { createContext, useContext } from "react";
import { usePersistedState } from "@/browser/hooks/usePersistedState";
import React, { createContext, useContext, useLayoutEffect } from "react";
import {
readPersistedState,
updatePersistedState,
usePersistedState,
} from "@/browser/hooks/usePersistedState";
import type { MuxProviderOptions } from "@/common/types/providerOptions";

interface ProviderOptionsContextType {
Expand All @@ -11,6 +15,10 @@ interface ProviderOptionsContextType {

const ProviderOptionsContext = createContext<ProviderOptionsContextType | undefined>(undefined);

const OPENAI_OPTIONS_KEY = "provider_options_openai";
// One-time migration key: force disableAutoTruncation to true for existing users
const OPENAI_TRUNCATION_MIGRATION_KEY = "provider_options_openai_truncation_migrated";

export function ProviderOptionsProvider({ children }: { children: React.ReactNode }) {
const [anthropicOptions, setAnthropicOptions] = usePersistedState<
MuxProviderOptions["anthropic"]
Expand All @@ -19,12 +27,20 @@ export function ProviderOptionsProvider({ children }: { children: React.ReactNod
});

const [openaiOptions, setOpenAIOptions] = usePersistedState<MuxProviderOptions["openai"]>(
"provider_options_openai",
{
disableAutoTruncation: false,
}
OPENAI_OPTIONS_KEY,
{ disableAutoTruncation: true }
);

// One-time migration: force disableAutoTruncation to true for existing users
useLayoutEffect(() => {
const alreadyMigrated = readPersistedState<boolean>(OPENAI_TRUNCATION_MIGRATION_KEY, false);
if (alreadyMigrated) {
return;
}
updatePersistedState(OPENAI_OPTIONS_KEY, { disableAutoTruncation: true });
updatePersistedState(OPENAI_TRUNCATION_MIGRATION_KEY, true);
}, []);

const [googleOptions, setGoogleOptions] = usePersistedState<MuxProviderOptions["google"]>(
"provider_options_google",
{}
Expand Down
2 changes: 1 addition & 1 deletion src/browser/utils/messages/sendOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function getProviderOptions(): MuxProviderOptions {
{ use1MContext: false }
);
const openai = readPersistedState<MuxProviderOptions["openai"]>("provider_options_openai", {
disableAutoTruncation: false,
disableAutoTruncation: true,
});
const google = readPersistedState<MuxProviderOptions["google"]>("provider_options_google", {});

Expand Down
20 changes: 17 additions & 3 deletions tests/ipc/sendMessage.heavy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ describeIntegration("sendMessage heavy/load tests", () => {
await withSharedWorkspace(provider, async ({ env, workspaceId, collector }) => {
// Build up large conversation history to exceed context limit
// This approach is model-agnostic - it keeps sending until we've built up enough history
// Use auto-truncation enabled (disableAutoTruncation: false) so history builds up successfully
const largeMessage = "x".repeat(50_000);
for (let i = 0; i < 10; i++) {
await sendMessageWithModel(
env,
workspaceId,
`Message ${i}: ${largeMessage}`,
modelString(provider, model)
modelString(provider, model),
{
providerOptions: {
openai: {
disableAutoTruncation: false,
},
},
}
);
await collector.waitForEvent("stream-end", 30000);
collector.clear();
Expand Down Expand Up @@ -93,8 +101,14 @@ describeIntegration("sendMessage heavy/load tests", () => {
env,
workspaceId,
"This should succeed with auto-truncation",
modelString(provider, model)
// disableAutoTruncation defaults to false (auto-truncation enabled)
modelString(provider, model),
{
providerOptions: {
openai: {
disableAutoTruncation: false,
},
},
}
);

expect(successResult.success).toBe(true);
Expand Down
Loading