Skip to content

test(task): make the zero-budget sleep check robust to a contended machine (#3772) - #3780

Merged
zackees merged 1 commit into
masterfrom
fix/3772-flaky-yield-timing
Jul 31, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3772-flaky-yield-timing

Conversation

@zackees

@zackees zackees commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Closes #3772.

fl::task::run SYSTEM yield paths failed intermittently in the full suite while always passing in isolation and clean under sanitizers. It hit two of my own PRs this week (#3771, #3778) on both Windows and the macOS runner, so it is producing real false reds on the gate used to decide whether to merge.

Measured before changing anything

condition best of 5 samples
idle 0–1µs
under 48 busy procs on 16 cores 6650µs
under 48 busy procs on 16 cores 17259µs

The bound is 250µs. Idle, the path has 250x headroom — so the assertion is nowhere near marginal. Under load the minimum is 26–69x over.

Why the obvious fixes don't work

Raising the threshold cannot work. At 6–17ms of scheduling noise, a 1ms sleep is undetectable by any wall-clock method. Any threshold that survives the noise sits far above the thing it exists to catch, and it would blunt the check on the idle machines where it does work.

More samples alone doesn't work either. Under sustained contention every sample is inflated. That is precisely the case the existing comment assumed away:

A regression that made this path sleep would raise every sample, which best-of-N cannot hide.

True of a regression; not true of a loaded machine, where contention also raises every sample. Best-of-N cannot tell the two apart.

What this does instead

Time a bare fl::yield() as a control, interleaved with the candidate. It is the exact call the zero-budget path is supposed to take (executor.cpp.hpp:156) and by definition cannot sleep, so preemption inflates both together.

The tight 250µs bound is kept and asserted normally. When even the control exceeds it, the environment cannot support a wall-clock measurement at all, so the test reports inconclusive rather than a false failure. Samples raised 5 → 32 to sharpen both minima.

Verified in both directions

This is the part that matters — a flake "fix" that just stops asserting is worse than the flake.

  • No longer false-fails: under the same synthetic load that previously failed 2 of 10 runs, the revised test passed 12 of 12.
  • Still catches the regression: injecting a 2ms cost into the zero-budget path in src/fl/task/executor.cpp.hpp makes the test fail as intended. The probe was reverted; only tests/fl/task/executor.cpp is changed in this PR.

Full C++ suite 274/274. Passes clean under --debug (ASAN/LSAN/UBSAN). bash lint clean.

Note

I deliberately left this alone earlier in the week when it was blocking #3771, because relaxing an unrelated regression guard to unblock my own PR is the wrong shape of change even when the guard is the thing at fault. Doing it now as its own task, with the numbers measured and the guard proven still live.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved validation of system-yield responsiveness and timing behavior.
    • Added more representative repeated measurements to reduce flaky results.
    • Tests now account for temporary system contention and provide a warning when timing conditions are inconclusive.

…chine

`fl::task::run SYSTEM yield paths` failed intermittently in the full suite
while always passing in isolation and clean under sanitizers. It bounds a wall
clock, and the suite runs hundreds of test binaries in parallel.

Measured the actual distribution rather than guessing. Uncontended, the
zero-budget path costs 0-1us against a 250us bound -- 250x headroom. Under 48
busy processes on a 16-core box, the *minimum* of 5 samples was 6650us and
17259us, i.e. 26x and 69x the bound.

That rules out the obvious fixes. Raising the threshold cannot work: at 6-17ms
of scheduling noise a 1ms sleep is undetectable by any wall-clock method, so
any threshold that survives the noise is far above what it is meant to catch,
and it would blunt the check on the idle machines where it does work. More
samples alone does not work either, because under sustained contention every
sample is inflated -- which is exactly the case the existing best-of-5 comment
assumed could not happen.

Instead, time a bare fl::yield() as a control alongside the candidate. It is
the very call the zero-budget path is supposed to take and by definition
cannot sleep, and interleaving the two means OS preemption inflates both
together. The tight 250us bound is kept and asserted normally; when even the
control exceeds it, the environment cannot support a wall-clock measurement at
all, so the check reports inconclusive instead of a false failure. Samples
raised 5 -> 32 to sharpen both minima.

Verified both directions:

- Under the same synthetic load that previously failed 2 of 10 runs, the
  revised test passed 12 of 12.
- The guard still bites: injecting a 2ms cost into the zero-budget path in
  src/fl/task/executor.cpp.hpp made the test fail as intended. This is not a
  disabled assertion.

Full C++ suite 274/274, and the test passes clean under --debug (ASAN/UBSAN).

Closes #3772

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

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The executor test now compares zero-budget system yields with bare fl::yield() measurements. It uses 32 samples and skips the bound assertion when system contention makes the control measurement inconclusive.

Changes

System yield test

Layer / File(s) Summary
Timing control and validation
tests/fl/task/executor.cpp
The test includes fl::yield, samples both yield paths 32 times, compares their best durations, and applies the 250µs assertion only when the control measurement is conclusive.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • FastLED/FastLED#3766: Both changes test SYSTEM and zero-budget yielding behavior in tests/fl/task/executor.cpp; this change revises timing validation.
🚥 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 describes the test change and its purpose under machine contention.
Linked Issues check ✅ Passed The test changes address issue #3772 by reducing contention-related false failures while retaining regression detection.
Out of Scope Changes check ✅ Passed The changes are limited to the flaky SYSTEM-yield test and match the linked issue objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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/3772-flaky-yield-timing

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)
tests/fl/task/executor.cpp (1)

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

Use lowercase naming for the local sample count.

Rename kSamples to k_samples. This local object must use simple lowercase naming.

As per coding guidelines, use “simple lowercase naming for simple objects.”

🤖 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 `@tests/fl/task/executor.cpp` at line 1111, Rename the local sample-count
constant kSamples to k_samples in the surrounding test code, updating all
references while preserving its value and behavior.

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.

Nitpick comments:
In `@tests/fl/task/executor.cpp`:
- Line 1111: Rename the local sample-count constant kSamples to k_samples in the
surrounding test code, updating all references while preserving its value and
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e0787315-8350-4904-87de-8a31a39b5727

📥 Commits

Reviewing files that changed from the base of the PR and between 0faeff4 and 4b08877.

📒 Files selected for processing (1)
  • tests/fl/task/executor.cpp

@zackees
zackees merged commit bdf2efc into master Jul 31, 2026
6 checks passed
@zackees
zackees deleted the fix/3772-flaky-yield-timing branch July 31, 2026 05:23
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 31, 2026
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.

test: fl_task_executor 'fl::task::run SYSTEM yield paths' is flaky under full-suite load

1 participant