Skip to content

docs(conventions): codify noop fallback and FL_<COMPONENT>_HAS_* macro patterns - #2732

Merged
zackees merged 2 commits into
masterfrom
feat/agent-conventions-noop-impl-cpp-hpp
Jun 4, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/agent-conventions-noop-impl-cpp-hpp

Conversation

@zackees

@zackees zackees commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Two cross-cutting C++ conventions that were established by existing code but not previously written down. Codified in agents/docs/cpp-standards.md (authoritative source) and propagated to CodeRabbit, the /code-review command, and the c-cpp-expert + architecture-reviewer agents so that they get enforced consistently.

1. No-op fallback (*_noop.hpp in src/platforms/shared/)

  • Literal _noop suffix — not _null, _stub, _dummy, or _empty. The keyword noop is the grep marker for this pattern.
  • // IWYU pragma: private, inline functions in fl::platforms:: namespace.
  • Bodies return 0/false/nullptr/empty span — never assert or log.
  • Stub-only variant lives in src/platforms/stub/ with _stub_noop.h suffix.

Matches existing pin_noop.hpp, memory_noop.hpp, simd_noop.hpp, codec/h264_noop.hpp.

2. Type 3 component capability flags (FL_<COMPONENT>_HAS_<FEATURE>)

  • Spelled-out component names — no acronyms. If the public API is FastLED.watchdog(), the macros are FL_WATCHDOG_*, not FL_WDT_*. The macro identifier and the public API share one vocabulary so readers don't have to learn two names for the same thing.
  • Booleans: defined/undefined (no value).
  • Numeric properties: explicit values.
  • The _noop.hpp fallback defines none of the boolean flags but always defaults every numeric property to zero so user code compiles unconditionally.
  • Distinct from Type 1 (FL_IS_<PLATFORM>) and Type 2 (FASTLED_<NAME>).

Motivation

#2731 (unified cross-platform Watchdog Timer API) introduces both patterns at scale and needed an authoritative spec to reference.

Test plan

  • Docs-only PR — no code changes, no test surface
  • CI lint runs to confirm markdown / YAML parses

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Enhanced architectural and C++ standards: clearer platform dispatch and no-op fallback expectations, component capability flag rules, and naming/namespace guidance for maintainability.
    • Expanded code-review guidance with detailed checks for conformity, safety, and header/include practices.
  • Chores

    • Updated automated review/configuration to enforce repository-specific verification and review workflows.

…o patterns

Adds two cross-cutting conventions to cpp-standards.md (the authoritative source)
and propagates them to CodeRabbit, the /code-review command, and the c-cpp-expert
and architecture-reviewer agents:

1. No-op fallback (`*_noop.hpp` in `src/platforms/shared/`)
   - Literal `_noop` suffix; not `_null`, `_stub`, or `_dummy`
   - `// IWYU pragma: private`, inline functions in `fl::platforms::` namespace
   - Bodies return 0/false/nullptr — never assert or log
   - Matches existing pin_noop.hpp, memory_noop.hpp, simd_noop.hpp pattern

2. Type 3 component capability flags (`FL_<COMPONENT>_HAS_<FEATURE>`)
   - Spelled-out component names — no acronyms
   - If the API is `FastLED.watchdog()`, macros are `FL_WATCHDOG_*`, not `FL_WDT_*`
   - Boolean flags defined/undefined, numeric properties have explicit values
   - The `_noop.hpp` fallback defines no booleans, defaults all numerics to 0

Both conventions were established by existing code but not previously written down.
Codifies the keyword `noop` as the grep marker for the fallback pattern, and the
`.impl.cpp.hpp` / `.impl.hpp` suffix pair as the dispatcher/fragment naming.

Motivated by #2731 (unified watchdog API) — its noop fallback and
FL_WATCHDOG_* macros needed a place to point at.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Ignoring CodeRabbit configuration file changes. For security, only the configuration from the base branch is applied for open source repositories.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3fdddd1d-a5fb-4920-9809-960d3235a7df

📥 Commits

Reviewing files that changed from the base of the PR and between 828d9f3 and 33d2847.

