Potential bug report: Execution Count

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Potential bug report: Execution Count

Post by digitalstone » 26 Sep 2018 15:15

Over the last weeks i noticed some quick fails, causing stops withing my "Check Ping Response" flow.
Now, somewhere in that flow i use the action "Execution Count" to ping my host multiple times in case something goes a bit off.
I have set that number to 10. The problem is that, half of the time or so, it does not even reach the 10 times... it just cuts of at a number that seems very random (5,6 or 3).

So, in this particular instance, i came home yesterday and switched my Automagic-made profile to "Home".
It does all sorts of things locally on the phone, and at the end it's supposed to ping my router to do all sorts of thing within my home... that's where the "Check Ping Response" flow comes in.
That flow is supposed to fail after 10 tries of unsuccessfully pinging my router.
...
Problem is, it failed after only 2 tries.
As soon as the flow reached "Execution Count" for the second time, it exit with a 'true' value :shock:

Here is my flow:
photo_2018-09-26_16-44-45.jpg
photo_2018-09-26_16-44-45.jpg (145.81 KiB) Viewed 10539 times

In the log, that i catched as soon as i could, you'll notice that when searching for 'Execution Count: 10 times' there are only 2 instances.
The important part is actually everything after the flow-element called:
------========------
Empty Node Collector
------========------

Code: Select all

25.09.2018 19:44:09.230 [Check Ping Response] End executing action 'Execute Flows: Check Router Connection'
25.09.2018 19:44:09.287 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:09.287 [Check Ping Response] Start executing condition 'Return Value:
HomeConnection'
25.09.2018 19:44:09.290 [Check Ping Response] End executing condition 'Return Value:
HomeConnection' with return value true
25.09.2018 19:44:09.290 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:09.290 [Check Ping Response] Start executing action '------========------
Empty Node Collector
------========------'
25.09.2018 19:44:09.290 [Check Ping Response] End executing action '------========------
Empty Node Collector
------========------'
25.09.2018 19:44:09.291 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:09.291 [Check Ping Response] Start executing action 'Widget (Network):
Set Pinging
&
Ping Attempt'
25.09.2018 19:44:09.303 [Check Ping Response] End executing action 'Widget (Network):
Set Pinging
&
Ping Attempt'
25.09.2018 19:44:09.303 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:09.304 [Check Ping Response] Start executing action 'Execute Command: ping -c 1 {ping_address} in '
25.09.2018 19:44:14.318 [Check Ping Response] Action 'Execute Command: ping -c 1 {ping_address} in ' Could not execute command 
ch.gridvision.ppam.androidautomagiclib.util.m: Executing command failed, see log output
 at ch.gridvision.ppam.androidautomagic.model.a.am$1.a(SourceFile:144)
 at ch.gridvision.ppam.androidautomagic.model.a.am$1.c(SourceFile:112)
 at ch.gridvision.ppam.androidautomagiclib.util.cj$1.run(SourceFile:40)
 at java.lang.Thread.run(Thread.java:761)

25.09.2018 19:44:14.354 [Check Ping Response] End executing action 'Execute Command: ping -c 1 {ping_address} in ' and exception Executing command failed, see log output
25.09.2018 19:44:14.356 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:14.357 [Check Ping Response] Start executing condition 'Expression: exit_code == 0'
25.09.2018 19:44:14.360 [Check Ping Response] Start executing action 'Write to File: {triggertime,dateformat,dd.HH:mm:ss} - Attempt: {ping_attempt}
 to /storage/emulated/0/file.txt (append)'
25.09.2018 19:44:14.364 [Check Ping Response] End executing condition 'Expression: exit_code == 0' with return value false
25.09.2018 19:44:14.374 [Check Ping Response] End executing action 'Write to File: {triggertime,dateformat,dd.HH:mm:ss} - Attempt: {ping_attempt}
 to /storage/emulated/0/file.txt (append)'
