Skip to content

fix(autoresearch): arm WDT at top of setup() so boot hangs don't wedge COM port - #3552

Merged
zackees merged 1 commit into
masterfrom
fix/autoresearch-early-watchdog-arm
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/autoresearch-early-watchdog-arm

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at the top of loop(). If setup() hung — e.g., a null-deref inside an RPC bind lambda, a stalled singleton static-init, or a wedged serial handshake — no WDT was armed and the COM port stayed owned by a dead sketch until manual power-cycle. This turned every setup-phase bug into a lost port.

Change

  • Arm the unified WDT with a 20 s window at the very top of setup() via fl::Watchdog::instance().begin(AUTORESEARCH_SETUP_WATCHDOG_TIMEOUT_MS).
  • Feed the WDT inside the serial-monitor wait loop because on classic ESP32 (non-USB-CDC) that loop can span up to AUTORESEARCH_SERIAL_WAIT_MS = 120 s — far past the 20 s setup window.
  • FL_WATCHDOG_AUTO() at the top of loop() re-arms with the shorter loop-scoped timeout (5 s) once setup() has finished.

20 s is generous enough for cold boot (RPC handler registration for ~65 binds, PSRAM RX-buffer allocation, FastLED singleton init, driver enumeration) yet short enough that host-side autoresearch RPC timeouts (default 30 s) surface the reboot cleanly.

The low-memory autoResearchLowMemorySetup() path already arms the WDT via fl::Watchdog::instance().begin(3000), so that path is untouched.

Test plan

  • Compile clean: bash compile esp32dev --examples AutoResearch --no-filter — SUCCESS
  • Flash + boot on ESP32-WROOM via COM11 → device emits {\"type\":\"status\",\"ready\":true,...} heartbeats after WDT-driven recovery from a first-boot panic
  • Follow-up: root-cause the intermittent first-boot StoreProhibited panic in fl::json::json(const char*) — separate bug, WDT-recovery now unwedges the port

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved startup reliability by ensuring the device can recover from hangs during initialization instead of getting stuck waiting for a serial connection.
    • Added periodic watchdog feeding while waiting for the serial monitor, reducing the chance of an unresponsive boot.
    • Updated startup timing behavior so initialization and runtime now use appropriate watchdog timeouts.

…e COM port

Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at
the top of loop(). If setup() hung (RPC bind null-deref, stalled
static-init, wedged serial handshake), no WDT was armed and the COM
port stayed owned by a dead sketch until manual power-cycle.

Arm the WDT with a 20 s window at the very top of setup() so a hang
here auto-reboots. Feed the WDT in the serial-monitor wait loop
because on classic ESP32 (non-USB-CDC) that loop can span up to
AUTORESEARCH_SERIAL_WAIT_MS = 120 s, well past the setup WDT window.

FL_WATCHDOG_AUTO() at loop() top re-arms with the shorter loop-scoped
timeout once setup() has finished.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit d56f015 into master Jul 1, 2026
7 checks passed
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec8a7314-b231-41e3-84bf-1640ad7803b3

📥 Commits

Reviewing files that changed from the base of the PR and between 52459cb and 1acf70c.

📒 Files selected for processing (1)
  • examples/AutoResearch/AutoResearch.ino

📝 Walkthrough

Walkthrough

The AutoResearch example is updated to arm the watchdog explicitly at the start of setup() with a new longer timeout constant, and the serial readiness wait loop is changed to periodically feed the watchdog while waiting, preventing hangs before loop() begins.

Changes

AutoResearch Watchdog Setup Flow

Layer / File(s) Summary
Setup-phase watchdog arming and feeding
examples/AutoResearch/AutoResearch.ino
Adds AUTORESEARCH_SETUP_WATCHDOG_TIMEOUT_MS constant, arms the watchdog at the very start of setup() via fl::Watchdog::instance().begin(...), and replaces the blocking serial-wait with a loop that feeds the watchdog while waiting for fl::serial_ready(), with updated comments describing the two-stage timeout behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Setup as setup()
  participant Watchdog as fl::Watchdog
  participant Serial as fl::serial_ready()

  Setup->>Watchdog: begin(AUTORESEARCH_SETUP_WATCHDOG_TIMEOUT_MS)
  loop Waiting for serial monitor
    Setup->>Serial: check serial_ready()
    Setup->>Watchdog: feed()
  end
  Setup->>Setup: continue initialization
Loading

Possibly related PRs

  • FastLED/FastLED#2753: Also modifies AutoResearch.ino's watchdog arming/feeding flow around setup()/loop(), overlapping on the same watchdog initialization logic.
  • FastLED/FastLED#2763: Also changes AutoResearch.ino's watchdog begin/feed wiring around fl::Watchdog::begin() and FL_WATCHDOG_AUTO().
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/autoresearch-early-watchdog-arm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant