Skip to content

fix(power): replace assert(0) on stuck preflight with controlled restart#10441

Open
DatanoiseTV wants to merge 2 commits into
meshtastic:developfrom
DatanoiseTV:fix/power-preflight-restart
Open

fix(power): replace assert(0) on stuck preflight with controlled restart#10441
DatanoiseTV wants to merge 2 commits into
meshtastic:developfrom
DatanoiseTV:fix/power-preflight-restart

Conversation

@DatanoiseTV
Copy link
Copy Markdown
Contributor

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.

Split out from #10425 — single-concern PR.

Build verification

pio run -e t-deck-tft succeeds, no new warnings.

Attestations

  • I have tested that my proposed changes behave as described — review/static-analysis only, not on-air.
  • On-hardware testing requested from community: build-verified t-deck-tft only.

waitEnterSleep panicked with assert(0) when an observer vetoed sleep
for >30s (FIXME meshtastic#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.
@github-actions github-actions Bot added needs-review Needs human review bugfix Pull request that fixes bugs labels May 9, 2026
@thebentern thebentern requested a review from Copilot May 9, 2026 11:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes the sleep preflight timeout handling to avoid repeated assert(0) panics when a sleep-preflight observer vetoes sleep for longer than 30 seconds, replacing the panic with a controlled, per-architecture reboot sequence (mirroring Power::reboot’s intent).

Changes:

  • Replace the 30s preflight timeout assert(0) with a logged, observer-notified restart using per-arch reset primitives.
  • Notify notifyReboot observers and flush the console before restarting to allow components to persist/cleanup.

Comment thread 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
Comment thread src/sleep.cpp
Comment thread src/sleep.cpp
Comment on lines +202 to 218
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;
@cvaldess
Copy link
Copy Markdown
Contributor

Tested on Nordic nRF54L15-DK (stacked with the other Tier-1 hardening
PRs on a single experiment branch).

LGTM.

Tested-by: cvaldess

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Pull request that fixes bugs needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants