Skip to content

fix(autoresearch): fail the test when RX capture is truncated - #2297

Merged
zackees merged 1 commit into
masterfrom
autoresearch-truncation-hard-fail
Apr 18, 2026
Merged

zackees merged 1 commit into
masterfrom
autoresearch-truncation-hard-fail

Conversation

@zackees

@zackees zackees commented Apr 18, 2026 •

Copy link
Copy Markdown
Member

Summary

The autoresearch WS2812 comparator silently breaks the per-LED compare loop when bytes_captured runs short, then reports Errors: 0/<num_leds> as PASS. Any LEDs past the first bytes_captured / 3 are skipped without comparison — turning truncated captures into false-positive PASSes.

On ESP32-S3 the RMT RX DMA buffer caps a single receive at 4096 symbols (≈ 170 WS2812B LEDs), so every autoresearch run on a strip longer than ~170 LEDs was passing without actually verifying the tail.

Change

Track verified_leds. After the loop, if it's short of num_leds, count the unchecked LEDs as mismatches and emit a clear [TRUNCATED CAPTURE] diagnostic so the run hard-FAILs. No-op when capture is full.

Before on bash autoresearch --spi --strip-sizes 550 (ESP32-S3):

[RUN 1] Driver=SPI, bytes_captured=512
[Run 1/2] PASS | Errors: 0/550 (100.0%)    ← false positive

After:

[RUN 1] Driver=SPI, bytes_captured=512
[TRUNCATED CAPTURE] Only verified 170/550 LEDs (512 bytes captured,
needed 1650). Marking 380 unchecked LEDs as mismatches.
[Run 1/2] FAIL | Errors: 380/550 (30.91%)

Test plan

  • bash autoresearch --spi --strip-sizes 550 on ESP32-S3 now hard-FAILs with the [TRUNCATED CAPTURE] diagnostic.
  • bash autoresearch --spi --strip-sizes 100 on ESP32-S3 still PASSes legitimately (bytes_captured=300, all 100 LEDs verified).
  • No regression in the RMT driver test path (uses the same comparator but captures fit easily within 4096 symbols for the --strip-sizes small default).

Background

Exposed while reproducing issue #2254 (ESP32-S3 SPI driver "black frame between displays"). Independent of any driver fix; this is purely a test-harness correctness improvement that makes the harness stop lying on long strips.

The underlying RX-capacity limit (~170 LEDs per pass) is a separate, larger investigation documented in #2254 — it requires RmtMemoryManager refactoring to support DMA-mode RX allocations. Until that lands, this PR at least ensures such runs FAIL loudly instead of passing silently.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Enhanced RGB LED validation testing to properly identify and report incomplete data captures. Unchecked LEDs are now correctly flagged as mismatches rather than ignored, with diagnostic messages provided for better visibility into test failures. This ensures more accurate validation results.

The WS2812 per-LED comparator silently `break`s when `bytes_captured`
runs short, then reports `Errors: 0/<num_leds>` as PASS. Any LEDs past
the first `bytes_captured / 3` are quietly skipped without comparison
— turning truncated captures into false-positive PASSes.

On ESP32-S3 the RMT RX DMA buffer caps a single receive at 4096
symbols (≈ 170 WS2812B LEDs), so every autoresearch run on a strip
longer than ~170 LEDs was passing without actually verifying the tail.

Track how many LEDs were actually compared. After the loop, if the
count is short of `num_leds`, count the unchecked LEDs as mismatches
and emit a clear `[TRUNCATED CAPTURE]` diagnostic so the run hard-FAILs.
No-op when capture is full (current pass paths unchanged).

Observed behavior on ESP32-S3 before: `--spi --strip-sizes 550` reports
PASS with `bytes_captured=512` / `Errors: 0/550 (100.0%)`. After: hard
FAIL with `[TRUNCATED CAPTURE] Only verified 170/550 LEDs (512 bytes
captured, needed 1650). Marking 380 unchecked LEDs as mismatches.`
100-LED test regression-free (still PASSes legitimately).

See issue #2254.

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

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The test verification logic now properly detects and penalizes truncated RX buffer captures by tracking verified LED counts, comparing against expected totals, and counting missing validations as byte mismatches with a warning message.

Changes

Cohort / File(s) Summary
WS2812 LED Verification Logic
examples/AutoResearch/AutoResearchTest.cpp
Added tracking of verified LED count in runMultiTest() to detect truncated RX data; unmapped LEDs now counted as mismatches with proportional byte penalty (unchecked LEDs × 3) and [TRUNCATED CAPTURE] warning, preventing false test passes on incomplete captures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 A hoppy fix for LEDs unright,
When buffers cut short the light,
Now mismatches shine clear,
No false passes here,
Validation complete and tight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding logic to fail tests when RX capture is truncated, which directly matches the code modification that tracks verified LEDs and treats unverified LEDs as mismatches.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 autoresearch-truncation-hard-fail

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.

🧹 Nitpick comments (1)
examples/AutoResearch/AutoResearchTest.cpp (1)

690-712: Same silent-truncation bug still lives in runTest().

This PR fixes runMultiTest(), but the sibling runTest() has the identical pattern: the loop breaks on insufficient bytes_captured (line 698) without incrementing mismatches, so a truncated capture whose verified LEDs all happen to match will still be reported as PASS ✓ at line 720. If any callers exercise runTest() on strips that can exceed the RMT 4096-symbol DMA budget (e.g., --strip-sizes 550 on ESP32-S3), they will continue to see false positives even after this PR lands.

Consider mirroring the fix here for consistency.

♻️ Proposed parallel fix for runTest()
+            size_t verified_leds = 0;
             for (size_t i = 0; i < num_leds; i++) {
                 size_t byte_offset = rx_buffer_offset + i * 3; // Skip front padding
                 if (byte_offset + 2 >= bytes_captured) { // Check against total captured bytes
                     FL_ERROR("[" << ctx.driver_name << "/" << ctx.timing_name << "/" << ctx.pattern_name
                             << " | Lane " << ctx.lane_index << "/" << ctx.lane_count
                             << " (Pin " << ctx.pin_number << ", " << ctx.num_leds << " LEDs) | RX:" << ctx.rx_type_name << "] "
                             << "Incomplete data for LED[" << static_cast<int>(i)
                             << "] (only " << bytes_captured << " bytes captured)");
                     break;
                 }
+                verified_leds = i + 1;
 
                 uint8_t expected_r = leds[i].r;
                 // ...
                 if (expected_r != actual_r || expected_g != actual_g || expected_b != actual_b) {
                     mismatches++;
                 }
             }
+
+            if (verified_leds < num_leds) {
+                size_t unchecked = num_leds - verified_leds;
+                mismatches += static_cast<int>(unchecked);
+                FL_WARN("[TRUNCATED CAPTURE] Only verified " << verified_leds
+                        << "/" << num_leds << " LEDs - marking " << unchecked
+                        << " unchecked LEDs as mismatches.");
+            }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/AutoResearch/AutoResearchTest.cpp` around lines 690 - 712, runTest()
currently breaks out of the LED verification loop when (byte_offset + 2 >=
bytes_captured) without marking that remaining LEDs were unverified, which can
yield false PASS results; update the loop in runTest() (the block referencing
rx_buffer_offset, num_leds, bytes_captured, mismatches and the FL_ERROR log) to
treat a truncation as mismatches for the remaining LEDs — increment mismatches
by (num_leds - i) or otherwise set a failing flag before breaking and keep the
existing FL_ERROR message so truncated captures are counted as failures.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@examples/AutoResearch/AutoResearchTest.cpp`:
- Around line 690-712: runTest() currently breaks out of the LED verification
loop when (byte_offset + 2 >= bytes_captured) without marking that remaining
LEDs were unverified, which can yield false PASS results; update the loop in
runTest() (the block referencing rx_buffer_offset, num_leds, bytes_captured,
mismatches and the FL_ERROR log) to treat a truncation as mismatches for the
remaining LEDs — increment mismatches by (num_leds - i) or otherwise set a
failing flag before breaking and keep the existing FL_ERROR message so truncated
captures are counted as failures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d596ff79-00ba-4f6e-9b80-ac02a84198c2

📥 Commits

Reviewing files that changed from the base of the PR and between de11566 and 1be506e.

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

@zackees
zackees merged commit ad85c96 into master Apr 18, 2026
66 of 81 checks passed
@zackees
zackees deleted the autoresearch-truncation-hard-fail branch April 18, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant