@@ -12,6 +12,8 @@ INSTALL_PACKAGE_IMPORT_METHOD="${CORTEXPILOT_DESKTOP_PNPM_IMPORT_METHOD:-copy}"
1212INSTALL_SHAMEFULLY_HOIST=" ${CORTEXPILOT_DESKTOP_PNPM_SHAMEFULLY_HOIST:- 1} "
1313BASE_INSTALL_NODE_LINKER=" $INSTALL_NODE_LINKER "
1414BASE_INSTALL_SHAMEFULLY_HOIST=" $INSTALL_SHAMEFULLY_HOIST "
15+ NETWORK_RETRY_ATTEMPTS=2
16+ NETWORK_RETRY_SLEEP_SECONDS=5
1517INSTALL_LOG=" $ROOT_DIR /.runtime-cache/logs/runtime/deps_install/install_desktop_deps.log"
1618LOCK_DIR=" $ROOT_DIR /.runtime-cache/cortexpilot/locks/install-desktop-deps.lock"
1719LOCK_OWNER_FILE=" $LOCK_DIR /owner"
@@ -159,6 +161,36 @@ run_install() {
159161 )
160162}
161163
164+ install_log_has_socket_timeout () {
165+ [[ -f " $INSTALL_LOG " ]] || return 1
166+ local content=" "
167+ content=" $( < " $INSTALL_LOG " ) "
168+ [[ " $content " == * " ERR_SOCKET_TIMEOUT" * || " $content " == * " Socket timeout" * ]]
169+ }
170+
171+ run_install_with_network_retry () {
172+ local context=" $1 "
173+ local attempt=0
174+ while true ; do
175+ if run_install; then
176+ return 0
177+ fi
178+ if ! install_log_has_socket_timeout; then
179+ return 1
180+ fi
181+ if (( attempt >= NETWORK_RETRY_ATTEMPTS )) ; then
182+ return 1
183+ fi
184+ attempt=$(( attempt + 1 ))
185+ echo " ⚠️ [install-desktop-deps] ${context} ; transient npm registry socket timeout detected; retrying install (${attempt} /${NETWORK_RETRY_ATTEMPTS} )" >&2
186+ sleep " $NETWORK_RETRY_SLEEP_SECONDS "
187+ if ! reset_app_node_modules; then
188+ tail -n 80 " $INSTALL_LOG " >&2 || true
189+ exit 1
190+ fi
191+ done
192+ }
193+
162194verify_typescript_toolchain () {
163195 (
164196 cd " $APP_DIR "
@@ -175,12 +207,17 @@ recover_with_fresh_store() {
175207 tail -n 80 " $INSTALL_LOG " >&2 || true
176208 exit 1
177209 fi
178- if ! run_install ; then
210+ if ! run_install_with_network_retry " fresh-store recovery install " ; then
179211 if grep -q " ERR_PNPM_ENOENT" " $INSTALL_LOG " ; then
180212 echo " ⚠️ [install-desktop-deps] fresh-store recovery hit another ERR_PNPM_ENOENT; escalating to workspace-local pnpm store recovery" >&2
181213 recover_with_workspace_store " fresh-store ERR_PNPM_ENOENT persisted after desktop retry"
182214 return 0
183215 fi
216+ if install_log_has_socket_timeout; then
217+ echo " ❌ [install-desktop-deps] fresh-store recovery exhausted transient npm registry retries; tail follows" >&2
218+ tail -n 80 " $INSTALL_LOG " >&2 || true
219+ exit 1
220+ fi
184221 echo " ❌ [install-desktop-deps] pnpm install failed after fresh-store recovery; tail follows" >&2
185222 tail -n 80 " $INSTALL_LOG " >&2 || true
186223 exit 1
@@ -206,10 +243,15 @@ recover_with_workspace_store() {
206243 tail -n 80 " $INSTALL_LOG " >&2 || true
207244 exit 1
208245 fi
209- if ! run_install ; then
246+ if ! run_install_with_network_retry " workspace-local recovery install " ; then
210247 INSTALL_PACKAGE_IMPORT_METHOD=" $previous_import_method "
211248 INSTALL_NODE_LINKER=" $previous_node_linker "
212249 INSTALL_SHAMEFULLY_HOIST=" $previous_shamefully_hoist "
250+ if install_log_has_socket_timeout; then
251+ echo " ❌ [install-desktop-deps] workspace-local recovery exhausted transient npm registry retries; tail follows" >&2
252+ tail -n 80 " $INSTALL_LOG " >&2 || true
253+ exit 1
254+ fi
213255 echo " ❌ [install-desktop-deps] pnpm install failed after workspace-local recovery; tail follows" >&2
214256 tail -n 80 " $INSTALL_LOG " >&2 || true
215257 exit 1
@@ -238,18 +280,22 @@ reset_app_node_modules() {
238280 return 1
239281}
240282
241- if ! run_install ; then
283+ if ! run_install_with_network_retry " initial install " ; then
242284 if grep -q " ERR_PNPM_ENOENT" " $INSTALL_LOG " ; then
243285 recover_with_fresh_store " detected pnpm store ENOENT"
244286 elif grep -q " ERR_PNPM_ENOSPC" " $INSTALL_LOG " || grep -qi " no space left on device" " $INSTALL_LOG " ; then
245287 recover_with_workspace_store " detected pnpm ENOSPC"
288+ elif install_log_has_socket_timeout; then
289+ echo " ❌ [install-desktop-deps] pnpm install failed after transient npm registry retries; tail follows" >&2
290+ tail -n 80 " $INSTALL_LOG " >&2 || true
291+ exit 1
246292 elif grep -q " ERR_PNPM_ENOTDIR" " $INSTALL_LOG " ; then
247293 echo " ⚠️ [install-desktop-deps] detected app-local node_modules ENOTDIR; resetting desktop node_modules and retrying once" >&2
248294 if ! reset_app_node_modules; then
249295 tail -n 80 " $INSTALL_LOG " >&2 || true
250296 exit 1
251297 fi
252- if ! run_install ; then
298+ if ! run_install_with_network_retry " node_modules reset retry " ; then
253299 echo " ❌ [install-desktop-deps] pnpm install failed after node_modules reset; tail follows" >&2
254300 tail -n 80 " $INSTALL_LOG " >&2 || true
255301 exit 1
0 commit comments