Repository navigation
test(task): make the zero-budget sleep check robust to a contended machine (#3772) - #3780
Conversation
…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]>
📝 WalkthroughWalkthroughThe executor test now compares zero-budget system yields with bare ChangesSystem yield test
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/fl/task/executor.cpp (1)
1111-1111: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse lowercase naming for the local sample count.
Rename
kSamplestok_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
📒 Files selected for processing (1)
tests/fl/task/executor.cpp
Closes #3772.
fl::task::run SYSTEM yield pathsfailed 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
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:
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.
src/fl/task/executor.cpp.hppmakes the test fail as intended. The probe was reverted; onlytests/fl/task/executor.cppis changed in this PR.Full C++ suite 274/274. Passes clean under
--debug(ASAN/LSAN/UBSAN).bash lintclean.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