Skip to content

Commit

Permalink
[Backport jb-v7.12.x] fix(models): ensure Tool Cody is only added whe…
Browse files Browse the repository at this point in the history
…n enabled (#6759)

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:

<img width="603" alt="image"
src="https://github.com/user-attachments/assets/6ebdbb6e-650d-4bc4-ad62-40a285a13f5f"
/>

 <br> Backport ae351c2 from #6753

Co-authored-by: Beatrix <[email protected]>
  • Loading branch information
sourcegraph-release-bot and abeatrix authored Jan 22, 2025
1 parent bfa18e6 commit 60bbda0
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions lib/shared/src/models/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)
Expand Down

0 comments on commit 60bbda0

Please sign in to comment.