From ae351c26669f2c329a2175992b43e1e5f1ec487f Mon Sep 17 00:00:00 2001 From: Beatrix <68532117+abeatrix@users.noreply.github.com> Date: Thu, 23 Jan 2025 01:09:41 +0900 Subject: [PATCH] fix(models): ensure Tool Cody is only added when enabled (#6753) FIX https://linear.app/sourcegraph/issue/CODY-4737 The issue was that the Tool Cody model was being added to the list of primary models regardless of whether the feature was enabled or not. The root cause was that the check for the existence of the Tool Cody model was not properly scoped to the `isToolCodyEnabled` flag but was checking the observable instead, which would always returns true as the observable is defined. This change fixes the issue by only adding the Tool Cody model to the list of primary models if the `isToolCodyEnabled` flag is true and the Tool Cody model is not already present in the list of primary models. Included some minor clean up. ## Test plan Verify Tool Cody is not showing up in your model dropdown if you don't have the configuration in your settings: image --- lib/shared/src/models/sync.ts | 69 +++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/lib/shared/src/models/sync.ts b/lib/shared/src/models/sync.ts index d6f21c429cbe..deadde784ae8 100644 --- a/lib/shared/src/models/sync.ts +++ b/lib/shared/src/models/sync.ts @@ -212,7 +212,12 @@ export function syncModels({ enableToolCody ).pipe( switchMap( - ([hasEarlyAccess, hasAgenticChatFlag, defaultToHaiku]) => { + ([ + hasEarlyAccess, + hasAgenticChatFlag, + defaultToHaiku, + isToolCodyEnabled, + ]) => { // TODO(sqs): remove waitlist from localStorage when user has access const isOnWaitlist = config.clientState.waitlist_o1 if (isDotComUser && (hasEarlyAccess || isOnWaitlist)) { @@ -233,49 +238,57 @@ export function syncModels({ } ) } + + const clientModels = [] + + // Handle agentic chat features + const isAgenticChatEnabled = + hasAgenticChatFlag || + (isDotComUser && !isCodyFreeUser) const haikuModel = data.primaryModels.find(m => m.id.includes('5-haiku') ) const sonnetModel = data.primaryModels.find(m => m.id.includes('5-sonnet') ) - // Agentic Chat is available for all Pro users. - // Enterprise users need to have the feature flag enabled. - const isAgenticChatEnabled = - hasAgenticChatFlag || - (isDotComUser && !isCodyFreeUser) - - // Requires 3.5 Haiku and 3.5 Sonnet models to be available. + const hasDeepCody = data.primaryModels.some(m => + m.id.includes('deep-cody') + ) if ( + !hasDeepCody && isAgenticChatEnabled && sonnetModel && - haikuModel && - // Ensure the deep-cody model is only added once. - !data.primaryModels.some(m => - m.id.includes('deep-cody') - ) + haikuModel ) { - const DEEPCODY_MODEL = + clientModels.push( getExperimentalClientModelByFeatureFlag( FeatureFlag.DeepCody )! + ) + } - const clientModels = [DEEPCODY_MODEL] - if (enableToolCody) { - clientModels.push(TOOL_CODY_MODEL) - } + const hasToolCody = data.primaryModels.some(m => + m.id.includes('tool-cody') + ) + if (!hasToolCody && isToolCodyEnabled) { + clientModels.push(TOOL_CODY_MODEL) + } - data.primaryModels.push( - ...maybeAdjustContextWindows(clientModels).map( - createModelFromServerModel - ) + // Add the client models to the list of models. + data.primaryModels.push( + ...maybeAdjustContextWindows(clientModels).map( + createModelFromServerModel ) - } - // set the default model to Haiku for free users - if (isDotComUser && isCodyFreeUser && defaultToHaiku) { - if (haikuModel) { - data.preferences!.defaults.chat = haikuModel.id - } + ) + + // Set the default model to Haiku for free users. + if ( + isDotComUser && + isCodyFreeUser && + defaultToHaiku && + haikuModel + ) { + data.preferences!.defaults.chat = haikuModel.id } return Observable.of(data)