Skip to content

Commit

Permalink
autoedit: Add feature flag to enable/disable autoedit feature (#6145)
Browse files Browse the repository at this point in the history
## Context
Adds a feature flag to enable if the `auto-edits` feature should be
enable instead of autocomplete.

## Test plan
1. Override the userId `feature-flag` in the backend and see
`autocomplete` triggers when flag is off, else `autoedits` trigger.
  • Loading branch information
hitesh-1997 authored Nov 19, 2024
1 parent f5b991b commit ba499fe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/shared/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interface RawClientConfiguration {
experimentalSupercompletions: boolean
experimentalAutoeditsRendererTesting: boolean
experimentalAutoeditsConfigOverride: AutoEditsModelConfig | undefined
experimentalAutoeditsEnabled: boolean
experimentalAutoeditsEnabled: boolean | undefined
experimentalCommitMessage: boolean
experimentalNoodle: boolean
experimentalMinionAnthropicKey: string | undefined
Expand Down
2 changes: 2 additions & 0 deletions lib/shared/src/experimentation/FeatureFlagProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export enum FeatureFlag {
CodyAutocompleteContextExperimentVariant4 = 'cody-autocomplete-context-experiment-variant-4',
CodyAutocompleteContextExperimentControl = 'cody-autocomplete-context-experiment-control',

CodyAutoeditExperimentEnabledFeatureFlag = 'cody-autoedit-experiment-enabled-flag',

// Enables gpt-4o-mini as a default Edit model
CodyEditDefaultToGpt4oMini = 'cody-edit-default-to-gpt-4o-mini',

Expand Down
4 changes: 2 additions & 2 deletions vscode/src/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('getConfiguration', () => {
case 'cody.experimental.supercompletions':
return false
case 'cody.experimental.autoedits.enabled':
return false
return undefined
case 'cody.experimental.autoedits-renderer-testing':
return false
case 'cody.experimental.autoedits.config.override':
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('getConfiguration', () => {
},
commandCodeLenses: true,
experimentalSupercompletions: false,
experimentalAutoeditsEnabled: false,
experimentalAutoeditsEnabled: undefined,
experimentalAutoeditsConfigOverride: undefined,
experimentalAutoeditsRendererTesting: false,
experimentalMinionAnthropicKey: undefined,
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function getConfiguration(
experimentalTracing: getHiddenSetting('experimental.tracing', false),

experimentalSupercompletions: getHiddenSetting('experimental.supercompletions', false),
experimentalAutoeditsEnabled: getHiddenSetting('experimental.autoedits.enabled', false),
experimentalAutoeditsEnabled: getHiddenSetting('experimental.autoedits.enabled', undefined),
experimentalAutoeditsConfigOverride: getHiddenSetting(
'experimental.autoedits.config.override',
undefined
Expand Down
63 changes: 50 additions & 13 deletions vscode/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode'

import {
type AuthStatus,
type ChatClient,
ClientConfigSingleton,
type ConfigurationInput,
Expand Down Expand Up @@ -40,6 +41,7 @@ import {
import _ from 'lodash'
import { isEqual } from 'lodash'
import { filter, map } from 'observable-fns'
import { isS2 } from '../../lib/shared/src/sourcegraph-api/environments'
import { isReinstalling } from '../uninstall/reinstall'
import type { CommandResult } from './CommandResult'
import { showAccountMenu } from './auth/account-menu'
Expand Down Expand Up @@ -704,21 +706,40 @@ async function tryRegisterTutorial(

function registerAutoEdits(disposables: vscode.Disposable[]): void {
disposables.push(
enableFeature(
({ configuration }) => {
return (
configuration.experimentalAutoeditsEnabled === true &&
configuration.autocomplete === false
subscriptionDisposable(
combineLatest(
resolvedConfig,
authStatus,
featureFlagProvider.evaluatedFeatureFlag(
FeatureFlag.CodyAutoeditExperimentEnabledFeatureFlag
)
},
() => {
const provider = new AutoeditsProvider()
return provider
}
)
.pipe(
map(([config, authStatus, autoeditEnabled]) => {
if (shouldEnableExperimentalAutoedits(config, autoeditEnabled, authStatus)) {
const provider = new AutoeditsProvider()
return provider
}
return []
})
)
.subscribe({})
)
)
}

function shouldEnableExperimentalAutoedits(
config: ResolvedConfiguration,
autoeditExperimentFlag: boolean,
authStatus: AuthStatus
): boolean {
// If the config is explicitly set in the vscode settings, use the setting instead of the feature flag.
if (config.configuration.experimentalAutoeditsEnabled !== undefined) {
return config.configuration.experimentalAutoeditsEnabled
}
return autoeditExperimentFlag && isS2(authStatus)
}

/**
* Registers autocomplete functionality.
*/
Expand All @@ -736,16 +757,32 @@ function registerAutocomplete(
statusBarLoader?.()
statusBarLoader = undefined
}

disposables.push(
subscriptionDisposable(
combineLatest(resolvedConfig, authStatus)
combineLatest(
resolvedConfig,
authStatus,
featureFlagProvider.evaluatedFeatureFlag(
FeatureFlag.CodyAutoeditExperimentEnabledFeatureFlag
)
)
.pipe(
//TODO(@rnauta -> @sqs): It feels yuk to handle the invalidation outside of
//where the state is picked. It's also very tedious
distinctUntilChanged((a, b) => {
return isEqual(a[0].configuration, b[0].configuration) && isEqual(a[1], b[1])
return (
isEqual(a[0].configuration, b[0].configuration) &&
isEqual(a[1], b[1]) &&
isEqual(a[2], b[2])
)
}),
switchMap(([config, authStatus]) => {
switchMap(([config, authStatus, autoeditEnabled]) => {
// If the auto-edit experiment is enabled, we don't need to load the completion provider
if (shouldEnableExperimentalAutoedits(config, autoeditEnabled, authStatus)) {
finishLoading()
return NEVER
}
if (!authStatus.pendingValidation && !statusBarLoader) {
statusBarLoader = statusBar.addLoader({
title: 'Completion Provider is starting',
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/testutils/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ export const DEFAULT_VSCODE_SETTINGS = {
},
commandCodeLenses: false,
experimentalSupercompletions: false,
experimentalAutoeditsEnabled: false,
experimentalAutoeditsEnabled: undefined,
experimentalAutoeditsRendererTesting: false,
experimentalAutoeditsConfigOverride: undefined,
experimentalMinionAnthropicKey: undefined,
Expand Down

0 comments on commit ba499fe

Please sign in to comment.