@@ -55,6 +55,7 @@ export class WorkspaceFolderManager {
5555 private optOutMonitorInterval : NodeJS . Timeout | undefined
5656 private messageQueueConsumerInterval : NodeJS . Timeout | undefined
5757 private isOptedOut : boolean = false
58+ private featureDisabled : boolean = false // Serve as a server-side control. If true, stop WCS features
5859 private isCheckingRemoteWorkspaceStatus : boolean = false
5960 private isArtifactUploadedToRemoteWorkspace : boolean = false
6061
@@ -139,8 +140,13 @@ export class WorkspaceFolderManager {
139140 return this . isOptedOut
140141 }
141142
142- resetAdminOptOutStatus ( ) : void {
143+ resetAdminOptOutAndFeatureDisabledStatus ( ) : void {
143144 this . isOptedOut = false
145+ this . featureDisabled = false
146+ }
147+
148+ isFeatureDisabled ( ) : boolean {
149+ return this . featureDisabled
144150 }
145151
146152 getWorkspaceState ( ) : WorkspaceState {
@@ -326,6 +332,7 @@ export class WorkspaceFolderManager {
326332 // Reset workspace ID to force operations to wait for new remote workspace information
327333 this . resetRemoteWorkspaceId ( )
328334
335+ IdleWorkspaceManager . setSessionAsIdle ( )
329336 this . isArtifactUploadedToRemoteWorkspace = false
330337
331338 // Set up message queue consumer
@@ -371,7 +378,9 @@ export class WorkspaceFolderManager {
371378 return resolve ( false )
372379 }
373380
374- const { metadata, optOut } = await this . listWorkspaceMetadata ( this . workspaceIdentifier )
381+ const { metadata, optOut, featureDisabled } = await this . listWorkspaceMetadata (
382+ this . workspaceIdentifier
383+ )
375384
376385 if ( optOut ) {
377386 this . logging . log ( `User opted out during initial connection` )
@@ -381,6 +390,13 @@ export class WorkspaceFolderManager {
381390 return resolve ( false )
382391 }
383392
393+ if ( featureDisabled ) {
394+ this . logging . log ( `Feature disabled during initial connection` )
395+ this . featureDisabled = true
396+ this . clearAllWorkspaceResources ( )
397+ return resolve ( false )
398+ }
399+
384400 if ( ! metadata ) {
385401 // Continue polling by exiting only this iteration
386402 return
@@ -437,7 +453,9 @@ export class WorkspaceFolderManager {
437453 }
438454
439455 this . logging . log ( `Checking remote workspace status for workspace [${ this . workspaceIdentifier } ]` )
440- const { metadata, optOut, error } = await this . listWorkspaceMetadata ( this . workspaceIdentifier )
456+ const { metadata, optOut, featureDisabled, error } = await this . listWorkspaceMetadata (
457+ this . workspaceIdentifier
458+ )
441459
442460 if ( optOut ) {
443461 this . logging . log ( 'User opted out, clearing all resources and starting opt-out monitor' )
@@ -447,6 +465,13 @@ export class WorkspaceFolderManager {
447465 return
448466 }
449467
468+ if ( featureDisabled ) {
469+ this . logging . log ( 'Feature disabled, clearing all resources and stoping server-side indexing features' )
470+ this . featureDisabled = true
471+ this . clearAllWorkspaceResources ( )
472+ return
473+ }
474+
450475 if ( error ) {
451476 // Do not do anything if we received an exception but not caused by optOut
452477 return
@@ -528,7 +553,14 @@ export class WorkspaceFolderManager {
528553 if ( this . optOutMonitorInterval === undefined ) {
529554 const intervalId = setInterval ( async ( ) => {
530555 try {
531- const { optOut } = await this . listWorkspaceMetadata ( )
556+ const { optOut, featureDisabled } = await this . listWorkspaceMetadata ( )
557+
558+ if ( featureDisabled ) {
559+ // Stop opt-out monitor when WCS feature is disabled from server-side
560+ this . featureDisabled = true
561+ clearInterval ( intervalId )
562+ this . optOutMonitorInterval = undefined
563+ }
532564
533565 if ( ! optOut ) {
534566 this . isOptedOut = false
@@ -735,10 +767,12 @@ export class WorkspaceFolderManager {
735767 private async listWorkspaceMetadata ( workspaceRoot ?: WorkspaceRoot ) : Promise < {
736768 metadata : WorkspaceMetadata | undefined | null
737769 optOut : boolean
770+ featureDisabled : boolean
738771 error : any
739772 } > {
740773 let metadata : WorkspaceMetadata | undefined | null
741774 let optOut = false
775+ let featureDisabled = false
742776 let error : any
743777 try {
744778 const params = workspaceRoot ? { workspaceRoot } : { }
@@ -754,8 +788,11 @@ export class WorkspaceFolderManager {
754788 this . logging . log ( `User's administrator opted out server-side workspace context` )
755789 optOut = true
756790 }
791+ if ( isAwsError ( e ) && e . code === 'AccessDeniedException' && e . message . includes ( 'Feature is not supported' ) ) {
792+ featureDisabled = true
793+ }
757794 }
758- return { metadata, optOut, error }
795+ return { metadata, optOut, featureDisabled , error }
759796 }
760797
761798 private async createWorkspace ( workspaceRoot : WorkspaceRoot ) : Promise < {
0 commit comments