@@ -256,17 +256,24 @@ function recordOutput(value: unknown): boolean {
256256}
257257
258258const HOME_ARCHIVE_PROVIDER_WAIT_MS = 5_000 ;
259+ const HOME_BACKUP_PURGE_WAIT_MS = 30_000 ;
259260const HOME_ARCHIVE_PROVIDER_BUDGET_MS = 20 * 60_000 ;
260261const WAITING_FOR_HOME_ARCHIVE_PROVIDER = "home-archive-provider" ;
261262
262263function isHomeArchiveOperation ( op : OperationCompletionInput [ "op" ] ) : boolean {
263264 return op . kind === "gateway-vm" && op . input ?. action === "archive" && isAuthorizedHomeArchiveOrigin ( op ) ;
264265}
265266
267+ function isHomeBackupProviderOperation ( op : OperationCompletionInput [ "op" ] ) : boolean {
268+ return op . kind === "gateway-vm" && op . input ?. action === RELEASE_RESTORED_HOME_BACKUP &&
269+ op . origin === "automatic" && op . createdBy === "glm-controller-placement-policy" ;
270+ }
271+
266272export function homeArchiveProviderDueAt ( op : OperationCompletionInput [ "op" ] & {
267273 status ?: string ; waitingOn ?: string | null ; nextAttemptAt ?: number | null ;
268274} ) : number | undefined {
269- return isHomeArchiveOperation ( op ) && op . status === "pending" && op . waitingOn === WAITING_FOR_HOME_ARCHIVE_PROVIDER
275+ return ( isHomeArchiveOperation ( op ) || isHomeBackupProviderOperation ( op ) ) &&
276+ op . status === "pending" && op . waitingOn === WAITING_FOR_HOME_ARCHIVE_PROVIDER
270277 ? op . nextAttemptAt ?? undefined : undefined ;
271278}
272279
@@ -279,20 +286,36 @@ function homeArchiveProviderCompletion(input: OperationCompletionInput, steps: O
279286 const expired = { ...input , result : { success : false , steps, error : `Home archive provider wait timed out: ${ error } ` } } ;
280287 return failedCompletion ( expired , steps , attempts , failureCompletionContext ( expired , steps , attempts ) ) ;
281288 }
289+ return pendingHomeProvider ( input , steps , Math . min ( input . now + HOME_ARCHIVE_PROVIDER_WAIT_MS , deadline ) , {
290+ homeArchiveProviderDeadlineAt : deadline ,
291+ } ) ;
292+ }
293+
294+ function pendingHomeProvider ( input : OperationCompletionInput , steps : OperationStep [ ] , nextAttemptAt : number ,
295+ output : Record < string , unknown > ) : OperationPatch {
282296 return {
283297 status : "pending" ,
284298 startedAt : null ,
285299 completedAt : null ,
286300 expireAt : CLEAR ,
287301 steps,
288- nextAttemptAt : Math . min ( input . now + HOME_ARCHIVE_PROVIDER_WAIT_MS , deadline ) ,
302+ nextAttemptAt,
289303 lastProgressAt : input . now ,
290304 waitingOn : WAITING_FOR_HOME_ARCHIVE_PROVIDER ,
291- error,
292- output : { homeArchiveProviderDeadlineAt : deadline } ,
305+ error : input . result . error ?? "Provider has not completed the archive transition" ,
306+ output,
293307 } ;
294308}
295309
310+ function homeProviderContinuation ( input : OperationCompletionInput , steps : OperationStep [ ] , attempts : number ) : OperationPatch | undefined {
311+ if ( input . result . waitingForHomeArchiveProvider !== true ) return undefined ;
312+ if ( isHomeArchiveOperation ( input . op ) ) return homeArchiveProviderCompletion ( input , steps , attempts ) ;
313+ if ( isHomeBackupProviderOperation ( input . op ) ) {
314+ return pendingHomeProvider ( input , steps , input . now + HOME_BACKUP_PURGE_WAIT_MS , { homeBackupReleasePending : true } ) ;
315+ }
316+ return undefined ;
317+ }
318+
296319function isHomeBackupReleasePending ( { op, result } : OperationCompletionInput ) : boolean {
297320 return op . kind === "gateway-vm" && op . input ?. action === RELEASE_RESTORED_HOME_BACKUP && result . output ?. homeBackupReleasePending === true ;
298321}
@@ -521,9 +544,8 @@ export function buildOperationCompletionUpdate(
521544 } ;
522545 }
523546 if ( result . success ) return successfulCompletion ( input , persistedSteps , attempts ) ;
524- if ( result . waitingForHomeArchiveProvider === true && isHomeArchiveOperation ( op ) ) {
525- return homeArchiveProviderCompletion ( input , persistedSteps , attempts ) ;
526- }
547+ const continuation = homeProviderContinuation ( input , persistedSteps , attempts ) ;
548+ if ( continuation ) return continuation ;
527549
528550 const failure = failureCompletionContext ( input , persistedSteps , attempts ) ;
529551 if ( result . failedAfterCutover === true ) return failedAfterCutoverCompletion ( input , persistedSteps , attempts , failure ) ;
0 commit comments