Skip to content

feat(autoresearch): wire timingDriftTest RPC for #2994 repro - #3210

Merged
zackees merged 2 commits into
masterfrom
feat/2994-timing-drift-repro-rpc
Jun 17, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/2994-timing-drift-repro-rpc

Conversation

@zackees

@zackees zackees commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Summary

examples/AutoResearch/AutoResearchTimingDrift.h has been sitting untracked on master — its docstring claimed it's "Invoked via the timingDriftTest JSON-RPC handler registered in AutoResearchRemote.cpp", but the handler was never written and the file wasn't #included anywhere. This PR wires it up so the harness can actually be invoked.

Related to open issue #2994 (compounded per-sequence timing drift on master vs 3.10.3).

Changes

  • Add AutoResearchTimingDrift.h to the tracked tree.
  • Add the #include in AutoResearch.ino, AutoResearchRemote.cpp, and all 9 *Methods.cpp translation units (matches the existing pattern used by AutoResearchSimd / Wave8Expand / ParlioEncode / ParlioStream / AnimartrixBench).
  • Register timingDriftTest in bindDriverMethods():
    • Args: [{pin, numLeds, iterations}] (all optional; defaults 4 / 35 / 10; iterations clamped to kMaxIterations = 64).
    • Returns: {success, pin, num_leds, iterations, cpu_mhz, show_count, show_min_us, show_max_us, show_total_us, iter_ms: [...]}.
  • Add the discovery catalog entry in PinMethods so the function shows up in the listed RPC catalog.

No host-side Python caller — the harness is invocable through the generic JSON-RPC test path when #2994 is next investigated.

Test plan

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a timing-drift test utility that runs repeated legacy clockless fade sequences and reports CPU frequency (when available), per-show() timing statistics (count/min/max/total), and per-sequence elapsed milliseconds.
    • Added a remote testing RPC (timingDriftTest) that accepts optional pin, LED count, and iteration parameters and returns validity plus the collected timing metrics in JSON.
  • Documentation

    • Updated the help RPC to include the new timingDriftTest endpoint and to report the function count dynamically.

The AutoResearchTimingDrift.h harness was sitting untracked on master —
self-documented as "Invoked via the timingDriftTest JSON-RPC handler
registered in AutoResearchRemote.cpp", but the handler was never written
and the file was never #include'd anywhere.

Wires it up to match the existing AutoResearchSimd / Wave8Expand /
ParlioEncode / ParlioStream / AnimartrixBench pattern:
  - Adds the include in AutoResearch.ino, AutoResearchRemote.cpp, and
    all 9 *Methods.cpp translation units.
  - Registers `timingDriftTest` in bindDriverMethods(), accepting
    {pin, numLeds, iterations} (all optional, defaults 4/35/10) and
    returning {success, pin, num_leds, iterations, cpu_mhz,
    show_count, show_min_us, show_max_us, show_total_us, iter_ms[]}.
  - Adds the discovery catalog entry in PinMethods.

Smoke-tested via `bash compile wasm --examples AutoResearch` (build
successful, 55s).

No host-side Python caller — the harness is invocable through the
generic JSON-RPC test path when #2994 is next investigated.

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

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a1a216a9-1210-4967-be33-89108e5659d1

📥 Commits

Reviewing files that changed from the base of the PR and between e0ad6c4 and b1c5a47.

📒 Files selected for processing (2)
  • examples/AutoResearch/AutoResearchRemotePinMethods.cpp
  • examples/AutoResearch/AutoResearchTimingDrift.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • examples/AutoResearch/AutoResearchRemotePinMethods.cpp
  • examples/AutoResearch/AutoResearchTimingDrift.h

📝 Walkthrough

Walkthrough

A new header AutoResearchTimingDrift.h is added to the AutoResearch example, implementing a WS2812B timing-drift reproduction module with MillisDelay, DriftResult, and a run() function. The header is included in all AutoResearch translation units, and a timingDriftTest RPC is registered in bindDriverMethods with a corresponding help entry and dynamic function count.

Changes

Timing Drift Repro Module

Layer / File(s) Summary
AutoResearchTimingDrift.h: types and run() implementation
examples/AutoResearch/AutoResearchTimingDrift.h
Defines MillisDelay (5ms/1000ms deadline helper), DriftResult (output container with per-sequence elapsed ms and FastLED.show() timing stats), and run(pin, num_leds, iterations) which drives a LegacyClocklessProxy WS2812B fade loop, records per-show() microsecond durations and per-sequence wall-clock times, and returns the populated DriftResult.
timingDriftTest RPC handler and help entry
examples/AutoResearch/AutoResearchRemoteDriverMethods.cpp, examples/AutoResearch/AutoResearchRemotePinMethods.cpp
Registers timingDriftTest in bindDriverMethods, parsing pin/num_leds/iterations from object or array input, invoking autoresearch::timing_drift::run(), and returning JSON with validity status, CPU MHz, show-timing stats, and per-iteration elapsed_ms. Returns InvalidPin error for invalid pins. Adds a matching timingDriftTest entry to the help RPC listing and updates totalFunctions to compute from functions.size() instead of a hardcoded constant.
Header include propagation
examples/AutoResearch/AutoResearch.ino, examples/AutoResearch/AutoResearchRemote.cpp, examples/AutoResearch/AutoResearchRemote*.cpp
Adds #include "AutoResearchTimingDrift.h" to all AutoResearch compilation units so the module's types and run() are available throughout the build.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • FastLED/FastLED#3191: Refactors/reorders AutoResearchRemoteControl::bindDriverMethods, the same function where timingDriftTest is registered in this PR.
  • FastLED/FastLED#3123: Gates AutoResearchRemote.cpp and companion files behind FASTLED_AUTORESEARCH_LOW_MEMORY, affecting whether the newly added timingDriftTest RPC code is compiled.

