public function actionChangeRole(string $email, string $role = 'client')
	{
		$trimmedEmail = trim($email);
		$trimmedRole = trim($role);
		
		$user = UserConsole::findByEmail($trimmedEmail);
		if (!$user) {
		
			Console::error("Email \"$trimmedEmail\" user doesn't exist");
			
			return ExitCode::UNSPECIFIED_ERROR;
		}
		
		//$userUsername = $user->getUsername();
		$userId = $user->getId();
		$userEmail = $user->getEmail();
		
		// Initialize AuthManager and check current roles.
		$authManager = \Yii::$app->authManager;
		$assignments = $authManager->getAssignments($userId);
		Console::output("Assignments returned: " . print_r($assignments, true));// Debugging.
		if ($assignments) {
			
			Console::output("User already assigned to a role. Revoking old roles...");
			foreach ($assignments as $roleName => $assignment) {
				
				//if ($assignment instanceof RbacAssignment) {
				if ($assignment instanceof \yii\rbac\Assignment) {
				
					if ($authManager->revoke($roleName, $userId)) {
						
						Console::output("Revoked role \"{$assignment->roleName}\" from user \"$trimmedEmail\".");
					}
					else {
						Console::error("Failed to revoke role \"{$assignment->roleName}\" from user \"$trimmedEmail\".");
					}
				}
				else {
					Console::error("Invalid assignment data for user \"$trimmedEmail\".");
				}
			}
		}
		else {
			Console::output("User \"$userEmail\" has no assigned roles.");
		}
		
		$transaction = \Yii::$app->db->beginTransaction();
		try {
			// Check if the provided role exists.
			$authRole = $authManager->getRole($trimmedRole);
			if (!$authRole) {
				
				throw new Exception("Role \"$trimmedRole\" does not exist.");
			}
		
			// Assign the new role to the user.
			if ($authManager->assign($authRole, $userId)) {
				
				Console::output("Successfully assigned role \"$trimmedRole\" to user \"$userEmail\".");
			}
			else {
				throw new Exception("Failed to assign role \"$trimmedRole\" to user \"$userEmail\".");
			}
			
			// If all saves are successful, commit the transaction.
			$transaction->commit();
			
			Console::output("User role has been updated successfully.");
			Console::output("Email: " . $userEmail);
			Console::output("New Role: " . $trimmedRole);
			
			return ExitCode::OK;
		}
		catch (\Exception $e) {
		
			// An error occurred; roll back the transaction.
			$transaction->rollBack();
			
			Console::output("Role change failed: " . $e->getMessage());
				
			return ExitCode::UNSPECIFIED_ERROR;
		}
	}

so this entire area does not work:

		if ($assignments) {
			
			Console::output("User already assigned to a role. Revoking old roles...");
			foreach ($assignments as $roleName => $assignment) {
				
				//if ($assignment instanceof RbacAssignment) {
				if ($assignment instanceof \yii\rbac\Assignment) {
				
					if ($authManager->revoke($roleName, $userId)) {
						
						Console::output("Revoked role \"{$assignment->roleName}\" from user \"$trimmedEmail\".");
					}
					else {
						Console::error("Failed to revoke role \"{$assignment->roleName}\" from user \"$trimmedEmail\".");
					}
				}
				else {
					Console::error("Invalid assignment data for user \"$trimmedEmail\".");
				}
			}
		}
		else {
			Console::output("User \"$userEmail\" has no assigned roles.");
		}

The main issue is:

if ($assignment instanceof \yii\rbac\Assignment) {
				
					if ($authManager->revoke($roleName, $userId)) {

and rbac assigment was never meant to be directly accessed this way. yii2 does have revoke->all that ManagerInterface, so we have access to