Skip to content

fix(FeatherMask): correct negative zero indexing for right/bottom feathering#12881

Merged
alexisrolland merged 2 commits into
Comfy-Org:masterfrom
alvinttang:fix/feather-mask-negative-zero-index
May 18, 2026
Merged

fix(FeatherMask): correct negative zero indexing for right/bottom feathering#12881
alexisrolland merged 2 commits into
Comfy-Org:masterfrom
alvinttang:fix/feather-mask-negative-zero-index

Conversation

@alvinttang
Copy link
Copy Markdown
Contributor

Summary

  • Fix FeatherMask node applying feathering to the wrong edge for right and bottom parameters
  • When x=0 or y=0 in the feathering loops, -0 in Python equals 0, so output[:, :, -0] indexes the first column instead of the last
  • This causes the first column/row to be multiplied twice (by both left+right or top+bottom feathering) while the actual last column/row is never feathered

Before (bug)

for x in range(right):
    feather_rate = (x + 1) / right
    output[:, :, -x] *= feather_rate  # -0 == 0, hits first column!

After (fix)

for x in range(right):
    feather_rate = (x + 1) / right
    output[:, :, -(x + 1)] *= feather_rate  # -1 correctly hits last column

Test plan

  • Create a solid white mask (e.g. 256x256)
  • Apply FeatherMask with right=50, bottom=50 (left=0, top=0)
  • Verify the right edge and bottom edge are feathered (gradient to black)
  • Verify the left edge and top edge remain sharp (fully white)
  • Previously, the left column and top row would incorrectly get darkened while right/bottom edges stayed white

…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.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 11, 2026

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

Run ID: eb58a548-cf8a-4bf1-a2d8-16c8113de2a3

📥 Commits

Reviewing files that changed from the base of the PR and between 730eeec and 0c15a58.

📒 Files selected for processing (1)
  • comfy_extras/nodes_mask.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • comfy_extras/nodes_mask.py

📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: correcting negative zero indexing for right/bottom feathering in FeatherMask.
Description check ✅ Passed The description clearly explains the bug, provides before/after code examples, and outlines a comprehensive test plan related to the changeset.
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.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
comfy_extras/nodes_mask.py (1)

323-325: Please add a regression test for the right=1 / bottom=1 case.

This fix is easy to accidentally undo because -0 == 0 is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ad36d6 and 730eeec.

📒 Files selected for processing (1)
  • comfy_extras/nodes_mask.py

@alexisrolland
Copy link
Copy Markdown
Member

alexisrolland commented May 18, 2026

Hello @alvinttang and thank you for your contribution.

Do you have a workflow example to reproduce the issue before the fix please?

Test on master branch (looks fine):

{BAEDBE0B-0F97-40D4-B61A-B7F0BBA6B9A9}

Test on your PR (looks identical):

{6F8AB052-0BAA-444A-9F16-A14D0240B8C1}

@alexisrolland
Copy link
Copy Markdown
Member

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.

@alexisrolland alexisrolland merged commit d4c6c9e into Comfy-Org:master May 18, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants