Repository navigation
Description
Background
Surveyed CodeRabbit's findings across 94 PRs updated 2026-05-20 → 2026-06-03 (59 had CodeRabbit activity, ~95 substantive findings examined). ~68% of findings were preventable at code-generation time with a written rule. The rules below cover the top recurring themes that a written agents/docs/cpp-standards.md rule would have prevented — i.e., rules that LLMs and humans should follow before code is even written.
Two related artifacts already exist:
- PR docs(cpp): enforce Public Settings Pattern for global setters #2715 — Public Settings Pattern (god-instance setter requirement)
- PR feat(lint): enforce Public Settings Pattern for fl:: global setters (layer 5) #2716 — syntactic lint checker for the Public Settings Pattern
This issue captures the remaining 8 documentation gaps surfaced by the survey.
Rules to add to agents/docs/cpp-standards.md
Tier 1 — biggest leverage (would have prevented ~16 findings)
-
Singleton ownership: own profile/config by value, never by borrowed pointer. Any public
fl::set_*(const T*)that stashes the pointer in process-wide state must takeconst T&and copy. Use-after-scope is otherwise deterministic when callers pass a stack temporary. Prevented findings in fix(rgbw): address CodeRabbit findings from #2552 #2554, feat(rgbww): 5-channel RGB+WW pipeline via Channels API (#2558 Phases A-F) #2560, fix(rgbww): own profile copy in singleton (meta #2580 A4) #2588, fix(io): finish fl::print minimal-surface contract for hosts (closes #2668) #2683, feat(parlio): land c6 streaming diagnostics #2682. -
Cache invalidation contract for in-place mutation APIs. If
set_X(T* obj, ...)rewrites fields of*objand any subsystem caches values derived from*objkeyed only on(obj_ptr, ...), the setter must bump a version counter and the cache key must include it. Prevented fix(rgbw): address CodeRabbit findings from #2552 #2554, fix(rgbw): zero-init failed cache matrices + drop duplicate comment (meta #2580 B1+B7) #2589, fix(rgbw): source RGB color space + differentiated boosted solver + Hermite LUT #2707, fix(rgbw): default source = native LED gamut + D65; named-gamut opt-in #2711. -
Contract Change Fanout (broaden the existing §595–604 "API unit change" rule). Any change that widens / narrows a numeric bound, enum range, or struct shape on a public surface must touch (a) producer, (b) validator, (c) tests, (d) docs, (e) debug-metrics struct in one PR. Prevented docs(autoresearch): rewrite JSON-RPC reference to match bound methods #2621, fix(esp32-s3): LCD_CLOCKLESS chunk-ISR IRAM/ISR-safety + equal-chunk (#2647 WIP) #2648, fix(esp32c6): route Serial to HWCDC + non-blocking writes (#2665) #2669, feat(parlio): land c6 streaming diagnostics #2682.
-
`fl::span` rule — extend the shape table with two missing forms. Existing rule covers function parameters but repeatedly missed: (a) callback typedefs like `fl::function<...(const u8*, size_t)>`, (b) small fixed-size arrays like `const float xy[2]`. Prevented feat(rgbww): 5-channel RGB+WW pipeline via Channels API (#2558 Phases A-F) #2560, fix(io): finish fl::print minimal-surface contract for hosts (closes #2668) #2683, fix(rgbw): default source = native LED gamut + D65; named-gamut opt-in #2711.
Tier 2 — narrower but real recurrence (would have prevented ~7 findings)
-
ISR-shared state uses `fl::atomic` or `portENTER_CRITICAL`. Fields touched by both an ISR callback and task context must be `fl::atomic` (explicit memory order) or guarded by `portENTER_CRITICAL_ISR/portEXIT_CRITICAL_ISR`. Plain `volatile` is not sufficient. Prevented feat(parlio): land c6 streaming diagnostics #2682, fix: stream ESP32-S3 LCD clockless chunks #2703. NOTE: `fl::atomic`, not `std::atomic` — FastLED disallows `std::` except for a narrow exception list (
std::move,std::forward, low-level metaprogramming traits). -
Unsigned narrowing cast must clamp. Sibling to the existing signed-overflow rule. `static_cast(red + green / 3)` silently wraps when the sum exceeds 255 — defined but wrong behavior. Prevented feat(rgbww): 5-channel RGB+WW pipeline via Channels API (#2558 Phases A-F) #2560 (flagged twice).
-
Test mirrors must call production symbols, not redeclare them. When test code mirrors a production implementation, the test must exercise the production symbol directly. Local re-definitions silently pass through production regressions. Prevented fix(io): finish fl::print minimal-surface contract for hosts (closes #2668) #2683, fix(rgbw): source RGB color space + differentiated boosted solver + Hermite LUT #2707, fix(rgbw): NNLS out-of-hull projection (#2708) + in-test ground truth #2709.
Tier 3 — polish (cheap to add, prevents ~4 findings)
- ASCII-only in source files. C++ source files (`.h`, `.cpp`, `.hpp`, `.cpp.hpp`) and Python sources MUST be 7-bit ASCII. No emoji (`
⚠️ `), no Unicode math glyphs (`×`, `−`, `ρ`, `∆`). Use text prefixes (`WARNING:`, `NOTE:`) instead. Prevented fix(esp32-s3): LCD_CLOCKLESS chunk-ISR IRAM/ISR-safety + equal-chunk (#2647 WIP) #2648, fix(rgbw): NNLS out-of-hull projection (#2708) + in-test ground truth #2709.
Dropped from earlier draft
- Mirror KeyboardInterrupt rule into `python-standards.md` — already present at lines 17–46 of `agents/docs/python-standards.md`.
Survey statistics
```
PRs surveyed: 94
PRs with any CodeRabbit comment/review: 59
Substantive findings examined: ~95
Classified as preventable-at-gen: ~65 (≈68%)
Findings the new rules would have caught: ~27
Findings reinforcing existing rules: ~14 (covered in PR bodies)
```
Out of scope for this issue
Findings that cannot be prevented by a documentation rule:
- Behavioral correctness of timing-sensitive ESP32 ISR code (Fix AutoResearch lane limits and LCD chunk sizing #2691, fix: stream ESP32-S3 LCD clockless chunks #2703, feat(parlio): land c6 streaming diagnostics #2682 underrun races) — needs hardware testing
- PyPI version availability (chore: bump zccache pin to >=1.11.9 #2670, Pin fbuild 2.2.16 for ESP32-C2 #2704) — needs registry lookup
- Doc-vs-implementation drift in `agents/docs/hardware-autoresearch.md` (docs(autoresearch): rewrite JSON-RPC reference to match bound methods #2621) — should be generated from firmware manifest
- Domain-specific colorimetric bugs (fix(rgbw): source RGB color space + differentiated boosted solver + Hermite LUT #2707 eta in emitter space) — review-time judgment
- Workflow CI strictness (feat(stm32): add Arduino UNO Q support #2678 UNO-Q only builds Blink) — judgment
Plan
Single PR adds all 8 rules to `agents/docs/cpp-standards.md`, following the existing rule style (Core Principle / ❌ Bad / ✅ Good / Rationale / Check Process). Linked to this issue via `Closes #XXXX`.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
docs(cpp): add 8 code-gen rules from 2-week CodeRabbit survey (closes F…