25.09.2018 19:44:14.375 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:14.375 [Check Ping Response] Start executing condition 'Execution Count: 10 times'
25.09.2018 19:44:14.377 [Check Ping Response] End executing condition 'Execution Count: 10 times' with return value false
25.09.2018 19:44:14.378 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:14.378 [Check Ping Response] Start executing action 'Sleep: 1s (keep device awake)'
25.09.2018 19:44:14.379 [Check Ping Response] Action 'Sleep: 1s (keep device awake)' Sleeping for 1s (keep device awake)
25.09.2018 19:44:15.381 [Check Ping Response] End executing action 'Sleep: 1s (keep device awake)'
25.09.2018 19:44:15.383 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:15.384 [Check Ping Response] Start executing action 'Widget (Network):
Set Pinging
&
Ping Attempt'
25.09.2018 19:44:15.407 [Check Ping Response] End executing action 'Widget (Network):
Set Pinging
&
Ping Attempt'
25.09.2018 19:44:15.408 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:15.409 [Check Ping Response] Start executing action 'Execute Command: ping -c 1 {ping_address} in '
25.09.2018 19:44:20.418 [Check Ping Response] Action 'Execute Command: ping -c 1 {ping_address} in ' Could not execute command 
ch.gridvision.ppam.androidautomagiclib.util.m: Executing command failed, see log output
 at ch.gridvision.ppam.androidautomagic.model.a.am$1.a(SourceFile:144)
 at ch.gridvision.ppam.androidautomagic.model.a.am$1.c(SourceFile:112)
 at ch.gridvision.ppam.androidautomagiclib.util.cj$1.run(SourceFile:40)
 at java.lang.Thread.run(Thread.java:761)

25.09.2018 19:44:20.418 [Check Ping Response] End executing action 'Execute Command: ping -c 1 {ping_address} in ' and exception Executing command failed, see log output
25.09.2018 19:44:20.419 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:20.419 [Check Ping Response] Start executing condition 'Expression: exit_code == 0'
25.09.2018 19:44:20.420 [Check Ping Response] Start executing action 'Write to File: {triggertime,dateformat,dd.HH:mm:ss} - Attempt: {ping_attempt}
 to /storage/emulated/0/file.txt (append)'
25.09.2018 19:44:20.425 [Check Ping Response] End executing condition 'Expression: exit_code == 0' with return value false
25.09.2018 19:44:20.427 [Check Ping Response] End executing action 'Write to File: {triggertime,dateformat,dd.HH:mm:ss} - Attempt: {ping_attempt}
 to /storage/emulated/0/file.txt (append)'
25.09.2018 19:44:20.427 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:20.428 [Check Ping Response] Start executing condition 'Execution Count: 10 times'
25.09.2018 19:44:20.429 [Check Ping Response] End executing condition 'Execution Count: 10 times' with return value true
25.09.2018 19:44:20.429 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:20.429 [Check Ping Response] Start executing action 'Ping:
Set Response
(false)'
25.09.2018 19:44:20.432 [Check Ping Response] End executing action 'Ping:
Set Response
(false)'
25.09.2018 19:44:20.432 [Check Ping Response] Flow continues executing with the next step.
25.09.2018 19:44:20.432 [Check Ping Response] Start executing action 'Widget (Network):
-Set Total Time
-Ping Response
-Set End Time'
25.09.2018 19:44:20.443 [Check Ping Response] End executing action 'Widget (Network):
-Set Total Time
-Ping Response
-Set End Time'
25.09.2018 19:44:20.444 [Check Ping Response] Flow ended.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Potential bug report: Execution Count

Post by Desmanto » 26 Sep 2018 17:06

When I read the title, I somehow already know what is the bug you are referring to. And turns out I am right. I ever wanted to report this, with flow example, but distracted by other things and forgotten already.