📒 Files selected for processing (2)
  • .coderabbit.yaml
  • agents/docs/cpp-standards.md
✅ Files skipped from review due to trivial changes (2)
  • .coderabbit.yaml
  • agents/docs/cpp-standards.md

📝 Walkthrough

Walkthrough

This PR records documentation and configuration enforcing FastLED C++ conventions: a three-suffix platform-dispatch pattern (dispatcher/per-platform fragment/_noop fallback), strict no-op fallback header requirements, and Type 3 component capability macro naming. Updates touch core standards, AI reviewer guidance, code-review rules, and CodeRabbit path instructions.

Changes

Platform Dispatch and Capability Macro Standards

Layer / File(s) Summary
Core C++ conventions for platform fallbacks and capability flags
agents/docs/cpp-standards.md
Defines _noop.hpp no-op fallback placement (src/platforms/shared/), fl::platforms:: namespace use, ODR/include rules, strict no-op semantics (no asserts/throws/warnings), and capability-flag contract (no boolean FL_<COMPONENT>_HAS_<FEATURE> in no-op; numeric properties present). Adds Type 3 component capability flag rules (FL_<COMPONENT>_HAS_<FEATURE> boolean semantics and FL_<COMPONENT>_<NUMERIC> numeric semantics).
AI reviewer agent enforcement guidance
.claude/agents/architecture-reviewer-agent.md, .claude/agents/c-cpp-expert-agent.md
Adds three-suffix dispatch convention to agent reference material and C/C++ expert guidance: required dispatcher/fragment/_noop filenames and locations, exemplars, and enforcement checks; prescribes component-scoped FL_<COMPONENT>_... macro naming (spell out names, no acronyms).
Code review rules and automated configuration
.claude/commands/code_review.md, .coderabbit.yaml
Extends code-review checklist with platform dispatch/_noop/macro/header rules and other verification checks; updates CodeRabbit config to require reviews, enable pre-merge checks, and add path_instructions that enforce dispatcher/fragment/_noop naming, include patterns, and capability-macro conventions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through headers, tidy and neat,
Three suffixes tap-dance with tiny feet,
Macros spelled aloud, no cryptic acronyms near,
No-op fallbacks whisper: "compile without fear",
Docs, agents, and CI hum the same song—cheer! 🎶

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: codifying two specific documentation conventions (noop fallback patterns and FL_HAS* macro patterns) across agent documentation and configuration files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/agent-conventions-noop-impl-cpp-hpp

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
agents/docs/cpp-standards.md (1)

101-101: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Align fallback naming in the earlier router example with the new _noop standard.

The router sample still includes feature_null.impl.hpp, which now conflicts with the newly mandated _noop.hpp convention in the same document. Update the earlier example to avoid a self-contradicting spec.

Suggested doc fix
-// Fallback: null/no-op implementation
-#include "platforms/shared/feature_null.impl.hpp"
+// Fallback: no-op implementation
+#include "platforms/shared/feature_noop.hpp"

Based on learnings: "Read cpp-standards.md for writing/editing C++ code or creating API wrapper types".

Also applies to: 107-127

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@agents/docs/cpp-standards.md` at line 101, Replace the old fallback include
name to match the new `_noop` convention: change the include directive that
references "feature_null.impl.hpp" in the router example to the `_noop` variant
(e.g., "feature_noop.impl.hpp") and update all other occurrences in the same
section (lines ~107-127) so the document is consistent; ensure the router
example's fallback include and any mentions of FeatureNull/feature_null are
renamed to FeatureNoop/feature_noop as appropriate to match the `_noop` naming
convention.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.coderabbit.yaml:
- Around line 6-19: Update the dispatcher file glob and wording in
.coderabbit.yaml so the rule only matches root-level dispatcher files: change
the path from "src/platforms/**/*.cpp.hpp" to "src/platforms/*.impl.cpp.hpp" and
adjust the instruction text to refer to dispatcher filenames
`<component>.impl.cpp.hpp` located in `src/platforms/` (root), not in
subdirectories; keep the checks about `// IWYU pragma: private`, `#if
defined(FL_IS_*)` selection, `#else` fallback requiring `<component>_noop.hpp`,
and that included fragments use the `.impl.hpp` suffix.