Poem

🐇 Hoppity-hop through the fade loop I go,
Counting each show() with microseconds in tow.
A drift in the timing? Let's capture it right,
With DriftResult packed full of min, max, and height.
The RPC is wired, the histogram gleams —
This bunny tracks jitter down to the extremes! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: wiring up the timingDriftTest RPC handler for issue #2994 reproduction, which is directly reflected in the changeset additions.
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 feat/2994-timing-drift-repro-rpc

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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
examples/AutoResearch/AutoResearchTimingDrift.h (1)

28-28: ⚡ Quick win

Replace raw #pragma with the project-approved compiler-control pattern.

Line 28 uses #pragma once, which conflicts with repository C++ rules.

As per coding guidelines, "Use FastLED compiler control macros from fl/stl/compiler_control.h instead of raw #pragma directives."

🤖 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 `@examples/AutoResearch/AutoResearchTimingDrift.h` at line 28, Replace the raw
`#pragma once` directive in the AutoResearchTimingDrift.h file with the
project-approved compiler control macros from the fl/stl/compiler_control.h
header file. Remove the `#pragma once` line and instead include the appropriate
FastLED compiler control macros that provide include guard functionality
according to the project's C++ coding guidelines.

Source: Coding guidelines

🤖 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 `@examples/AutoResearch/AutoResearchRemotePinMethods.cpp`:
- Around line 576-582: A hardcoded totalFunctions constant exists somewhere
after the functions vector is populated that tracks the count of available RPC
functions. When adding the new timingDriftTest function to the functions vector
via push_back, this hardcoded value becomes stale and causes the help catalog to
under-report the RPC count. Update the totalFunctions constant to reflect the
new total count, or preferably refactor it to derive the count dynamically from
functions.size() so it automatically stays in sync whenever functions are added
or removed.

In `@examples/AutoResearch/AutoResearchTimingDrift.h`:
- Around line 147-183: The while loop starting with (completed < iterations) can
run for approximately 25 seconds with the 1000ms delay at line 174 repeated per
iteration, which exceeds the 5000ms watchdog timeout and risks system resets.
Add watchdog feed/refresh calls at strategic points within the loop to prevent
timeout violations. Place watchdog refresh calls at the beginning of each loop
iteration and after the 1000ms delay to ensure the watchdog timer is
continuously serviced before it times out.
- Around line 95-100: The FastLED.clear(ClearFlags::CHANNELS) call on line 95
modifies global state before the pin validity is checked via proxy.valid() on
line 98. Move the FastLED.clear(ClearFlags::CHANNELS) statement to after the
validity check block (after the if (!proxy.valid()) return statement) so that
global channel state is only cleared when the pin is confirmed to be valid,
preventing mutation of global state when an invalid pin is requested.

---

Nitpick comments:
In `@examples/AutoResearch/AutoResearchTimingDrift.h`:
- Line 28: Replace the raw `#pragma once` directive in the
AutoResearchTimingDrift.h file with the project-approved compiler control macros
from the fl/stl/compiler_control.h header file. Remove the `#pragma once` line
and instead include the appropriate FastLED compiler control macros that provide
include guard functionality according to the project's C++ coding guidelines.
🪄 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: 51dc0b12-838a-4874-870a-1625ee848a0e

📥 Commits

Reviewing files that changed from the base of the PR and between ba46ef1 and e0ad6c4.

📒 Files selected for processing (12)
  • examples/AutoResearch/AutoResearch.ino
  • examples/AutoResearch/AutoResearchRemote.cpp
  • examples/AutoResearch/AutoResearchRemoteAsyncMethods.cpp
  • examples/AutoResearch/AutoResearchRemoteBenchmarkMethods.cpp
  • examples/AutoResearch/AutoResearchRemoteDriverMethods.cpp
  • examples/AutoResearch/AutoResearchRemoteMathMethods.cpp
  • examples/AutoResearch/AutoResearchRemoteNetworkMethods.cpp
  • examples/AutoResearch/AutoResearchRemotePinMethods.cpp
  • examples/AutoResearch/AutoResearchRemoteRunParallelTest.cpp
  • examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp
  • examples/AutoResearch/AutoResearchRemoteSystemMethods.cpp
  • examples/AutoResearch/AutoResearchTimingDrift.h

…nel-clear ordering, watchdog feed

Three valid CodeRabbit findings on PR #3210:

1. PinMethods.cpp: hardcoded `totalFunctions=28` would drift every time
   a new RPC is registered. Use `functions.size()` so it stays accurate.

2. AutoResearchTimingDrift.h: `FastLED.clear(ClearFlags::CHANNELS)`
   ran before pin validity was checked, mutating global RPC-test channel
   state on bad pin requests. Probe with a throwaway proxy first, only
   touch globals once the pin is known valid.

3. AutoResearchTimingDrift.h: a default 10-iter run takes ~25s; the
   AutoResearch watchdog timeout (AUTORESEARCH_WATCHDOG_TIMEOUT_MS=5000,
   AutoResearch.ino:250) would fire mid-sequence. Feed watchdog around
   the per-sequence delay(1000) and on a 1 s cadence inside the inner
   poll loop.

Re-verified via `bash compile wasm --examples AutoResearch` (success, 51s).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 188908c into master Jun 17, 2026
18 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 17, 2026
@zackees
zackees deleted the feat/2994-timing-drift-repro-rpc branch August 21, 2026 19:15
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