@@ -873,7 +873,23 @@ export class RunExecution {
873
873
) ;
874
874
875
875
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
+ }
877
893
}
878
894
879
895
// Track restore count
@@ -899,11 +915,18 @@ export class RunExecution {
899
915
public async processEnvOverrides (
900
916
reason ?: string ,
901
917
shouldPollForSnapshotChanges ?: boolean
902
- ) : Promise < { overrides : Metadata } | null > {
918
+ ) : Promise < {
919
+ overrides : Metadata ;
920
+ runnerIdChanged ?: boolean ;
921
+ supervisorChanged ?: boolean ;
922
+ } | null > {
903
923
if ( ! this . metadataClient ) {
904
924
return null ;
905
925
}
906
926
927
+ const previousRunnerId = this . env . TRIGGER_RUNNER_ID ;
928
+ const previousSupervisorUrl = this . env . TRIGGER_SUPERVISOR_API_URL ;
929
+
907
930
const [ error , overrides ] = await this . metadataClient . getEnvOverrides ( ) ;
908
931
909
932
if ( error ) {
@@ -931,6 +954,14 @@ export class RunExecution {
931
954
// Override the env with the new values
932
955
this . env . override ( overrides ) ;
933
956
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
+
934
965
// Update services with new values
935
966
if ( overrides . TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS ) {
936
967
this . snapshotPoller ?. updateInterval ( this . env . TRIGGER_SNAPSHOT_POLL_INTERVAL_SECONDS * 1000 ) ;
@@ -954,6 +985,8 @@ export class RunExecution {
954
985
955
986
return {
956
987
overrides,
988
+ runnerIdChanged,
989
+ supervisorChanged,
957
990
} ;
958
991
}
959
992
@@ -977,6 +1010,12 @@ export class RunExecution {
977
1010
978
1011
if ( ! response . success ) {
979
1012
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
+ }
980
1019
}
981
1020
982
1021
this . lastHeartbeat = new Date ( ) ;
@@ -1192,6 +1231,14 @@ export class RunExecution {
1192
1231
error : response . error ,
1193
1232
} ) ;
1194
1233
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
1195
1242
await this . processEnvOverrides ( "snapshots since error" ) ;
1196
1243
return ;
1197
1244
}
0 commit comments