Skip to content

fix(gfx): the white-allocation bound clamp is unsound as an interval - #4197

Merged
zackees merged 1 commit into
masterfrom
fix/4041-white-allocation-clamp
Sep 7, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/4041-white-allocation-clamp

Conversation

@zackees

@zackees zackees commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Small, and the interesting part is the measurement I got wrong first.

#4188 clamped the bound quotient in divideWhiteQ16 to full drive, with this reasoning: a bound outside ±1.0 either doesn't bind or means infeasible, so the min/max that follow reach the same verdict either way — "decision-preserving rather than a fudge".

That argument doesn't hold. Clamping turns a lower bound of w >= 6.64 — which no drive can satisfy, so the target is out of reach — into w >= 1.0, which an upper bound of exactly 1.0 then meets. The interval collapses to a single point instead of being empty.

Being precise about the impact

I first measured this as 2,745 verdict flips in 300,000 random targets and was about to ship it as a live bug with a regression test. Then the mutation test didn't fail, which was the useful signal.

The drives are at_zero − level · per_white, which reproduce the target for any level — that's an identity, not a property of the level. So the real feasibility test is the range check on the drives at the end, and it rejects those targets whether or not the bound was clamped. Re-measured through the actual API: no difference in what the function returns across the same sweep.

So my figure described the interval computation in isolation, not the function. Corrected in the comment.

Why fix it anyway

It's latent, not harmless. The bound is consumed as an interval, and any caller that uses the interval for something other than reading off one of its two ends inherits the collapse. That's exactly how it surfaced — in work on a two-white (RGBWW) allocation that bisects over totals, where the clamped bound reported a bright target reachable and then produced a red drive of −0.21.

No test

Deliberately. There's no observable difference to assert, and a test that passes with the clamp restored would be decoration. The reasoning lives in the comment.


The RGBWW allocation that found this is not in this PR. Its design needs more work than I could validate honestly — details in the issue I'm filing alongside.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of high white-drive values during emitter allocation.
    • Prevented premature value clamping, enabling more accurate channel-level calculations.

#4188 clamped the bound quotient to full drive and argued that was
decision-preserving: a bound outside +/-1.0 either does not bind or means
infeasible, so the min and max that follow reach the same verdict either
way. That argument does not hold. Clamping turns a lower bound of
"w >= 6.64", which no drive can satisfy, into "w >= 1.0" -- and an upper
bound of exactly 1.0 then meets it, so the interval collapses to a single
point instead of being empty.

Worth being precise about the impact, because I first measured it wrong.
The drives are `at_zero - level * per_white`, which reproduce the target for
*any* level; that is an identity, not a property of the level. So the real
feasibility test is the range check on the drives at the end, and it rejects
those targets whether or not the bound was clamped. A sweep of 300 000
random targets finds no difference in what the function returns. My first
reading of that sweep -- 2 745 flipped verdicts -- was of the interval
computation alone, not of the function, and overstated it.

Latent, then, not live. Still worth removing: the bound is consumed as an
interval, and a caller that uses the interval for anything other than
picking one of its two ends inherits the collapse. That is how it surfaced,
in work on a two-white allocation that bisects over totals rather than
reading off an end.

No test accompanies this, deliberately. There is no observable difference to
assert, and a test that passes with the clamp restored would be decoration.
The reasoning is in the comment instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
@coderabbitai

coderabbitai Bot commented Sep 7, 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: Team

Run ID: 2905f1c5-ee79-4d5c-9354-3e9c35321b10

📥 Commits

Reviewing files that changed from the base of the PR and between 8a08aed and 2ae2fc6.

📒 Files selected for processing (1)
  • src/fl/gfx/white_allocation.cpp.hpp

Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

divideWhiteQ16 now returns an unclamped i64 quotient. allocateEmitterDrivesQ16 stores interval bounds as i64 and explicitly casts the policy-selected level to i32.

Changes

White allocation precision

Layer / File(s) Summary
Preserve white-level interval precision
src/fl/gfx/white_allocation.cpp.hpp
divideWhiteQ16 returns the raw i64 quotient without clamping. Allocation interval bounds use i64, and the selected level is explicitly narrowed to i32.

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

Merge Risk: ⚪ Minimal · up to 2ae2f

This change preserves infeasible white-allocation intervals instead of collapsing them through a full-drive clamp, while retaining the existing final output range check. No current merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. 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: removing the unsound white-allocation bound clamp.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4041-white-allocation-clamp

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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Sep 7, 2026
@zackees
zackees merged commit b643071 into master Sep 7, 2026
32 of 33 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 7, 2026
@zackees
zackees deleted the fix/4041-white-allocation-clamp branch November 5, 2026 05:52
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