fix(FeatherMask): correct negative zero indexing for right/bottom feathering#12881
Conversation
…thering In the FeatherMask node, when applying right and bottom feathering, the loop variable starts at 0, making `-x` and `-y` equal to `-0`, which in Python indexes the first element (index 0) instead of the last. This causes the first column/row to be incorrectly modified while the last column/row is left untouched. Fix by using `-(x + 1)` and `-(y + 1)` so the loop correctly starts from the last element (index -1) and works inward, matching the behavior of the left/top feathering loops which start from index 0 and work outward.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR updates FeatherMask.execute in comfy_extras/nodes_mask.py to fix off-by-one negative indexing when applying feather gradients: right-edge indexing changed to output[:, :, -(x + 1)] and bottom-edge indexing changed to output[:, -(y + 1), :], adjusting how feather rates are applied to the output mask edges. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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)
comfy_extras/nodes_mask.py (1)
323-325: Please add a regression test for theright=1/bottom=1case.This fix is easy to accidentally undo because
-0 == 0is non-obvious. A tiny mask assertion that only the last column/row is feathered would lock the behavior in.Also applies to: 331-333
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@comfy_extras/nodes_mask.py` around lines 323 - 325, Add a regression test that covers the edge cases right=1 and bottom=1 to ensure the feather loops use negative indexing correctly (i.e., index -1, not -0) and only the final column/row is modified: create a simple known input mask, call the mask-feathering function (the code that sets feather_rate and mutates output using variables right, bottom, and output), and assert that all columns/rows except the last are unchanged and the last column/row has been multiplied by the expected feather_rate; add separate assertions for the right loop and the bottom loop (the blocks using "for x in range(right): ... output[:, :, -(x + 1)] *= feather_rate" and the analogous bottom code).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@comfy_extras/nodes_mask.py`:
- Around line 323-325: Add a regression test that covers the edge cases right=1
and bottom=1 to ensure the feather loops use negative indexing correctly (i.e.,
index -1, not -0) and only the final column/row is modified: create a simple
known input mask, call the mask-feathering function (the code that sets
feather_rate and mutates output using variables right, bottom, and output), and
assert that all columns/rows except the last are unchanged and the last
column/row has been multiplied by the expected feather_rate; add separate
assertions for the right loop and the bottom loop (the blocks using "for x in
range(right): ... output[:, :, -(x + 1)] *= feather_rate" and the analogous
bottom code).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 18ea1d38-3b77-46b4-9a12-565ac6656de4
📒 Files selected for processing (1)
comfy_extras/nodes_mask.py
|
Hello @alvinttang and thank you for your contribution. Do you have a workflow example to reproduce the issue before the fix please? Test on
Test on your PR (looks identical):
|
|
Ok I see the issue now, there's indeed one pixel feathering on the top and left side of the mask before the fix. I am merging this, thank you. |


Summary
FeatherMasknode applying feathering to the wrong edge forrightandbottomparametersx=0ory=0in the feathering loops,-0in Python equals0, sooutput[:, :, -0]indexes the first column instead of the lastBefore (bug)
After (fix)
Test plan
right=50, bottom=50(left=0, top=0)