Allow negative batch_index on ImageFromBatch and LatentFromBatch (CORE-195)#13857
Conversation
|
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)
📝 WalkthroughWalkthroughThis PR enables negative 🚥 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. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@comfy_extras/nodes_images.py`:
- Around line 148-151: After converting a negative batch_index (batch_index +=
s_in.shape[0]) ensure you clamp it to a non-negative lower bound like
batch_index = max(0, batch_index) before computing length; in other words update
the block that manipulates batch_index and length in nodes_images.py so that
after the negative-index conversion you enforce batch_index = max(0,
batch_index) and then compute batch_index = min(s_in.shape[0] - 1, batch_index)
and length = min(s_in.shape[0] - batch_index, length) to prevent negative
indices and empty/unexpected slices when batch_index is more negative than the
batch size.
In `@nodes.py`:
- Around line 1235-1238: The negative-index conversion for batch_index can
produce values below 0 and bypass the upper clamp, causing empty slices; update
the logic around batch_index (the block that adjusts batch_index and length
using s_in.shape[0]) to clamp batch_index into [0, s_in.shape[0]-1] after adding
s_in.shape[0] for negatives (e.g., set batch_index = max(0, batch_index) before
the min(...) upper clamp or use batch_index = min(s_in.shape[0]-1, max(0,
batch_index))), and then recompute length = min(s_in.shape[0] - batch_index,
length) so slicing of s_in[batch_index:batch_index+length] cannot produce empty
results due to overly negative indices.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: eb2eaf3c-a15e-4ee4-b4d4-20a84ad63f60
📒 Files selected for processing (2)
comfy_extras/nodes_images.pynodes.py


Adds negative-indexing support to
batch_indexonImageFromBatch(comfy_extras/nodes_images.py:139) andLatentFromBatch(nodes.py:1224). Schema bounds change from(0, 4095)and(0, 63)respectively to(-MAX_RESOLUTION, MAX_RESOLUTION). Each method gainsif batch_index < 0: batch_index += s_in.shape[0]before the existing upper clamp.lengthis unchanged. Each value verified against current code.Similar newer indexing nodes (
LatentCut,ReplaceVideoLatentFrames,LTXVAddGuide,TrimAudioDuration,VideoSlice) already support negative indexing. The two FromBatch nodes were the exceptions, so workflows that wanted the last N frames had to computebatch_size - Nupstream. With this change,batch_index = -N, length = Nworks directly, which is the standard ergonomic pattern for windowing and first-last-frame loop flows.The
(-MAX_RESOLUTION, MAX_RESOLUTION)bound matchesLatentCut.indexandReplaceVideoLatentFrames.index.