@@ -873,7 +873,23 @@ export class RunExecution {
873873 ) ;
874874
875875 if ( ! continuationResult . success ) {
876- throw new Error ( continuationResult . error ) ;
876+ // Check if we need to refresh metadata due to connection error
877+ if ( continuationResult . isConnectionError ) {
878+ this . sendDebugLog ( "restore: connection error detected, refreshing metadata" ) ;
879+ await this . processEnvOverrides ( "restore connection error" ) ;
880+
881+ // Retry the continuation after refreshing metadata
882+ const retryResult = await this . httpClient . continueRunExecution (
883+ this . runFriendlyId ,
884+ this . snapshotManager . snapshotId
885+ ) ;
886+
887+ if ( ! retryResult . success ) {
888+ throw new Error ( retryResult . error ) ;
889+ }
890+ } else {
891+ throw new Error ( continuationResult . error ) ;
892+ }
877893 }
878894
879895 // Track restore count
@@ -899,11 +915,18 @@ export class RunExecution {
899915 public async processEnvOverrides (
900916 reason ?: string ,
901917 shouldPollForSnapshotChanges ?: boolean
902- ) : Promise < { overrides : Metadata } | null > {
918+ ) : Promise < {
919+ overrides : Metadata ;
920+ runnerIdChanged ?: boolean ;
921+ supervisorChanged ?: boolean ;
922+ } | null > {
903923 if ( ! this . metadataClient ) {
904924 return null ;
905925 }
906926
927+ const previousRunnerId = this . env . TRIGGER_RUNNER_ID ;
928+ const previousSupervisorUrl = this . env . TRIGGER_SUPERVISOR_API_URL ;
929+
907930 const [ error , overrides ] = await this . metadataClient . getEnvOverrides ( ) ;
908931
909932 if ( error ) {
@@ -931,6 +954,14 @@ export class RunExecution {
931954 // Override the env with the new values
932955 this . env . override ( overrides ) ;
933956
957+ // Check if runner ID changed
958+ const newRunnerId = this . env . TRIGGER_RUNNER_ID ;
959+ const runnerIdChanged = previousRunnerId !== newRunnerId ;
960+
961+ // Check if supervisor URL changed
962+ const newSupervisorUrl = this . env . TRIGGER_SUPERVISOR_API_URL ;
963+ const supervisorChanged = previousSupervisorUrl !== newSupervisorUrl ;
964+
934965 // Update services with new values
935966 if ( overrides . TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS ) {
936967 this . snapshotPoller ?. updateInterval ( this . env . TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS * 1000 ) ;
@@ -954,6 +985,8 @@ export class RunExecution {
954985
955986 return {
956987 overrides,
988+ runnerIdChanged,
989+ supervisorChanged,
957990 } ;
958991 }
959992
@@ -977,6 +1010,12 @@ export class RunExecution {
9771010
9781011 if ( ! response . success ) {
9791012 this . sendDebugLog ( "heartbeat: failed" , { error : response . error } ) ;
1013+
1014+ // Check if we need to refresh metadata due to connection error
1015+ if ( response . isConnectionError ) {
1016+ this . sendDebugLog ( "heartbeat: connection error detected, refreshing metadata" ) ;
1017+ await this . processEnvOverrides ( "heartbeat connection error" ) ;
1018+ }
9801019 }
9811020
9821021 this . lastHeartbeat = new Date ( ) ;
@@ -1192,6 +1231,14 @@ export class RunExecution {
11921231 error : response . error ,
11931232 } ) ;
11941233
1234+ if ( response . isConnectionError ) {
1235+ // Log this separately to make it more visible
1236+ this . sendDebugLog (
1237+ "fetchAndProcessSnapshotChanges: connection error detected, refreshing metadata"
1238+ ) ;
1239+ }
1240+
1241+ // Always trigger metadata refresh on snapshot fetch errors
11951242 await this . processEnvOverrides ( "snapshots since error" ) ;
11961243 return ;
11971244 }
0 commit comments