@@ -141,7 +141,9 @@ public async Task<CreateSessionResult> CreateSessionAsync(CancellationToken toke
141141 Trace . Error ( "Catch exception during create session." ) ;
142142 Trace . Error ( ex ) ;
143143
144- if ( ex is VssOAuthTokenRequestException vssOAuthEx && _credsV2 . Federated is VssOAuthCredential vssOAuthCred )
144+ if ( ! HostContext . AllowAuthMigration &&
145+ ex is VssOAuthTokenRequestException vssOAuthEx &&
146+ _credsV2 . Federated is VssOAuthCredential vssOAuthCred )
145147 {
146148 // "invalid_client" means the runner registration has been deleted from the server.
147149 if ( string . Equals ( vssOAuthEx . Error , "invalid_client" , StringComparison . OrdinalIgnoreCase ) )
@@ -162,7 +164,8 @@ public async Task<CreateSessionResult> CreateSessionAsync(CancellationToken toke
162164 }
163165 }
164166
165- if ( ! IsSessionCreationExceptionRetriable ( ex ) )
167+ if ( ! HostContext . AllowAuthMigration &&
168+ ! IsSessionCreationExceptionRetriable ( ex ) )
166169 {
167170 _term . WriteError ( $ "Failed to create session. { ex . Message } ") ;
168171 if ( ex is TaskAgentSessionConflictException )
@@ -283,11 +286,11 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
283286 Trace . Info ( "Hosted runner has been deprovisioned." ) ;
284287 throw ;
285288 }
286- catch ( AccessDeniedException e ) when ( e . ErrorCode == 1 )
289+ catch ( AccessDeniedException e ) when ( e . ErrorCode == 1 && ! HostContext . AllowAuthMigration )
287290 {
288291 throw ;
289292 }
290- catch ( RunnerNotFoundException )
293+ catch ( RunnerNotFoundException ) when ( ! HostContext . AllowAuthMigration )
291294 {
292295 throw ;
293296 }
@@ -296,7 +299,8 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
296299 Trace . Error ( "Catch exception during get next message." ) ;
297300 Trace . Error ( ex ) ;
298301
299- if ( ! IsGetNextMessageExceptionRetriable ( ex ) )
302+ if ( ! HostContext . AllowAuthMigration &&
303+ ! IsGetNextMessageExceptionRetriable ( ex ) )
300304 {
301305 throw new NonRetryableException ( "Get next message failed with non-retryable error." , ex ) ;
302306 }
0 commit comments