Global scope "items" stops working

I can’t reproduce it on demand, but every few days the “items” global scope disappears. I can still access items and all their properties through ir.getItems(), though.

So, for example, after days of running just fine:

mode_metadata = get_key_value(item_name, "area_triggers_and_actions", items.mode)

…results in:

2020-10-20 07:00:59.659 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'f5f36e86-db67-407b-837b-ca45af66fa2e': Fail to execute action: 1
2020-10-20 07:01:18.791 [INFO ] [ort.shared.ScriptedAutomationManager] - removeAll added handlers
2020-10-20 07:01:18.933 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/personal/area_mt_logic.py'
2020-10-20 07:01:23.336 [ERROR] [jsr223.jython                       ] - Traceback (most recent call last):
  File "/etc/openhab2/automation/lib/python/core/log.py", line 51, in wrapper
    return fn(*args, **kwargs)
  File "<script>", line 68, in light_action
NameError: global name 'mode' is not defined

If I replace items.mode with ir.getItem('mode').state and simply reload the rule, everything works fine again.

Life is great if I just replace all my items. references, but I’d still like to understand the problem. I’m not sure how to further troubleshoot the issue, however.

Some environment information:

  • Openhabian, OH 2.5.9-1
  • openjdk version “1.8.0_265”
  • OpenJDK Runtime Environment (Zulu 8.48.3.246-CA-linux_aarch32hf) (build 1.8.0_265-b11)
  • OpenJDK Client VM (Zulu 8.48.3.246-CA-linux_aarch32hf) (build 25.265-b11, mixed mode)
  • jython-standalone-2.7.0.jar

Shouldn’t that be items["mode"]? items is a dict using the Item names as the key and the Item’s state as the value. Thus items["mode"] == ir.getItem("mode").state should return True.

The documentation I referenced here:

https://openhab-scripters.github.io/openhab-helper-libraries/Guides/But%20How%20Do%20I.html

…states that all three ways should work.

And they all do, for several days usually. Then something happens and the global dict seems to disappear.