Repository navigation
disable_limits_group requiring multiple runs to disable all limits #3932
Description
Activity
Analysis
Looking at the
disable_limits_groupimplementation , I see a likely root cause for the "have to disable multiple times" symptom.Root cause hypothesis: exception mid-loop leaves later packets untouched
def _limits_group(group_name, action:, manual:, scope:, token:) ... group.sort.each do |target_name, packet_name, item_name| if last_target_name != target_name || last_packet_name != packet_name if last_target_name && last_packet_name TargetModel.set_packet(last_target_name, last_packet_name, packet, scope: scope) end packet = TargetModel.packet(target_name, packet_name, scope: scope) end packet['items'].each do |item| if item['name'] == item_name if action == :enable item['limits']['enabled'] = true elsif action == :disable item['limits']['enabled'] = false # <-- no ||= {} guard end ... end end last_target_name = target_name last_packet_name = packet_name end if last_target_name && last_packet_name TargetModel.set_packet(last_target_name, last_packet_name, packet, scope: scope) end end
Notice
item['limits']['enabled'] = falseassumesitem['limits']already exists as a Hash. Compare this toset_state_colorelsewhere in the same file, which explicitly doesitem['limits'] ||= {}before setting a key on it.If any item added via
LIMITS_GROUP_ITEMdoes not already have aLIMITSdefinition on it (i.e.item['limits']isnil), this line raisesNoMethodError: undefined method '[]=' for nil:NilClass. Because packets are processed and written back toTargetModel.set_packetonly when the target/packet changes (i.e., after the fact), an exception partway through a 70k‑item, multi‑packet group would:- Persist changes for packets already completed before the failure,
- Abort processing for everything after the failure point (that batch's
set_packetwrite never happens), - Leave the rest of the group's items still "enabled," so you'd keep seeing OOL alarms.
Since the item order comes from
group.sort, re-runningdisable_limits_groupwould make it further through the list each time before hitting the next offending item — explaining why it takes ~4 runs to fully "stick."What would help confirm this
Could you check the Script Runner / cmd-tlm-api logs right after you call
disable_limits_groupon the 70k-item group? Look for a Ruby exception likeundefined method '[]=' for nil:NilClassaround the time of the call. If present, that confirms the bug is items in yourLIMITS_GROUPlacking an actualLIMITSdefinition.Possible quick fix
Adding
item['limits'] ||= {}before line 428/432 (mirroring theset_state_colorpattern) would prevent the exception and let the whole group process in one pass.If you can share a snippet of the logs from a failing disable call, that will help confirm/refute this theory before an engineer picks it up.
Describe the bug
have 6 limit groups/sets:
70113 _limits_group_DEFAULT.txt
6916 _limits_group_Default_Default.txt
7013 _limits_group_Mission_Default.txt
5092 _limits_group_On_Station_Default.txt
262 _limits_group_On_Station_Eclipse.txt
804 _limits_group_On_Station_StationChg.txt
90200 total
have to disable multiple time to truly get the limits off, typically 4 times.
To Reproduce
create db/limit group with 70k items (use point size/type limits for the default set)
disable the limit group and see if still getting ool
Expected behavior
1 run turns limits off for a given group.
Screenshots
No response
OS
Alma9x
OpenC3 COSMOS Version
7.3.0
Browser
Chrome