Skip to content

perf(autoresearch): collapse per-byte + per-edge FL_WARN dumps (fbuild#755) - #3342

Merged
zackees merged 3 commits into
masterfrom
loop/3219-autoresearch-warn-audit
Jun 22, 2026
Merged

zackees merged 3 commits into
masterfrom
loop/3219-autoresearch-warn-audit

Conversation

@zackees

@zackees zackees commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Direct follow-up to FastLED/fbuild#755 ("audit and remove as much as possible FL_WARN in autoresearch") and the wrapper-side work merged in #3341. Cuts three high-volume FL_WARN sites in examples/AutoResearch/AutoResearchTest.cpp so the device's UART TX FIFO stops being the gating bottleneck on bursty autoresearch tests.

Changes

Site Before After
Per-byte capture dump 26 FL_WARNs/pattern (2 headers + 24 byte lines) 1 FL_WARN/pattern with hex string
Decode-failure raw-edge dump callers EdgeRange(0, 256) EdgeRange(0, 32)
dumpRawEdgeTiming() body 1 FL_WARN per edge 1 collated FL_WARN with all edges

Net effect

4-pattern OBJECT_FLED test with one decode failure:

  • Before: ~360 FL_WARN lines per test (104 byte dumps + ~257 raw-edge)
  • After: ~37 FL_WARN lines per test (4 byte dumps + ~33 raw-edge)
  • ~10x reduction in serial-line traffic

Test plan

  • bash lint --cpp — green
  • On-hardware autoresearch validation deferred: there's a pre-existing fbuild prototype-generator linkage conflict on startup_early_hook that's blocking the autoresearch deploy path right now. Unrelated to this change. Will validate once that's unblocked.

Context

fbuild#755 calls out this exact [CORRUPTION @ LED X] + per-byte verbosity as the dominant UART backpressure source after fbuild#750 fixed the daemon-side bridge. This PR is the first step in that audit.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added session-level tracking for RPC send attempts via a new sent_count property, with an optional verbose summary when the client closes.
  • Bug Fixes
    • Improved FlexIO RX wait behavior by treating empty-buffer captures as a timeout result to avoid continuing with decode on all-zero data.
  • Chores
    • Reduced and reformatted diagnostic edge timing and captured-data logging to be more compact, including fewer edges dumped after decode failures and a single-line hex preview for multi-run captures.

…ild#755)

Three high-volume FL_WARN sites in AutoResearchTest.cpp were dominating
the Teensy 4 UART TX FIFO and stalling autoresearch between patterns
when the wrapper consumed serial output. Even with fbuild #750's
daemon-side batching fix, the device-side TX backpressure remained
measurable on bursty 100-LED tests.

1) Per-byte capture dump (was line 809-814):
   - BEFORE: 2 header FL_WARNs + 24 individual `  [N] = 0xff` lines
     = 26 FL_WARNs per pattern per run. 4-pattern test = 104 lines.
   - AFTER:  single FL_WARN with space-separated hex string
     = 1 FL_WARN per pattern per run. 4-pattern test = 4 lines.
   - Diagnostic value preserved (same 24 bytes, same hex format,
     same per-pattern context). Drops UART output by ~2.0 KB per test.

2) Raw-edge dump on decode failures (3 callers):
   - BEFORE: `EdgeRange(0, 256)` -- up to 257 FL_WARN lines per
     failure path. UART totally swamped on a single decode error.
   - AFTER:  `EdgeRange(0, 32)` -- 33 FL_WARN lines per failure.
     Still enough to see whether the first transition is a clean
     bit-0 or a glitch. ~8x reduction per failure.

3) `dumpRawEdgeTiming()` body itself (was line 64-71):
   - BEFORE: one FL_WARN per edge (1 + N lines).
   - AFTER:  single collated FL_WARN with all edges in compact
     `H580 L640 H586 L640` notation. Reads the same; ships in
     one WebSocket frame instead of N.

Net effect on a 4-pattern OBJECT_FLED test with one decode failure:
  Before: ~26*4 (per-byte) + ~257 (raw-edge) = ~360 FL_WARN lines.
  After:  ~4 (per-byte) + ~33 (raw-edge) = ~37 FL_WARN lines.
  ~10x reduction in serial-line traffic per test.

C++ lint passes. Hardware validation deferred -- there's a pre-
existing fbuild prototype-generator linkage conflict on
`startup_early_hook` that's blocking the autoresearch deploy path
on this branch; unrelated to this change.

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

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Three independent changes are made: diagnostic logging in AutoResearchTest.cpp is condensed by emitting single-line FL_WARN messages for edge timings and byte dumps instead of per-item loops, while edge dump counts are reduced from 256 to 32 on three decode-failure paths; separately, RpcClient tracks session-level RPC send attempt count, exposed via sent_count property, incremented on each send/send_and_match attempt, and reported in verbose close summary; additionally, FlexIoRxChannelImpl::wait() simplifies timeout diagnostics and reclassifies empty buffer captures (zero DMA transfers) as TIMEOUT instead of SUCCESS.

