Recursive scripts and script mode (WAS: New mysterious warning in logs since 2022.04)

EDIT: The cause of the new warning is now clear but a resultant question remains.

I had a script that was calling itself (in a controlled manner :wink: ) which never used to give a warning or be a problem. Now I have removed the recursion but still get the warning.

(Skip to here)


I’m getting a new warning a lot in my logs.
I think I might know why but has it been documented?

(‘Notify’ is the name of my script)

Notify: Disallowed recursion detected
17:59:29 – (WARNING) Scripts - message first occurred at 16 April 2022, 07:57:17 and shows up 20 times

And more importantly I believe (but cannot yet prove) that whatever is causing it is doing more than creating a warning because my ‘suspect’ script is behaving strangely.


image

Yes, well no,thou actually it might, i think :wink:

Beside naming your script “Notify” might be not so good idea, unless you can distinct it each time you see the word Notify

Sounds like you’re calling your script from the same script.

Yes I am.
But (rightly or wrongly) that has never been a problem until 2022.04

I’m busy refactoring now…

Maybe it was undefined prior (kinda worked, but not really intended to and no one really thought about it) and they explicitly made it unsupported now. Supporting recursion properly is not trivial and needs strict resource control, maximum recursion depth, etc. Misbehaving recursive code can go nuclear very easily without proper control. Maybe they didn’t want to add all this complexity for a feature that would be very rarely used.

You can always write your script in Python directly (with recursion if you want) and call it from HA.

Yeah, I agree with all that. And I have no problem with the change, in fact my recursion whilst intentional was really something I should have avoided so I’m glad it has been pointed out.

It just would have been good to have read about the ‘new’ warning/error in the release notes.

So…

I mostly understand what is going on here and have re-written sections of my code but I’m still getting the same warning, which I wasn’t expecting.

Some clarification would be good regarding the warning and the script mode, queued.

I have a script, let’s call it recursive_script with a mode of queued which is still causing the ‘recursive’ warning.

recursive_script is called from several places using,

      - service: script.turn_on
        data:
          entity_id: script.recursive_script

i.e. it starts but the calling script continues processing without waiting for it to finish.

recursive_script never calls itself (which was the root cause of my original question).

Why would this still be a problem?

1 Like

After updating to 2024.4.4 I started getting this with a script that had been working fine several times a day for more than a year. I don’t feel like decomposing it for debugging for the moment. However, looks like the problem is due to the mode being queued and the script being called in two parallel actions. One of the calls fails with Disallowed recursion detected, which I guessed meant that a queued script cannot be called in parallel (thus cheating the queue) but I couldn’t prove it with a little test script. The test is set to queued yet two parallel runs execute fine.

The original script does not call itself or any other script, so not sure what’s up. In any case, now I just call in it series instead.