Skip to content

fix(task): clamp the SYSTEM yield to the caller's budget; drop dead needsDeepYield (#3765) - #3766

Merged
zackees merged 1 commit into
masterfrom
fix/3765-executor-honors-budget
Jul 29, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3765-executor-honors-budget

Conversation

@zackees

@zackees zackees commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Two items from the #3765 meta-tracker — the two that are actually landable while on-device work is blocked by FastLED/fbuild#1213.

1. task::run() ignored its own microseconds budget

executor.cpp.hpp called pumpCoroutines(1000) with a literal 1000, discarding the caller's microseconds. Because run() is a do/while loop against a deadline, run(250, SYSTEM) could pump past its own budget.

Now clamped to fl::min(1000u, remaining()) — exactly what the COROUTINES branch three lines below already does.

Scope, stated plainly because it is narrower than I claimed on #3765. This is a correctness/consistency fix, not an observable bug fix on either platform this suite exercises:

platform behavior
ESP32 pumpCoroutines() floors any non-zero request at one FreeRTOS tick (the if (ticks == 0) ticks = 1 branch from #2254) — 250 and 1000 are identical. The #2254 deep-yield guarantee is untouched.
host CoroutineRunner::run() early-returns when no coroutine is registered (if (mCount == 0) return;) — both are no-ops.

It only bites with coroutines registered, where the hardcoded 1000 pumps them past the caller's deadline.

2. needsDeepYield() was dead code

Declared in coroutine_runtime.h, overridden in coroutine_esp32.impl.hpp, called from nowhere. It duplicated fl::NetworkDetector with weaker semantics — WIFI_MODE_NULL only, no Bluetooth, no Ethernet — and was superseded by the NetworkDetector gating in #2817 / #3764.

Removed along with its only helper isWiFiActive() and the esp_wifi.h include plus weak-symbol declaration that existed solely to serve it.

soc/soc_caps.h is deliberately left: it sits inside an IWYU pragma: keep block, other ESP headers may rely on it transitively, and this file cannot be compiled locally — not worth the risk for a dead include.

A note on the test, because it matters

My first version of this change shipped a wall-clock test asserting run(250, SYSTEM) does not sleep ~1000 µs. It passed against the un-fixed code — the mCount == 0 early return above means neither value sleeps on host. That is false assurance, so I deleted it rather than keep a green test that proves nothing. It also corrected my own understanding of the bug's scope, which is why the framing above differs from #3765.

What remains pins the contract that is observable here: the zero-budget path must take the cheap fl::yield() and must not sleep, and a small budget must terminate.

Verification

  • 357/357 host tests, clean build
  • bash lint --cpp exit 0
  • The ESP32 deletion is compile-verified by CI's ESP32 jobs, not locally — flagging that explicitly since I could not build for that target on this bench

Not in this PR

Remaining #3765 items, all needing hardware or further investigation:

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved task scheduling so coroutine processing respects the caller’s available time budget.
    • Prevented zero-duration task runs from introducing unnecessary delays.
    • Ensured short-duration runs complete promptly without exceeding their intended timing.
  • Tests

    • Added coverage for system-yield execution paths and timing behavior across zero and short time budgets.

…eedsDeepYield (#3765)

Two items from the #3765 meta-tracker.

1. task::run()'s SYSTEM branch called pumpCoroutines(1000) with a literal
   1000, ignoring its own `microseconds` parameter. Since run() is a
   do/while loop against a deadline, a caller asking for
   run(250, SYSTEM) could pump past its own budget. Now clamped to
   fl::min(1000u, remaining()), mirroring exactly what the COROUTINES
   branch immediately below already does.

   Scope, stated plainly because it is narrower than I first claimed on
   #3765: this is a correctness/consistency fix, NOT an observable bug fix
   on either platform this suite exercises.
     - ESP32: pumpCoroutines() floors any non-zero request at one FreeRTOS
       tick (the `if (ticks == 0) ticks = 1` branch from #2254), so 250 and
       1000 are identical. The #2254 deep-yield guarantee is untouched.
     - Host: CoroutineRunner::run() early-returns when no coroutine is
       registered (`if (mCount == 0) return;`), so both are no-ops.
   It only bites with coroutines registered, where the hardcoded 1000
   pumps them past the caller's deadline.

2. ICoroutineRuntime::needsDeepYield() was dead code -- declared in
   coroutine_runtime.h, overridden in coroutine_esp32.impl.hpp, called
   from nowhere. It duplicated fl::NetworkDetector with weaker semantics
   (WIFI_MODE_NULL only; no Bluetooth, no Ethernet) and was superseded by
   the NetworkDetector gating in #2817/#3764. Removed, along with its
   only caller-helper isWiFiActive() and the esp_wifi include and weak
   symbol declaration that existed solely to serve it.

   soc/soc_caps.h is deliberately left: it sits in an IWYU keep block and
   other ESP headers may rely on it transitively, and this file cannot be
   compiled locally.

On testing: the first version of this change shipped a wall-clock test
asserting run(250) does not sleep ~1000us. It passed against the
un-fixed code, because of the mCount==0 early return above -- false
assurance, so it was removed rather than kept. What remains pins the
contract that IS observable here: the zero-budget path must take the
cheap fl::yield() and must not sleep, and a small budget must terminate.

Verified: 357/357 host tests, bash lint --cpp exit 0. The ESP32 deletion
is compile-verified by CI's ESP32 jobs, not locally.

Refs #3765, #3762, #2817, #2254

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

coderabbitai Bot commented Jul 29, 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 Plus

Run ID: 639b4886-972d-4e00-b3a5-2c02d3d09b99

📥 Commits

Reviewing files that changed from the base of the PR and between 1e70d60 and ce00907.

📒 Files selected for processing (4)
  • src/fl/task/executor.cpp.hpp
  • src/platforms/coroutine_runtime.h
  • src/platforms/esp/32/coroutine_esp32.impl.hpp
  • tests/fl/task/executor.cpp
💤 Files with no reviewable changes (2)
  • src/platforms/coroutine_runtime.h
  • src/platforms/esp/32/coroutine_esp32.impl.hpp

📝 Walkthrough

Walkthrough

The system task runner now limits coroutine pumping to the caller’s remaining microsecond budget. The coroutine runtime removes WiFi-specific deep-yield detection, and executor tests cover zero-budget yielding and bounded positive-budget execution.

Changes

System yield behavior

Layer / File(s) Summary
Remove platform deep-yield capability
src/platforms/coroutine_runtime.h, src/platforms/esp/32/coroutine_esp32.impl.hpp
The coroutine runtime interface and ESP32 implementation no longer expose WiFi-dependent deep-yield detection.
Enforce system yield deadlines
src/fl/task/executor.cpp.hpp, tests/fl/task/executor.cpp
System coroutine pumping uses the remaining deadline budget, with timing tests covering zero-budget and small positive-budget execution.

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

🚥 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 change: clamping SYSTEM yielding to the caller budget and removing the dead needsDeepYield API.
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-executor-honors-budget

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.

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