From e88532a64e30154f75db083d8df0a9f5ef58423e Mon Sep 17 00:00:00 2001 From: DatanoiseTV <6614616+DatanoiseTV@users.noreply.github.com> Date: Fri, 8 May 2026 21:56:45 +0200 Subject: [PATCH 1/2] sleep: replace assert(0) on stuck preflight with controlled restart waitEnterSleep panicked with assert(0) when an observer vetoed sleep for >30s (FIXME #167). On a field device that turns into a noisy crash log every 30s rather than a clean reboot. Use the same per-arch restart primitives Power::reboot uses, fall back to assert only for archs we don't have a primitive for. --- src/sleep.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/sleep.cpp b/src/sleep.cpp index 792781f6d0d..769b9d7b26f 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -195,7 +195,26 @@ static void waitEnterSleep(bool skipPreflight = false) if (!Throttle::isWithinTimespanMs(now, THIRTY_SECONDS_MS)) { // If we wait too long just report an error and go to sleep RECORD_CRITICALERROR(meshtastic_CriticalErrorCode_SLEEP_ENTER_WAIT); - assert(0); // FIXME - for now we just restart, need to fix bug #167 + // FIXME issue #167: a misbehaving observer can veto sleep forever. + // Restart cleanly rather than panicking — same effective recovery, + // no core-dump pollution, and the firmware can come back up with a + // working state machine instead of triggering the panic handler. + LOG_ERROR("Preflight sleep wait exceeded 30s, restarting"); + // Notify reboot observers (e.g. InkHUD) so they can persist / + // shut down cleanly, matching Power::reboot's contract. + notifyReboot.notifyObservers(NULL); + console->flush(); +#if defined(ARCH_ESP32) + ESP.restart(); +#elif defined(ARCH_NRF52) + NVIC_SystemReset(); +#elif defined(ARCH_RP2040) + rp2040.reboot(); +#elif defined(ARCH_STM32WL) + HAL_NVIC_SystemReset(); +#else + assert(0); // fallback for archs without a clean restart primitive +#endif break; } } From f7d99caa8f71fcfe1fc9d5d85ab3352b4e746ca9 Mon Sep 17 00:00:00 2001 From: Sylwester Date: Mon, 18 May 2026 06:27:01 +0200 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/sleep.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sleep.cpp b/src/sleep.cpp index 769b9d7b26f..b58cde88bb9 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -212,6 +212,8 @@ static void waitEnterSleep(bool skipPreflight = false) rp2040.reboot(); #elif defined(ARCH_STM32WL) HAL_NVIC_SystemReset(); +#elif defined(ARCH_PORTDUINO) + ::reboot(); #else assert(0); // fallback for archs without a clean restart primitive #endif