I’m pretty stumped.
Is this some known bug? See the screenshot below from traces. It looks like the very first iteration of the repeat loop doesn’t have first: true and also has repeat.index starting at 26?
I think the only relevant thing is the structure of the loop.
Is it normal for something labeled as Iteration 1 to have first: false and index: 26. Do the values of some calls to turn_on light really matter? it might as well be just the no-op delay.
I searched through my available traces to find an example containing a repeat and found just this one. It’s from a repeat until and it behaves as one would expect.
Thanks a lot @123. I use loops in only three of my scripts, and they all behave as expected.
Even this script behaves correctly 99% of the time but would occasionally “randomly” start from some number.
And BTW I’m obviously also not setting the repeat.index variable to anything in my loops, I only read it (i don’t even know if it would work but jinja prob allows it). So it’s pretty bizarre.
I’m doing a few more tests explicitly setting repeat.index it to a variable within each iteration, as that would be much easier to trace.
The only interesting thing I’ve observed in my logs is that the script behaves normally 99% of the time but the few “weird” behavior times when the loop starts from a random number is when it’s invoked consecutively. The run mode is set to “Single” and I don’t see any warnings in the logs that it’s killed but I’m starting to think it could be something related to tightly ordered invocations of the script itself. Still doesn’t make much sense to me. I’ll see what I can find.
The oddest part to me is just not that index isn’t at 1 but that it says first: false. How can the infra mark something as not being first in a script with just a single simple loop. So bizarre…
This appears to be purely a visualization bug in the Trace UI itself, the values themselves are accurate (meaning the values of repeat.first and repeat.index
If you have a large number of iterations (it appears anything over 25-ish but may be a diff value), the Traces UI incorrectly resets it to Iteration 1 but displays the 26th and further iteration values. That also explains why it shows first: false which was the most puzzling of all.
@123 do you know if it’s best to report this on the github side and under what topic? I’m fairly certain it’ll just go in a black hole somewhere as it’s not particularly critical
repeat.index does start at 1, automation/script traces will only show you the last 20 iterations which are named iteration 1 through 20.
It’s not a visual bug, it’s by design to reduced the stored information in a trace. Essentially they don’t want people storing 1000’s of iteration information in a single trace.
Showing the last 20 is ok but there is actually a bug because the UI incorrectly label it as Iteration 1 which is mighty confusing IMHO. It should correctly state Iteration X depending on how many iterations are in total and subtract 20 from that total count (if it shows the last 20).
Respectfully, I’d have to disagree with you @petro. We can argue semantics here but something saying “Iteration 1” to me reads as the first iteration rather than "the 1st of some arbitrarily starting number of iterations (specifically Max iterations - 20). It’s extremely confusing IMHO. I’ll post it as a bug as suggested by @123 – fully knowing that 99% likeliehood is no dev will look at it, and if they do, maybe they’ll take your stance. But I think it’s worth reporting.
I’m explaining how it works. There’s nothing to disagree with. It may be misleading but that’s what the actual intention of the name is. To show you the stored iteration in the trace.
I definitely won’t have the time, and I also think this is a pretty minor problem all things considered. But if you want to give it a go yourself, you are certainly welcome to.