Javascript rules compilation at openhab startup fails with error

Hello.

OH: 4.3.0-4.3.5
JAVA: Zulu v17.58.21 CA-JDK v17.0.15 x64
OS: Windows Server 2022 Std Latest
JS: application/javascript ECMAScript 262 Edition 11
Experience: 3+ years with OH v3&4

I encountered a problem with compiling javascript rules at system startup.
Previously, when there was no forced compilation, there were no such problems with rules/scripts.
DSL rules/scripts are compiled without problems.

In version 4.3.2 there was no problem, I could restart openhab.
But in 4.3.0, 4.3.1, 4.3.4 and 4.3.5 a compilation error occurs.

My rules depend on other bindings (telegram, gsm modem, mqtt), maybe this is a problem? If after starting manually turn off and then turn on the script from the interface, then everything works.

Help me find a solution.

2 rules, 1 script, three errors, everything is added via interface (not files), everything works correctly after recompilation

  1. rule: madhomebot
  2. rule: mobilesmsbot
  3. script: javascript (there are no dependencies)
2025-05-12 14:46:09.992 [INFO ] [org.openhab.core.Activator          ] - Starting openHAB 4.3.5 (Release Build)
2025-05-12 14:46:23.992 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'debug_sensor_climat_voltage.items'
2025-05-12 14:46:25.557 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'jdbc.persist'
2025-05-12 14:46:33.842 [INFO ] [.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2025-05-12 14:46:34.236 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'openhab.rules'
2025-05-12 14:46:38.136 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'intercom.rules'
2025-05-12 14:46:39.245 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'rflnk.rules'
2025-05-12 14:46:44.087 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'socketplug.rules'
2025-05-12 14:46:45.834 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Timeout occurred when executing commandLine '[r:\servers\openhab\userdata\bin\arp-ping.exe, --help]'
2025-05-12 14:46:46.210 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Failed to execute commandLine '[arping, --help]'
2025-05-12 14:46:48.586 [WARN ] [.discovery.sddp.SddpDiscoveryService] - listenActiveScanUnicast() error 'Invalid argument: setsockopt'
2025-05-12 14:46:49.855 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'bluetooth.rules'
2025-05-12 14:46:50.158 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'lightbulb.rules'
2025-05-12 14:46:51.977 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'relay.rules'
2025-05-12 14:46:52.916 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'debug.rules'
2025-05-12 14:46:53.690 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'siren.rules'
2025-05-12 14:46:55.238 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'weather.rules'
2025-05-12 14:46:55.785 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'intrusion.rules'
2025-05-12 14:46:55.862 [INFO ] [persistence.jdbc.internal.JdbcMapper] - JDBC::openConnection: Driver is available::Yank setupDataSource
2025-05-12 14:47:02.461 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'alarms.rules'
2025-05-12 14:47:03.171 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - Started HABPanel at /habpanel
2025-05-12 14:47:24.042 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'voice.rules'
2025-05-12 14:47:24.584 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script: Error: Failed to get any services of type(s): org.openhab.core.thing.link.ItemChannelLinkRegistry
        at <js>.getService(@openhab-globals.js:2)
        at <js>.236(@openhab-globals.js:2)
        at <js>.o(@openhab-globals.js:2)
        at <js>.605(@openhab-globals.js:2)
        at <js>.o(@openhab-globals.js:2)
        ... 28 more
2025-05-12 14:47:24.823 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script: Error: Failed to get any services of type(s): org.openhab.core.thing.link.ItemChannelLinkRegistry
        at <js>.getService(@openhab-globals.js:2)
        at <js>.236(@openhab-globals.js:2)
        at <js>.o(@openhab-globals.js:2)
        at <js>.605(@openhab-globals.js:2)
        at <js>.o(@openhab-globals.js:2)
        ... 28 more
2025-05-12 14:47:25.037 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script: Error: Failed to get any services of type(s): org.openhab.core.thing.link.ItemChannelLinkRegistry
        at <js>.getService(@openhab-globals.js:2)
        at <js>.236(@openhab-globals.js:2)
        at <js>.o(@openhab-globals.js:2)
        at <js>.605(@openhab-globals.js:2)
        at <js>.o(@openhab-globals.js:2)
        ... 28 more
2025-05-12 14:47:38.204 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'network.rules'
2025-05-12 14:47:42.265 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'scenes.rules'
2025-05-12 14:48:15.419 [INFO ] [ternal.dhcp.DHCPPacketListenerServer] - DHCP request packet listener online
2025-05-12 14:48:20.292 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '127.0.0.1' with clientid openhab
2025-05-12 14:48:33.375 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to compile rule ā€˜madhomebot' with status 'UNINITIALIZED'
2025-05-12 14:48:33.381 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to compile rule ā€˜mobilesmsbot' with status 'UNINITIALIZED'
2025-05-12 14:48:33.388 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to compile rule ā€˜javascript' with status 'UNINITIALIZED'
2025-05-12 14:48:33.397 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.

Are the errors ocurring for all JS rules or just those that use Thing actions?

What triggers the two rules?

What calls the script?

That’s probably just a fluke. This looks like a timing issue. For some reason the ItemRegistry is not ready when OH enters startlevel 40 so it’s not available when the rule is loaded and compiled. It works fine later because by then the ItemRegistry is ready.

I don’t see any .items files being loaded so it looks like all your Items are managed. But I see you rely on jdbc. Is that being used for restoreOnStartup? I could see that potentially slowing down the Items becoming ready.

Because issues like that can cause problems, I always recommend using MapDB for restoreOnStartup instead of anything external. You’ll never run into problems if the jdbc service is down when OH first starts at least using that.

For all.

  • rule with sms bot - thing channel was triggered
  • rule with telegram bot - item was updated by thing or persistance (JDBC/PostgreSQL strategy = everyChange, everyUpdate, restoreOnStartup)

Only on user request (manually, for debugging) from the user interface (Administration \ Settings \ Scripts)

But it’s interesting that in 4.3.2 there was never a problem. I also think that the problem is in timings. The scripts use things like telegram, mobilesms, but in addition to this, there is an intensive reference to the historical state of items: for example, what was the text of the item (not the current one).

There are, but I don’t think they have any effect.

2025-05-12 14:46:23.992 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'debug_sensor_climat_voltage.items'

Content of debug_sensor_climat_voltage.items. Used in dslrule on user input, not in JavaScript

Number    debug_sensor_climat_voltage_cr2032    "CR2016, CR2032"                <energy>      (debug_sensor_climat) ["Temperature", "Voltage"] {widgetOrder="11", stateDescription=" "[pattern="%.3f V"]}
Number    debug_sensor_climat_voltage_cr2450    "CR2450"                        <energy>      (debug_sensor_climat) ["Temperature", "Voltage"] {widgetOrder="12", stateDescription=" "[pattern="%.3f V"]}
Number    debug_sensor_climat_voltage_cr123a    "CR123A"                        <energy>      (debug_sensor_climat) ["Temperature", "Voltage"] {widgetOrder="13", stateDescription=" "[pattern="%.3f V"]}
Number    debug_sensor_climat_voltage_a27       "A27/8LR732, A23/8LR932"        <energy>      (debug_sensor_climat) ["Temperature", "Voltage"] {widgetOrder="15", stateDescription=" "[pattern="%.3f V"]}
Number    debug_sensor_climat_voltage_476a      "A476A"                         <energy>      (debug_sensor_climat) ["Temperature", "Voltage"] {widgetOrder="16", stateDescription=" "[pattern="%.3f V"]}
Number    debug_sensor_climat_voltage_lr06      "AA/LR06, AAA/LR03"             <energy>      (debug_sensor_climat) ["Temperature", "Voltage"] {widgetOrder="18", stateDescription=" "[pattern="%.3f V"]}
Number    debug_sensor_climat_voltage_lr06x2    "2x, AA/LR06, AAA/LR03"         <energy>      (debug_sensor_climat) ["Temperature", "Voltage"] {widgetOrder="19", stateDescription=" "[pattern="%.3f V"]}
Number    debug_sensor_climat_voltage_nimh      "NiMH AA, AAA"                  <energy>      (debug_sensor_climat) ["Temperature", "Voltage"] {widgetOrder="20", stateDescription=" "[pattern="%.3f V"]}

Yes I use restoreOnStartup for dates and text.

I need access to history (in this rules and whole system). For example, all data that comes via SMS or Telegram will be saved in the database. If I use mapdb, I will be able to get only the last value.

Of course, I can use three databases

  1. rrd4j for standard types
  2. MAPDB for restoreOnStartup for text
  3. JDBC/PostgreSQL for storing text and dates

But it seems like too much )))

