Netwatch - keep global variables possible?

I am currently experimenting with Netwatch and ran into a limitation. It seems that global variables are discarded between runs.

Test setup:

/system/script add dont-require-permissions=no name=nw-globals owner=me policy=read,write,test source=\
    ":global foo;\
    \n:set foo (\$foo+1);\
    \n:log info (\$foo);"

/tool/netwatch/add host=1.1.1.1 test-script=nw-globals type=icmp

This produces the following log:

2026-05-08 11:47:02 script,info 1 
2026-05-08 11:47:12 script,info 1 
2026-05-08 11:47:23 script,info 1 
2026-05-08 11:47:32 script,info 1

However, when I run the script manually multiple times using /system/script/run nw-globals, the variable persists as expected:

2026-05-08 11:39:17 script,info 1 
2026-05-08 11:39:19 script,info 2 
2026-05-08 11:39:20 script,info 3

The documentation states that Netwatch executes scripts as the *sys user:

Netwatch executes scripts as *sys user, so any defined global variable in the Netwatch script will not be readable by for an example a scheduler or other users

My understanding was that as long as *sys is executing the script, the global variables should persist between runs.

As a workaround, I currently :serialize variables to JSON file and restore them using :deserialize at script startup. This works, but I would prefer a simpler approach.

Could this be a bug or an intentional limitation? I found several older discussions about issues with global variables, but I could not find a definitive answer or workaround.

My methods are quite complicated...
They have to be for me, so who cares?
I recommend using layer 7 as a persistent storage method (I've already posted examples of this in the forum),
and using the firewall address list for temporary things that don't need to persist across reboots.

I just need to "keep state" between the netwatch test-script runs. Need to know e.g. previous rtt-avg. And I want to write as little as possible to flash - avoid unnecessary wear. The json file is created on the default ram-disk. the "layer7 key-value store" would add history as well.

Must be keeped or not at plained/unexpected reboot?

Example for a num (0 to 4294967295):

{
:local lastrtt 15

/ip firewall address-list
remove [find where list=tmp_netwatch_global_vars and comment="prev-rtt-avg"]

add dynamic=yes list=tmp_netwatch_global_vars comment="prev-rtt-avg" address=(0.0.0.0 + $lastrtt)

:local prevrtt [get [find where list=tmp_netwatch_global_vars and comment="prev-rtt-avg"] address]

:set prevrtt [:tonum [:toip $prevrtt]]

:put $prevrtt
}

For true/false value, suffice the check if the item in list exist or not.

I could use that one and write serialized variables to "comment" and restore again. would probably need fewer script policies.

yes, you can use "IP" as variable... number and put values in comment.

netwatch "1" use from 0.0.1.0 to 0.0.1.255
netwatch "2" use from 0.0.2.0 to 0.0.2.255
netwatch "3" use from 0.0.3.0 to 0.0.3.255
etc.