Skip to content

Add 8 new C++ code-gen rules to cpp-standards.md from 2-week CodeRabbit survey #2717

Closed

Description

@zackees

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:

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)

  1. 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 take const 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.

  2. Cache invalidation contract for in-place mutation APIs. If set_X(T* obj, ...) rewrites fields of *obj and any subsystem caches values derived from *obj keyed 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.

  3. 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.

  4. `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)

  1. 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).

  2. 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).

  3. 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)

  1. 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:

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

Activity

  1. moved this from Triage to Done in FastLED Trackeron Jun 4, 2026
  2. added a commit that references this issue on Jun 4, 2026
    cf80f80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions