Skip to content

feat(autoresearch): host driver for the #2994 timing-drift reproducer (#3765) - #3768

Merged
zackees merged 1 commit into
masterfrom
fix/3765-timing-drift-driver
Jul 29, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3765-timing-drift-driver

Conversation

@zackees

@zackees zackees commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Another #3765 item: the #2994 reproducer had no way to run.

The gap

AutoResearchTimingDrift.h has faithfully replayed the reporter's sketch for some time — 35-LED WS2812B ring on the legacy addLeds path, setMaxRefreshRate(800), millisDelay-gated 255-step fade, delay(1000) between sequences — exposed as the timingDriftTest JSON-RPC method.

It had no host driver. Nothing in ci/ referenced timingDriftTest, and bash autoresearch --help has no matching flag. The reproducer had never been run.

That is not a footnote — it is arguably why #2994 went a year with a wrong root cause. The tool built to falsify a hypothesis existed but could not be invoked, so hypotheses got tested by argument instead of measurement. (Mine included: I published a throttle-based root cause that this script would have refuted in one run.)

What it reports

Follows the established standalone bring-up pattern (test_flexio_rx_objectfled.py) rather than adding an autoresearch flag, since that is what these device probes already look like.

1. Per-sequence wall time against the 2495 ms theoretical (225 + 254*5 + 1000), with a per-sequence bar chart. Index 0 is excluded — it is partial by construction (no leading 225 ms arm, no trailing 1000 ms delay), so including it understates the mean.

2. FastLED.show() duration — the decisive number. The firmware already returned show_min_us / show_max_us / show_total_us; nothing consumed them. The reported drift is 268–1012 µs per fade step, the same order as one 35-LED WS2812 frame (~1050 µs of wire time). Since tests/profile/fastled_show.cpp (#3767) established the CPU-side dispatch path costs only ~2 µs, if show() sits well above the wire floor then the cost is in encoding, DMA, or a driver wait — none of which are visible off-device.

It deliberately does not fail on drift. What counts as "too much" is the question under investigation, not something to hardcode into the tool.

Usage

uv run python -m ci.autoresearch.test_timing_drift --port COM9
uv run python -m ci.autoresearch.test_timing_drift --port COM9 --iterations 20

Run on master and on 3.10.3, compare.

Tests

7 cases in ci/tests/test_timing_drift_driver.py, covering the arithmetic that would otherwise silently mislead the investigation: the theoretical period, the wire floor, the partial-first-sequence exclusion, drift reported against theory, and the missing-timing fallback for older firmware.

Mutation-checked — removing the index-0 skip fails three of them.

What is not validated

The RPC round-trip is unexercised. The ESP32-C6 on this bench dropped off the USB bus during earlier deploy attempts and FastLED/fbuild#1213 blocks redeploying it, so only the analysis layer is covered here. Flagging that rather than implying an end-to-end run.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a command-line timing-drift diagnostic for LED firmware.
    • Supports configurable pin, LED count, and iteration count.
    • Reports sequence timing, drift against expected timing, and FastLED.show() performance statistics.
    • Provides clear success or failure status for connection, communication, and firmware-reported results.
  • Tests

    • Added automated coverage for timing calculations, drift reporting, partial sequences, insufficient data, and missing timing metrics.

…#3765)

AutoResearchTimingDrift.h has faithfully replayed the #2994 reporter's
sketch for some time -- 35-LED WS2812B ring on the legacy addLeds path,
setMaxRefreshRate(800), millisDelay-gated 255-step fade, delay(1000)
between sequences -- and exposes it as the `timingDriftTest` JSON-RPC
method.

It had no host driver. Nothing in ci/ referenced `timingDriftTest` and
there was no CLI flag, so the reproducer had never been run. That is why
#2994 went a year with a wrong root cause: the tool to falsify it existed
but could not be invoked.

Follows the established standalone bring-up pattern
(test_flexio_rx_objectfled.py), not a new autoresearch flag, since that is
what these device probes already look like.

Reports the two numbers that matter:

1. Per-sequence wall time against the 2495 ms theoretical (225 + 254*5 +
   1000). Index 0 is excluded -- it is partial by construction, with no
   leading 225 ms arm and no trailing 1000 ms delay, so including it
   understates the mean.

2. FastLED.show() duration. The firmware already returns show_min/max/
   total_us; nothing consumed them. This is the decisive measurement: the
   reported drift is 268-1012 us per fade step, the same order as one
   35-LED WS2812 frame (~1050 us of wire time). tests/profile/
   fastled_show.cpp already showed the CPU-side dispatch path costs ~2 us,
   so if show() sits well above the wire floor the cost is in encoding,
   DMA, or a driver wait -- none visible off-device.

Deliberately does not fail on drift. What counts as "too much" is the
question under investigation, not something to hardcode into the tool.

Tests: 7 cases in ci/tests/test_timing_drift_driver.py covering the
arithmetic that would otherwise silently mislead -- the theoretical
period, the wire floor, the partial-first-sequence exclusion, drift
reported against theory, and the missing-timing fallback. Mutation-checked:
removing the index-0 skip fails three of them.

Note this is validated at the analysis layer only. The RPC round-trip is
unexercised -- the ESP32-C6 on this bench dropped off the USB bus and
FastLED/fbuild#1213 blocks redeploying it.

Refs #3765, #2994

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a command-line host driver for the timingDriftTest JSON-RPC method, including sequence and FastLED.show() timing reports, error handling, and pytest coverage for timing calculations and output.

Changes

Timing drift driver

Layer / File(s) Summary
Timing and show reporting
ci/autoresearch/test_timing_drift.py, ci/tests/test_timing_drift_driver.py
Defines theoretical timing constants, RPC result summarizers, drift calculations, WS2812 wire-time comparisons, and tests for valid and missing timing data.
CLI execution flow
ci/autoresearch/test_timing_drift.py
Adds CLI options, serial connection setup, firmware capability checks, timingDriftTest execution, success validation, interruption handling, and the executable entry point.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant RpcBench
  participant Firmware
  CLI->>RpcBench: Connect using --port
  CLI->>RpcBench: Call ping
  RpcBench->>Firmware: Send ping JSON-RPC request
  Firmware-->>RpcBench: Return ping result
  CLI->>RpcBench: Call timingDriftTest with test parameters
  RpcBench->>Firmware: Send timingDriftTest JSON-RPC request
  Firmware-->>RpcBench: Return timing and show metrics
  CLI->>CLI: Print sequence and show summaries
Loading
🚥 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 clearly summarizes the main addition: a host driver for the #2994 timing-drift reproducer.
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.
✨ 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 fix/3765-timing-drift-driver

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.

@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)
ci/autoresearch/test_timing_drift.py (1)

1-10: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Rename the driver to avoid test-discovery ambiguity.

ci/autoresearch/test_timing_drift.py matches the repo test-file glob and pytest’s default test_*.py collection pattern, but it is a CLI/module driver, not a pytest test file. Rename it to something like timing_drift_driver.py or another non-test_-prefixed module name, and update ci/tests/test_timing_drift_driver.py imports accordingly.

🤖 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 `@ci/autoresearch/test_timing_drift.py` around lines 1 - 10, Rename the
CLI/module driver currently represented by the timing-drift script to a
non-test-prefixed name such as timing_drift_driver.py, then update imports in
ci/tests/test_timing_drift_driver.py to reference the renamed module. Preserve
the driver’s behavior and pytest test discovery for the actual test module.
🤖 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.

Nitpick comments:
In `@ci/autoresearch/test_timing_drift.py`:
- Around line 1-10: Rename the CLI/module driver currently represented by the
timing-drift script to a non-test-prefixed name such as timing_drift_driver.py,
then update imports in ci/tests/test_timing_drift_driver.py to reference the
renamed module. Preserve the driver’s behavior and pytest test discovery for the
actual test module.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 367a8cdd-3969-4c1b-b9e9-0f229d0e8a91

📥 Commits

Reviewing files that changed from the base of the PR and between 68411b1 and 7ffacc2.

📒 Files selected for processing (2)
  • ci/autoresearch/test_timing_drift.py
  • ci/tests/test_timing_drift_driver.py

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