@@ -58,7 +58,7 @@ import { EcsCredentialsProvider } from './providers/ecsCredentialsProvider'
5858import { EnvVarsCredentialsProvider } from './providers/envVarsCredentialsProvider'
5959import { showMessageWithUrl } from '../shared/utilities/messages'
6060import { credentialHelpUrl } from '../shared/constants'
61- import { ExtStartUpSources , ExtStartUpSource } from '../shared/telemetry/util'
61+ import { ExtStartUpSources , ExtStartUpSource , hadClientIdOnStartup } from '../shared/telemetry/util'
6262
6363// iam-only excludes Builder ID and IAM Identity Center from the list of valid connections
6464// TODO: Understand if "iam" should include these from the list at all
@@ -688,17 +688,43 @@ export class ExtensionUse {
688688 return this . isFirstUseCurrentSession
689689 }
690690
691- this . isFirstUseCurrentSession = globals . globalState . get ( 'isExtensionFirstUse' )
692- if ( this . isFirstUseCurrentSession === undefined ) {
691+ // This is for sure not their first use
692+ const isFirstUse = globals . globalState . tryGet ( 'isExtensionFirstUse' , Boolean )
693+ if ( isFirstUse === false ) {
694+ this . isFirstUseCurrentSession = isFirstUse
695+ return this . isFirstUseCurrentSession
696+ }
697+
698+ /**
699+ * SANITY CHECK: If the clientId already existed on startup, then isFirstUse MUST be false. So
700+ * there is a bug in the state.
701+ */
702+ if ( hadClientIdOnStartup ( globals . globalState ) ) {
703+ telemetry . function_call . emit ( {
704+ result : 'Failed' ,
705+ functionName : 'isFirstUse' ,
706+ reason : 'ClientIdAlreadyExisted' ,
707+ } )
708+ }
709+
710+ if ( isAmazonQ ( ) ) {
711+ this . isFirstUseCurrentSession = true
712+ if ( hasExistingConnections ( ) ) {
713+ telemetry . function_call . emit ( {
714+ result : 'Failed' ,
715+ functionName : 'isFirstUse' ,
716+ reason : 'UnexpectedConnections' ,
717+ } )
718+ }
719+ } else {
693720 // The variable in the store is not defined yet, fallback to checking if they have existing connections.
694721 this . isFirstUseCurrentSession = ! hasExistingConnections ( )
695-
696- getLogger ( ) . debug (
697- `isFirstUse: State not found, marking user as '${
698- this . isFirstUseCurrentSession ? '' : 'NOT '
699- } first use' since they 'did ${ this . isFirstUseCurrentSession ? 'NOT ' : '' } have existing connections'.`
700- )
701722 }
723+ getLogger ( ) . debug (
724+ `isFirstUse: State not found, marking user as '${
725+ this . isFirstUseCurrentSession ? '' : 'NOT '
726+ } first use' since they 'did ${ this . isFirstUseCurrentSession ? 'NOT ' : '' } have existing connections'.`
727+ )
702728
703729 // Update state, so next time it is not first use
704730 this . updateMemento ( 'isExtensionFirstUse' , false )
0 commit comments