diff --git a/misc/api.func b/misc/api.func index 1888412c7..25d269366 100644 --- a/misc/api.func +++ b/misc/api.func @@ -687,18 +687,23 @@ EOF [[ "${DEV_MODE:-}" == "true" ]] && echo "[DEBUG] Sending to: $TELEMETRY_URL" >&2 [[ "${DEV_MODE:-}" == "true" ]] && echo "[DEBUG] Payload: $JSON_PAYLOAD" >&2 - # Fire-and-forget: never block, never fail - local http_code - if [[ "${DEV_MODE:-}" == "true" ]]; then - http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ - -H "Content-Type: application/json" \ - -d "$JSON_PAYLOAD" -o /dev/stderr 2>&1) || true - echo "[DEBUG] HTTP response code: $http_code" >&2 - else - curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ - -H "Content-Type: application/json" \ - -d "$JSON_PAYLOAD" &>/dev/null || true - fi + # Send initial "installing" record with retry. + # This record MUST exist for all subsequent updates to succeed. + local http_code="" attempt + for attempt in 1 2 3; do + if [[ "${DEV_MODE:-}" == "true" ]]; then + http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ + -H "Content-Type: application/json" \ + -d "$JSON_PAYLOAD" -o /dev/stderr 2>&1) || http_code="000" + echo "[DEBUG] post_to_api attempt $attempt HTTP=$http_code" >&2 + else + http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ + -H "Content-Type: application/json" \ + -d "$JSON_PAYLOAD" -o /dev/null 2>/dev/null) || http_code="000" + fi + [[ "$http_code" =~ ^2[0-9]{2}$ ]] && break + [[ "$attempt" -lt 3 ]] && sleep 1 + done POST_TO_API_DONE=true } @@ -789,10 +794,15 @@ post_to_api_vm() { EOF ) - # Fire-and-forget: never block, never fail - curl -fsS -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ - -H "Content-Type: application/json" \ - -d "$JSON_PAYLOAD" &>/dev/null || true + # Send initial "installing" record with retry (must succeed for updates to work) + local http_code="" attempt + for attempt in 1 2 3; do + http_code=$(curl -sS -w "%{http_code}" -m "${TELEMETRY_TIMEOUT}" -X POST "${TELEMETRY_URL}" \ + -H "Content-Type: application/json" \ + -d "$JSON_PAYLOAD" -o /dev/null 2>/dev/null) || http_code="000" + [[ "$http_code" =~ ^2[0-9]{2}$ ]] && break + [[ "$attempt" -lt 3 ]] && sleep 1 + done POST_TO_API_DONE=true }