JSScripting persistedState inconsistent

I have a JSScripting rule which randomly fails sometimes (running once per minute). The failure comes from the fact that persistedState returns null, but only occasionally.

The item in question exists and has plenty of persisted data:

The item is defined statically in the rule, and the postUpdate method never fails (or at least never leaves any log indication of failing):

var totalItem = items.getItem("Sensor_Flume_Total")
totalItem.postUpdate(flmUsage.data[0].dailyTotal[0].value)

If I follow that postUpdate with

console.debug(utils.dumpObject(totalItem.persistence.persistedState(time.ZonedDateTime.now().minusMinutes(1))))

I see inconsistent results. For example, at 8:30 a persistedItem is returned:

2025-06-14 08:30:02.150 [INFO ] [.openhab.automation.openhab-js.utils] - Dumping object...
2025-06-14 08:30:02.150 [INFO ] [.openhab.automation.openhab-js.utils] -   typeof obj = object
2025-06-14 08:30:02.150 [INFO ] [.openhab.automation.openhab-js.utils] -   Java.isJavaObject(obj) = false
2025-06-14 08:30:02.150 [INFO ] [.openhab.automation.openhab-js.utils] -   Java.isType(obj) = false
2025-06-14 08:30:02.150 [INFO ] [.openhab.automation.openhab-js.utils] -   getOwnPropertyNames(obj) = rawState,rawHistoricItem
2025-06-14 08:30:02.151 [INFO ] [.openhab.automation.openhab-js.utils] -   getAllPropertyNames(obj) = rawState,rawHistoricItem,constructor,timestamp,instant,toString,state,numericState,quantityState,__proto__,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,valueOf,__defineGetter__,__defineSetter__,__lookupGetter__,__lookupSetter__

One minute later, null is returned:

2025-06-14 08:31:01.229 [INFO ] [.openhab.automation.openhab-js.utils] - Dumping object...
2025-06-14 08:31:01.229 [INFO ] [.openhab.automation.openhab-js.utils] -   typeof obj = object
2025-06-14 08:31:01.230 [INFO ] [.openhab.automation.openhab-js.utils] -   Java.isJavaObject(obj) = false
2025-06-14 08:31:01.230 [INFO ] [.openhab.automation.openhab-js.utils] -   Java.isType(obj) = false
2025-06-14 08:31:01.230 [INFO ] [.openhab.automation.openhab-js.utils] -   value = null

null is returned for several subsequent runs until at 8:35 a persistedItem is returned again:

2025-06-14 08:34:01.179 [INFO ] [.openhab.automation.openhab-js.utils] - Dumping object...
2025-06-14 08:34:01.179 [INFO ] [.openhab.automation.openhab-js.utils] -   typeof obj = object
2025-06-14 08:34:01.179 [INFO ] [.openhab.automation.openhab-js.utils] -   Java.isJavaObject(obj) = false
2025-06-14 08:34:01.179 [INFO ] [.openhab.automation.openhab-js.utils] -   Java.isType(obj) = false
2025-06-14 08:34:01.179 [INFO ] [.openhab.automation.openhab-js.utils] -   value = null
...
2025-06-14 08:35:02.266 [INFO ] [.openhab.automation.openhab-js.utils] - Dumping object...
2025-06-14 08:35:02.266 [INFO ] [.openhab.automation.openhab-js.utils] -   typeof obj = object
2025-06-14 08:35:02.266 [INFO ] [.openhab.automation.openhab-js.utils] -   Java.isJavaObject(obj) = false
2025-06-14 08:35:02.266 [INFO ] [.openhab.automation.openhab-js.utils] -   Java.isType(obj) = false
2025-06-14 08:35:02.266 [INFO ] [.openhab.automation.openhab-js.utils] -   getOwnPropertyNames(obj) = rawState,rawHistoricItem
2025-06-14 08:35:02.267 [INFO ] [.openhab.automation.openhab-js.utils] -   getAllPropertyNames(obj) = rawState,rawHistoricItem,constructor,timestamp,instant,toString,state,numericState,quantityState,__proto__,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,valueOf,__defineGetter__,__defineSetter__,__lookupGetter__,__lookupSetter__

I’ve just got the default rrd4j installation as my default persistence:

configurations:
  - items:
      - "*"
    strategies:
      - restoreOnStartup
      - everyChange
      - everyMinute
    filters: []
aliases: {}
cronStrategies:
  - name: everyMinute
    cronExpression: 0 * * * * ?
defaultStrategies:
  - restoreOnStartup
  - everyChange
  - everyMinute
thresholdFilters: []
timeFilters: []
equalsFilters: []
includeFilters: []

This behavior seems off to me. Once persistedState returns a valid persistedItem that demonstrates that there is persisted data for that item. So, shouldn’t all subsequent calls return something? I’m requesting data every minute from rrd4j, that data is there and should correspond pretty well with my request and even if there isn’t a value near the specific timepoint I’m requesting it should fall back to the nearest previous timepoint, correct?

I’m currently on 5.0M2, but this has been around for a while (I just haven’t had a chance to investigate until now).

Can you check again with 5.0M3? There was a recent bug fix in rrd4j that may be related: [rrd4j] Bugfix descending order by weymann · Pull Request #18789 · openhab/openhab-addons · GitHub

I’m leaving on a trip this morning. I’ll definitely upgrade to M3 on my return and let you know.