@@ -35,6 +35,8 @@ import {
3535const DEFAULT_CHECKOUT = "/Users/steipete/openclaw" ;
3636const DEFAULT_EXPECTED_ORIGIN = "openclaw/openclaw" ;
3737const FULL_SHA_RE = / ^ [ 0 - 9 a - f ] { 40 } $ / u;
38+ const GATEWAY_READINESS_ATTEMPTS = 3 ;
39+ const GATEWAY_READINESS_RETRY_DELAY_MS = 5_000 ;
3840const DEPENDENCY_INPUT_RE =
3941 / ^ (?: \. n p m r c $ | p a c k a g e \. j s o n $ | p n p m - l o c k \. y a m l $ | p n p m - w o r k s p a c e \. y a m l $ | p a t c h e s \/ ) | (?: ^ | \/ ) p a c k a g e \. j s o n $ / u;
4042
@@ -578,6 +580,26 @@ function verifyGateway(runCommand, checkout, expectedSha) {
578580 runCommand ( "pnpm" , [ "openclaw" , "health" , "--verbose" , "--json" ] , checkout ) ;
579581}
580582
583+ function defaultSleep ( ms ) {
584+ execFileSync ( "sleep" , [ String ( ms / 1_000 ) ] ) ;
585+ }
586+
587+ export function verifyGatewayReadiness ( runCommand , checkout , expectedSha , sleep = defaultSleep ) {
588+ let lastError ;
589+ for ( let attempt = 1 ; attempt <= GATEWAY_READINESS_ATTEMPTS ; attempt += 1 ) {
590+ try {
591+ verifyGateway ( runCommand , checkout , expectedSha ) ;
592+ return ;
593+ } catch ( error ) {
594+ lastError = error ;
595+ if ( attempt < GATEWAY_READINESS_ATTEMPTS ) {
596+ sleep ( GATEWAY_READINESS_RETRY_DELAY_MS ) ;
597+ }
598+ }
599+ }
600+ throw lastError ;
601+ }
602+
581603function summarizeGatewayLogEntry ( entry ) {
582604 return {
583605 time : entry . time ,
@@ -690,10 +712,17 @@ function defaultAuditGatewayLogs(checkout, sinceMs) {
690712 return audit ;
691713}
692714
693- function verifyAndAuditGateway ( { runCommand, auditGatewayLogs, checkout, expectedSha, sinceMs } ) {
715+ function verifyAndAuditGateway ( {
716+ runCommand,
717+ auditGatewayLogs,
718+ checkout,
719+ expectedSha,
720+ sinceMs,
721+ sleep,
722+ } ) {
694723 let verificationError ;
695724 try {
696- verifyGateway ( runCommand , checkout , expectedSha ) ;
725+ verifyGatewayReadiness ( runCommand , checkout , expectedSha , sleep ) ;
697726 } catch ( error ) {
698727 verificationError = error ;
699728 }
@@ -769,6 +798,7 @@ export function maintainMain(options, dependencies = {}) {
769798 const runCommand = dependencies . runCommand ?? defaultRunCommand ;
770799 const verifyMacTarget = dependencies . verifyMacTarget ?? defaultVerifyMacTarget ;
771800 const auditGatewayLogs = dependencies . auditGatewayLogs ?? defaultAuditGatewayLogs ;
801+ const sleep = dependencies . sleep ?? defaultSleep ;
772802 let gatewayLogAudit = null ;
773803 let queuedMacState = null ;
774804 if ( actions . macAppRebuild ) {
@@ -798,6 +828,7 @@ export function maintainMain(options, dependencies = {}) {
798828 checkout : update . checkout ,
799829 expectedSha : update . afterSha ,
800830 sinceMs : restartStartedAt ,
831+ sleep,
801832 } ) ;
802833 } else {
803834 try {
@@ -812,6 +843,7 @@ export function maintainMain(options, dependencies = {}) {
812843 checkout : update . checkout ,
813844 expectedSha : update . afterSha ,
814845 sinceMs : restartStartedAt ,
846+ sleep,
815847 } ) ;
816848 }
817849 }
0 commit comments