Maybe there is some way to fix this traditionally? For example, cancel the compilation of JS at system startup (as it was before) or set the conditions under which the compilation will go (wait for itemRegistry to be ready).

Now I have only one idea left: rewrite everything to DSLRule and hope that the problem goes away. But it would be a pity to lose a lot of time, as well as the flexibility of javascript.

Rule error on OH startup

Which is exactly why I think it’s a timing problem. In 4.3.2, the timing was just right where the problem was avoided. Note that only bug fixes are back ported so the number of changes between 4.3.0 and 4.3.5 is really minimal and only fixes major bugs where something significant is broken.

As far as I remember, there have been no changes to 4.3 related to OH startup or loading of the rules.

You can use more than one persistence. Use JDBC for all the history stuff and use MapDB only for restoreOnStartup.

If you are going to use Postgres anyway, why not just use it for everything and drop rrd4j?

Nothing you have control over.

If that fixes it I suspect it will be because Rules DSL takes a lot longer to compile so the ItemRegistry will be ready by the time it finally gets around to compiling the rule.

This problem has not been reported by anyone else and OH 4.3 has been out for a good long time now. JS is probably the most used language at this point. So there has to be something unique with your environment that is causing this problem.

I completely disagree with you.

You suggest choosing components based on system bugs (and looking for workarounds in a specific system build), and not on the provided functionality. In this case, there is a design error in the binding JS bundle and the rules compilation core.

