Recently we had a few reports[1] that in some cases esp_wifi_init function would fail with ESP_ERR_NVS_INVALID_STATE error.
These cases have been traced to the change from single app partition table to OTA partition table, without erasing NVS partition.
NVS library doesn't detect and handle cases when its partition is shrinked. The error would not always happen immediately, and could appear only when the space in the remaining NVS sectors got exhausted.
We will update NVS with additional code to handle such cases during nvs_flash_init, and add documentation about cases when NVS may fail to initialize.
For now we suggest using 'make erase_flash' command when changing the partition table layout.
[1]: https://github.com/espressif/arduino-esp32/issues/207