In `@agents/docs/cpp-standards.md`:
- Line 120: The example uses the abbreviated macro FL_WDT_PERSIST_BYTES which
violates the Type 3 “no acronyms” rule; update the example and any related
mentions to use the spelled-out macro FL_WATCHDOG_PERSIST_BYTES instead, making
sure the no-op header guidance still shows numeric properties (e.g., `#define`
FL_WATCHDOG_PERSIST_BYTES 0) and that any explanatory text or other example
macros reference the new symbol for internal consistency with the
cpp-standards.md naming rule.
- Line 119: Update the rule text that currently mandates "return `0`, `false`,
`nullptr`, or empty span" to permit API-defined sentinel defaults by rewording
it to something like "return safe API-defined inert defaults (e.g., sentinel
values defined by the API) — never assert, throw, or call `FL_WARN`." Adjust the
explanatory sentence and examples to reference existing no-op exemplars (for
instance `src/platforms/shared/pin_noop.hpp` which returns `true` and `-4`) so
maintainers understand that returning documented sentinel values is acceptable
when they are the safe inert defaults for that API.

---

Outside diff comments:
In `@agents/docs/cpp-standards.md`:
- Line 101: Replace the old fallback include name to match the new `_noop`
convention: change the include directive that references "feature_null.impl.hpp"
in the router example to the `_noop` variant (e.g., "feature_noop.impl.hpp") and
update all other occurrences in the same section (lines ~107-127) so the
document is consistent; ensure the router example's fallback include and any
mentions of FeatureNull/feature_null are renamed to FeatureNoop/feature_noop as
appropriate to match the `_noop` naming convention.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bd6885f6-13f0-44fc-821e-786915545a54

📥 Commits

Reviewing files that changed from the base of the PR and between 7bbb414 and 828d9f3.

📒 Files selected for processing (5)
  • .claude/agents/architecture-reviewer-agent.md
  • .claude/agents/c-cpp-expert-agent.md
  • .claude/commands/code_review.md
  • .coderabbit.yaml
  • agents/docs/cpp-standards.md

Comment thread .coderabbit.yaml Resolved
Comment thread agents/docs/cpp-standards.md Resolved
Comment thread agents/docs/cpp-standards.md Resolved
- Use spelled-out FL_WATCHDOG_PERSIST_BYTES (not FL_WDT_PERSIST_BYTES)
  in cpp-standards.md no-op example to match Type 3 "no acronyms" rule.
- Relax no-op body convention to permit documented API sentinel
  defaults (true, -4, etc.) so existing pin_noop.hpp exemplars stay
  conformant.