Changes

Debug Output Consolidation

Layer / File(s) Summary
Single-line collated debug output
examples/AutoResearch/AutoResearchTest.cpp
dumpRawEdgeTiming() replaces a per-edge FL_WARN loop with one compact space-separated H<ns>/L<ns> message. In runMultiTest(), multi-line per-byte index/value warnings are replaced by a single space-separated hex string capped at 24 bytes.
Reduced edge dump on decode failures
examples/AutoResearch/AutoResearchTest.cpp
Three sites in capture() — UART, SPI chipset, and generic decode failure — each change dumpRawEdgeTiming(fl::EdgeRange(0, 256)) to fl::EdgeRange(0, 32), with updated comments explaining the reduced dump count.

RPC Session Send Tracking

Layer / File(s) Summary
Send count field and property
ci/rpc_client.py
New _sent_count field tracks total RPC send attempts per session; public sent_count property exposes the count and documents that it increments on every attempt including retries.
Increment counter on send operations
ci/rpc_client.py
Both send() and send_and_match() increment _sent_count immediately after writing each JSON-RPC command during retry loops.
Verbose session summary
ci/rpc_client.py
close() prints a session summary line showing request count when verbose mode is enabled and _sent_count is non-zero.

FlexIO RX Timeout Handling

Layer / File(s) Summary
Simplified timeout diagnostics and empty-capture reclassification
src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp
Timeout logging is condensed from multiple verbose diagnostic lines into a single consolidated warning. Post-wait success path now reads DMA CITER/BITER, computes transfers_done, and reclassifies transfers_done == 0 (all-zero empty buffers) as RxWaitResult::TIMEOUT with a warning, preventing false SUCCESS on empty captures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2769: Both PRs modify src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp in FlexIoRxChannelImpl, with the main PR changing wait() timeout/empty-capture handling that gates decode behavior, while the retrieved PR implements the WS2812 decoding in decode() for FlexIO RX—so they're directly connected to the same RX decode pipeline.
  • FastLED/FastLED#3067: Both PRs modify FlexIoRxChannelImpl::wait()'s DMA timeout handling by reading DMA CITER/BITER to compute transfers_done and emitting FL_WARN diagnostics for the timeout path, with the main PR further consolidating logs and treating transfers_done==0 as RxWaitResult::TIMEOUT.
  • FastLED/FastLED#3068: Both PRs modify FlexIoRxChannelImpl::wait() in rx_flexio_channel.cpp.hpp to compute transfers_done from DMA CITER/BITER and alter the TIMEOUT/SUCCESS diagnostic behavior, with the retrieved PR additionally dumping mCaptureBuffer[0..7] while the main PR reclassifies transfers_done == 0 as TIMEOUT.

Poem

🐇 Three logs grow terse, hooray!
Edge dumps trimmed from 256 to 32,
One tidy hex string lights the way,
RPC counts and timeouts now behave,
The bunny cheers for tidier code today! 🎉

🚥 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 identifies the primary optimization: collapsing multiple verbose FL_WARN logging statements into consolidated outputs to reduce serial traffic bottlenecks during autoresearch testing.
Docstring Coverage ✅ Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch loop/3219-autoresearch-warn-audit

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.

zackees and others added 2 commits June 22, 2026 06:10
…build#755)

Adds `RpcClient._sent_count` that increments on every `send()` /
`send_and_match()` attempt (including retries). Exposed via the
public `sent_count` property; logged in verbose mode when `close()`
runs.

Lets us correlate "wrapper sent N requests" against device-reported
"Remote handled M requests" to detect daemon-side drops at the
fbuild WebSocket bridge. Cheap insurance: the only state added is a
single `int` per RpcClient instance; the increment is one statement
in two hot paths. No behavior change in the absence of dropped
messages.

Per fbuild#755 user-direction: "keep track of how many json rpc
messages you've sent. This has been a consistent problem since
ever."

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ated diagnostic (fbuild#755)

Two issues addressed:

1) `wait()` returned `SUCCESS` when the completion ISR fired even
   though `transfers_done == 0` -- the same cheat the FlexPWM driver
   had pre-#3219 (caller decodes a stale/empty buffer, reports fake
   errors). The diagnostic comment in this file at iter 4 of #3066
   documented the case: DMA can signal "complete" with CITER=BITER
   and an all-zero buffer when the shifter never fired but the ISR
   misfired. Now we re-classify that path as `TIMEOUT` so the
   caller bails honestly.