There are 2 "bugs" with execution condition :
1. You have already mention. Execution count store the count across flow execution, just like global variable. So if you use 10 times;
a. Execute the flow 1st time, you loop 3 times. The counter now is 3.
b. The next execution, you loop for 5 times. Counter now is 3+5 = 8.
c. So the next execution, even though you only loop 2 times, counter = 10 is reached, and continue to true branch.
To eliminate this problem, you have to reset the counter. Unfortunately, there is no way to reset the counter or to know the current counter value, except using the "Timed" tick box to reset it. So you have to put a reasonable timeframe to reset the counter. In your case, you use sleep 1s with 10 times of count. It should be reasonable to put 10-15s as the duration.

2. Execution count store the counter across multiple flow if the Name is the same. So not only the counter is stored globally, it also store uniquely based on the element Name (especially if you use default name). Example you have your execution count 10 times in flow A. Then you use another execution count 10 times also in flow B, with the exact same name (you can see the notif that "This condition is used in 2 flows"). If 2 execution count shared the same name, they shared the same counter too!!! In this case, you loop 3 times in flow A. Then in flow B, loop 4 times (totally different flow, different execution). The counter for both execution count now is 3+4 = 7. To eliminate this problem, using "Timed" tick box sometimes is not enough. Since flow A and B can be executed at the same moment. You have to make sure you untick the default name and give them different name, so they don't share the same global counter.

In short, both these actually are not bug, but featured. It is just not documented properly in the help menu.
But there are still improvement can be made :
1. Provide field in the Execution count to see the current counter, or maybe a button to reset it. Now, I reset the counter by setting it to Timed 1s, save. Open again and untick the Timed, the counter will be reset, but too hassle.
2. If no UI available, at least provide the counter variable so we can reset it manually
3. I don't know how the counter is stored, but probably it is stored as a hidden glovar, global_counter map, which has name of the execution count with its counter and timer to reset. If there is, probably also provide method to access this or to reset this.
4. Separate the unique identifier of the execution count when used in different flow. So even the same execution count name is used in flow A and B, they can't interfere with each other.
5. Add numbering and Increment to the default name of the execution count when it is added. So even I added the same execution count 10 times in the same flow, both will have different counter (Execution Count 1, Execution Count 2, ....)
6. Add a tick box with default on, to reset the counter after the flow finish. This make the counter behave just like local variable, which get resetted/destroyed after the flow execution end
7. Document the changes and unique behaviour in the help menu.

Above are just my ideas, not necessarily to be implemented. Let's see what are Martin opinion on this.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Potential bug report: Execution Count

Post by digitalstone » 26 Sep 2018 18:05

Wow, i already had the suspicion of an issue with shared variables or something along the likes of it.
But each time i thought: Nah, of course the count number is stored locally so the name and all that wouldn't matter.

I was wrong apparently :?
Especially because i viewed the Execution Count condition (i called it 'action' in my opening post... sorry) as a sort of notched up version of what you can do yourself with expressions.

No matter, i'll just switch back to 'manual' until this is fixed :)
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Potential bug report: Execution Count

Post by Desmanto » 26 Sep 2018 18:14

No problem. As long as we understand it. I sometimes mis-type some of the concept too.

BTW, i forgot to put the expression version of execution count, which use local variable and won't suffer from cross flow shared counter. Use expression

Code: Select all

if(count == null OR count >= 10) count = 0;
count = count + 1;
count >= 10;
Change the 10 to your loop limit. You can also reset the count by set it to 0. The counter will be resetted in every execution, since it is local variable.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Potential bug report: Execution Count

Post by digitalstone » 26 Sep 2018 19:08

Oh thanks for the script Desmanto.
i have made these kind of scrips before of course.
Yet i didn't know you could actually end this with a "loose hanging" evaluation at the end like that. I only did it like that if there is only 1 line of evaluation and nothing else.
But seems logical i suppose since it lacks any sort of action like with an if-then-else statement.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

Post Reply