- Narrow .coderabbit.yaml dispatcher path glob from
  src/platforms/**/*.cpp.hpp to src/platforms/*.impl.cpp.hpp so the
  rule no longer misclassifies translation-unit fragments as
  dispatchers.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit ae6785b into master Jun 4, 2026
13 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 4, 2026
zackees added a commit that referenced this pull request Jun 4, 2026
…impls (#2738)

* feat(watchdog): Phase 1 — unified fl::Watchdog API + host/stub/ESP32 impls

Lands the cross-platform watchdog API designed in #2731:

**Public surface** — `FastLED.watchdog()` accessor returning `fl::Watchdog&`,
matching the `FastLED.channelEvents()` singleton pattern. Three tiers:
- Tier 0 (universal): begin/feed/disable, lastResetCause, persist read/write,
  consecutiveCrashCount, markCleanShutdown, isInSafeMode, reboot
- Tier 1 (most platforms): onTimeout (C pointer + fl::function overload),
  setPauseOnDebug, writeCrashLog, readCrashLog, rebootIntoBootloader
- Tier 2 (advanced): setWindow, hasCrashReport, readCrashReport

**Architecture** — follows the conventions landed in #2732:
- `src/fl/wdt/watchdog.h` public header with the API + `instance()` defined
  inline so every TU resolves the singleton call
- `src/platforms/watchdog.impl.cpp.hpp` single dispatcher (matches
  coroutine.impl.cpp.hpp / channel_drivers.impl.cpp.hpp pattern)
- `src/platforms/shared/watchdog_noop.hpp` no-op fallback (matches
  memory_noop.hpp / pin_noop.hpp / simd_noop.hpp pattern)
- Per-platform `.impl.hpp` fragments included by the dispatcher

**Platform impls (Phase 1)**:
- `platforms/stub/watchdog_stub.impl.hpp` — thread-backed deadline timer,
  fully tested; the stub never std::abort()s the test process so unit
  tests can verify crash-counter / safe-mode behavior
- `platforms/wasm/watchdog_wasm.impl.hpp` — currently routes to the noop
  fallback (emscripten timer integration is its own follow-up)
- `platforms/esp/32/watchdog_esp32.impl.hpp` — wraps the existing
  `fl::watchdog_setup()` entry; preserves the weak-symbol panic override
  and USB-CDC disconnect that fix the Windows phantom-COM-port bug
- All other platforms fall through to the noop fallback for now

**Tests** — `tests/fl/wdt/watchdog.cpp` exercises the full Tier 0 + Tier 1
surface against the stub impl: singleton accessor, begin/feed/disable,
persist storage, safe-mode threshold, crash counter, timeout firing,
feeding-prevents-fire, safe-mode trip. 15/15 pass on host.

**Capability macros** (Type 3 per cpp-standards.md):
- `FL_WATCHDOG_HAS_HARDWARE` — 1 on stub + ESP32, undefined on noop platforms
- `FL_WATCHDOG_PERSIST_BYTES` — 16 on stub/ESP32, 0 on noop
- `FL_WATCHDOG_MAX_TIMEOUT_MS` — 600000 on stub, 60000 on ESP32, 0 on noop
- `FL_WATCHDOG_HAS_PRE_TIMEOUT_IRQ`, `FL_WATCHDOG_HAS_WINDOW_MODE`,
  `FL_WATCHDOG_HAS_CRASH_REPORT` — set per platform

**Phase 2+** (tracked in #2731): Teensy 4 (`WDT_T4<WDT3>`), Teensy 3.x,
RP2040/2350, nRF52, STM32, SAMD21/51, AVR, Apollo3, MGM240, WASM
emscripten-emulated impl. Each remaining platform compiles unconditionally
through the noop fallback until its hardware impl lands.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(watchdog): address CodeRabbit review on Phase 1 watchdog PR

- Move Watchdog::instance() definition out of public header into each
  per-platform .impl.hpp / watchdog_noop.hpp so the function-local static
  lives in exactly one TU. Header now declares the accessor only — avoids
  the Teensy 3.x __cxa_guard ABI conflict that header-side function-local
  statics trigger across every TU that includes FastLED.h.

- ESP32: serialize crash_count into the trailing 2 bytes of persist[] so
  consecutive-crash bookkeeping survives the move to RTC_NOINIT_ATTR /
  __NOINIT_ATTR in Phase 2 without further code change. persistRead/Write
  bounds shrunk to the user-visible kUserBytes window.

- ESP32: cache the armed timeout in Esp32WatchdogState so onTimeout()
  reuses it instead of silently re-arming at 5000 ms. begin(30000) +
  onTimeout(cb) now keeps the 30 s window.

- ESP32: disable() now re-arms the backend with FL_WATCHDOG_MAX_TIMEOUT_MS
  rather than silently leaving it ticking with the previous (shorter)
  timeout. Real TWDT teardown via esp_task_wdt_deinit() is still tracked
  in #2731 Phase 2; the interim behavior at least honors "no surprise
  resets during a disable window."

- Stub: drop FL_WATCHDOG_HAS_WINDOW_MODE and return false from
  setWindow(). The stub never modeled min/max-feed enforcement — the
  macro was lying to user code that branches on the capability flag.

- Stub: convert reset_was_watchdog and fired to fl::atomic<bool>,
  resolving the data race between the timer-thread writes and API-side
  reads/clears. Eliminates flake under TSAN-like builds.

- Stub: separate intentional Watchdog::reboot() from watchdog-induced
  resets. reboot() now flips a software_reboot atomic flag — does not
  bump crash_count and does not mark the reset as watchdog-induced.
  lastResetCause() reports SOFTWARE for reboots and WATCHDOG for
  timeouts. clearCrashReport() no longer flips lastResetCause() back to
  POWER_ON.

- Tests: derive persist-boundary indices from a single-source mirror of
  FL_WATCHDOG_PERSIST_BYTES (the capability macro is private to the
  impl TU). The boundary at idx == FL_WATCHDOG_PERSIST_BYTES is now
  exercised explicitly instead of via 9999.

- Tests: replace static volatile bool fired with static fl::atomic<bool>
  fired (with .store() / .load()) in the two timeout test cases. volatile
  is not a thread-safety primitive in C++ — atomic is required for the
  worker-thread → test-thread visibility contract.

- Tests: update the setWindow case to expect false (matches the stub now
  honestly reporting "no window mode" via the dropped capability macro).

Verified: bash test fl_wdt_watchdog --debug (15/15 pass with sanitizers),
bash test --cpp (309/309 pass), bash lint clean.

Addresses CodeRabbit comments 3353133142, 3353133149, 3353133154,
3353133155, 3353133161, 3353133164, 3353133166, 3353133174, 3353133179 on
PR #2738.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(watchdog): promote stub crash_count to fl::atomic<u16>

Addresses CodeRabbit review on PR #2738.

`StubWatchdogPersist::crash_count` was the last cross-thread field still
on plain memory after the earlier fix made `reset_was_watchdog` / `fired`
/ `software_reboot` atomic. The watchdog timer thread bumped it in
`stubWatchdogReset()` while `consecutiveCrashCount()`, `isInSafeMode()`,
and `markCleanShutdown()` read/wrote it from the test thread — a genuine
data race that TSAN would flag.

Promote `crash_count` to `fl::atomic<fl::u16>` and use a saturating CAS
loop in the worker-side increment so a concurrent `markCleanShutdown()`
reset isn't lost and the counter still pins at 0xFFFF instead of
rolling over.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(watchdog): real ESP32 disable() teardown via fl::watchdog_disable()

Addresses CodeRabbit follow-up on PR #2738: Watchdog::disable() on ESP32
previously re-armed the TWDT at max timeout instead of tearing it down,
which left the watchdog still capable of firing after a documented disable.

This adds a public `fl::watchdog_disable()` entry to watchdog_esp32.h that
wraps the existing internal `deinit_existing_watchdog()` helper (already
guarded against being called before the FreeRTOS scheduler runs). Defined
in both watchdog_esp32_idf4.hpp and watchdog_esp32_idf5.hpp; clears the
user callback state on teardown for both IDF versions.

Watchdog::disable() now calls fl::watchdog_disable() so the Tier-0 contract
is honored: after disable(), the watchdog truly does not fire on the
registered idle task.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(watchdog): propagate esp_task_wdt_deinit() failure through disable()

Addresses CodeRabbit follow-up on PR #2738: previously
fl::watchdog_disable() and Watchdog::disable() ignored
esp_task_wdt_deinit()'s esp_err_t return. Per ESP-IDF docs that call can
fail (other tasks still subscribed, already deinitialized, scheduler
not running) and on failure the TWDT remains active — so reporting
"disabled" while the WDT can still fire is wrong.

Changes:
- `deinit_existing_watchdog()` now returns bool (true iff esp_task_wdt_deinit
  returned ESP_OK, or if there was nothing to tear down)
- `fl::watchdog_disable()` returns bool, only clears the stored user
  callback/data on successful teardown
- `Watchdog::disable()` only clears `armed`/`armed_timeout_ms` on success;
  on failure the local state stays armed so subsequent calls don't lie
- The two existing internal call sites that ignored the return get an
  explicit `(void)` cast with a comment ("best-effort deinit before re-init")

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/agent-conventions-noop-impl-cpp-hpp branch August 21, 2026 19:15
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