2) On both TIMEOUT and SUCCESS paths the function emitted 3 verbose
   FL_WARN_F diagnostics each (~9 KB of register-state dumps per
   call). Collapsed into ONE collated FL_WARN_F per path with the
   single most useful number (`transfers_done=N/M`) and a couple of
   register peeks. ~10x reduction in FlexIO RX diagnostic line
   volume. FlexIO RX is dead-end per #3066 iter 9 so the deep
   register dumps were already mostly for historical reference --
   not worth the ongoing UART bandwidth cost.

C++ lint passes. FlexIO RX has no host-unit-test coverage (compile-
gated to FL_IS_TEENSY_4X) so this is verified by compile + lint only.

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

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

🤖 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 `@src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp`:
- Around line 657-659: The FL_WARN_F call in the FlexIO RX timeout warning is
using incorrect format specifiers. Replace the `%s` format specifiers with `%u`
for the integer values being passed: timeout_ms, transfers_done, biter, and the
result of (mDma.error() ? 1 : 0). The `%s` specifier expects a C-string pointer
while these are all unsigned 32-bit integers, which causes undefined behavior
and potential hard faults. Apply the same fix to the similar timeout warning at
line 675.
🪄 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: 207708ad-f058-48a0-87e4-ed896f729ac1

📥 Commits

Reviewing files that changed from the base of the PR and between c2d7d55 and 6b64ae8.

📒 Files selected for processing (1)
  • src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp

Comment on lines +657 to +659
FL_WARN_F("[FlexIO RX] TIMEOUT %sms done=%s/%s err=%s SHIFTSTAT=0x%x",
timeout_ms, transfers_done, biter,
(mDma.error() ? 1 : 0), FLEXIO1_SHIFTSTAT);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify printf-style format placeholders in FL_WARN_F calls in this file.
rg -nP 'FL_WARN_F\(".*%s' src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp

Repository: FastLED/FastLED

Length of output: 448


🏁 Script executed:

sed -n '650,680p' src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp

Repository: FastLED/FastLED

Length of output: 1669


🏁 Script executed:

grep -n "timeout_ms" src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp | head -20

Repository: FastLED/FastLED

Length of output: 285


🏁 Script executed:

rg -n "FLEXIO1_SHIFTSTAT" src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp | head -5

Repository: FastLED/FastLED

Length of output: 280


Fix %s/integer format mismatch in timeout warnings (can crash on target).

Lines 657 and 675 pass integer values to %s, which expects a C-string pointer. This is undefined behavior and can hard-fault in these diagnostic paths.

  • timeout_ms, transfers_done, biter are all u32; format specifiers should be %u
  • (mDma.error() ? 1 : 0) is an integer literal; use %u
Suggested patch
-            FL_WARN_F("[FlexIO RX] TIMEOUT %sms done=%s/%s err=%s SHIFTSTAT=0x%x",
-                      timeout_ms, transfers_done, biter,
-                      (mDma.error() ? 1 : 0), FLEXIO1_SHIFTSTAT);
+            FL_WARN_F("[FlexIO RX] TIMEOUT %ums done=%u/%u err=%u SHIFTSTAT=0x%x",
+                      timeout_ms, transfers_done, biter,
+                      (mDma.error() ? 1u : 0u), FLEXIO1_SHIFTSTAT);
@@
-        FL_WARN_F("[FlexIO RX] empty-buffer SUCCESS reclassified as TIMEOUT (transfers=0/%s)", biter);
+        FL_WARN_F("[FlexIO RX] empty-buffer SUCCESS reclassified as TIMEOUT (transfers=0/%u)", biter);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FL_WARN_F("[FlexIO RX] TIMEOUT %sms done=%s/%s err=%s SHIFTSTAT=0x%x",
timeout_ms, transfers_done, biter,
(mDma.error() ? 1 : 0), FLEXIO1_SHIFTSTAT);
FL_WARN_F("[FlexIO RX] TIMEOUT %ums done=%u/%u err=%u SHIFTSTAT=0x%x",
timeout_ms, transfers_done, biter,
(mDma.error() ? 1u : 0u), FLEXIO1_SHIFTSTAT);
🤖 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 `@src/platforms/arm/teensy/teensy4_common/rx_flexio_channel.cpp.hpp` around
lines 657 - 659, The FL_WARN_F call in the FlexIO RX timeout warning is using
incorrect format specifiers. Replace the `%s` format specifiers with `%u` for
the integer values being passed: timeout_ms, transfers_done, biter, and the
result of (mDma.error() ? 1 : 0). The `%s` specifier expects a C-string pointer
while these are all unsigned 32-bit integers, which causes undefined behavior
and potential hard faults. Apply the same fix to the similar timeout warning at
line 675.

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