๐Ÿž Possible bug in IF node: expression evaluates correctly but routing goes to True branch

Hi,

I believe Iโ€™ve run into a bug (or at least very unintuitive behavior) in the IF node when using expressions, and Iโ€™d like to check whether this is expected or not.

Context / goal

Iโ€™m using Split in Batches and want to wait only between batches, i.e.:

  • batch #1 โ†’ no wait

  • batch #2+ โ†’ wait (rate-limit OCR API)

The condition is based on:

$("Split in Batches").context["currentRunIndex"]

which is 0 for the first batch, 1, 2, โ€ฆ for subsequent batches.


What I tried

1. String comparison in IF node

IF node configuration:

  • Condition type: String

  • Value 1 (Expression):

{{ String($("Split in Batches").context["currentRunIndex"] ?? "0").trim() }}

  • Operation: is not equal

  • Value 2: "0" (string, not number)

  • Convert types where required: OFF

2. Debug confirms expression is correct

Using a Set node right before the IF, I verified:

  • currentRunIndex = 0

  • typeof currentRunIndex = number

  • String(...).trim() = "0"

  • String(...).trim() !== "0" = false

  • Expression preview in IF node shows Result: false

So logically, the IF should go to the False branch on the first batch.


:cross_mark: What actually happens

Despite all of the above:

  • The IF node routes items to the True branch

  • The downstream Wait node executes on the first batch

  • This happens consistently

I also tried:

  • Boolean conditions (is true / is false)

  • Explicit boolean expressions

  • Number comparisons

  • Turning Convert types where required ON and OFF

In multiple cases:

  • The expression preview shows the correct result

  • But runtime routing still goes to the True branch

This behavior looks very similar to the issue described here:
https://community.n8n.io/t/if-node-expression-returns-false-but-still-goes-to-true-branch/129452/2

Please share your workflow. or the part of it that doesnโ€™t work. That makes it a lot easier to see what is going on.