Perhaps it is worth waiting until a critical number of complaints is collected and fixing the problem, but you need to understand that I waited a year, hoping for a fix. I think there are enough of these ā€œwaitersā€.

It seems to me that if someone from the development team (who is responsible for this code) should pay attention. Perhaps I could help with logs, experiments, debugging.

I want our system to be stable and understandable. For example, on the one hand, I am happy with the changes that took place in 2024-2025, but I am ready to say that in 2022-2023 our system was much more stable. Now, we very often get bugs.

Recently, my friend became interested in a smart home. And asked me to help him choose a system. To my great chagrin, I recommended HomeAssistant to him. I use/maintain two systems (OH - at my home and HA - at my parents’). I am thrilled with OpenHAB as a programmer, I like the way everything looks. But I am extremely unhappy with the constant bugs. In HA, everything is very simple, but it works and is easily configured by an ordinary person.

:frowning:

I am suggesting no such thing,

What I am saying is that what ever the problem is, it is subtle and rare. It might even be unique to you as no one else has reported this particular problem. This means we need to focus on those unique parts of your system that might be causing this as the majority of users are not experiencing these problems, and a plurality of users are using this JS rules.

My next suggestion was going to be to try it in OH 5.0 M2. If it’s still a problem there then we at least have a smallish set of PRs we can look at to see what changed to make it work and maybe get a fix backported.

But since I’m apparently not being helpful here I’ll wish you luck. I hope you find the help you need.

1 Like

I understand that you offered a solution to save me from suffering. I was not just looking for a workaround. I wanted to report an existing problem. Maybe someone (like you) knew about it and would say - we know, you are panicking in vain. Like for example with the problem due to which the semantic model is constantly collapsing for almost a year now. The problem was recently fixed, but has not yet been sent to the release.

Good idea, probably worth checking. I’ll try to do it soon.

You did what you could. Thank you very much for your help.

Unfortunately, I don’t understand at all where to go to get someone to pay attention to something and fix it. I’m just waiting a year or two for it to be fixed.

In this case, I just restart these rules according to the timer after the System has loaded in a few minutes.

But no where have I offered a solution or workaround at all. I’ve offered steps to take, experiments to try, and places to narrow the focus to try to find the root problem.

OH is a 100% volunteer project. People work on what they want to work on. Some problems get fixed immediately, some take a very long time, some never get addressed at all. It all depends on when/if someone volunteers to work on it.

That will only be a part of OH 5 because it’s part of a new feature. It will not be backported to OH 4.

Thanks, I’ll try to create a ticket in the bug tracker. Maybe someone will notice and fix it if possible. Unfortunately, I’m not strong in Java to fix it myself.