@@ -116,6 +116,37 @@ os_helpers_fetch_target_state() {
116116 return 0
117117 fi
118118 fi
119+
120+ # A supervisor release that is still a draft is never published as a supervisor_release row, so the
121+ # query above finds nothing even though the device is pinned to it and the target state does carry
122+ # the release and its `core` image. Resolving `core` from the target state is what lets a device
123+ # pinned to a draft actually run it; without it the device silently keeps whatever supervisor the
124+ # image preloaded, and the pin only ever moves the app-scoped services.
125+ if _state=$( api_get_request " ${_api_env} /device/v3/${_device_uuid} /state" " ${_token} " ) ; then
126+ _core=$( echo " ${_state} " | jq -r '
127+ .[] | .apps | to_entries[]
128+ | select(.value.class == "app" and (.value.is_host | not))
129+ | .value.releases | to_entries[]
130+ | select(.value.services.core != null)
131+ | "\(.value.id) \(.value.services.core.image)"' 2> /dev/null | head -1)
132+ if [ -n " ${_core} " ]; then
133+ _release_id=" ${_core%% * } "
134+ _image_name=" ${_core#* } "
135+ # The target state carries the release id but not its version, so ask for the version
136+ # separately and fall back to the id rather than failing: the image is what has to be right.
137+ _version=" "
138+ if _release=$( api_get_request " ${_api_env} /v6/release(id=${_release_id} )?\$ select=raw_version" " ${_token} " ) ; then
139+ _version=$( echo " ${_release} " | jq -r ' .d[0].raw_version // empty' 2> /dev/null)
140+ fi
141+ [ -n " ${_version} " ] || _version=" ${_release_id} "
142+ case " ${_version} " in
143+ v* ) ;;
144+ * ) _version=" v${_version} " ;;
145+ esac
146+ echo " ${_version} ${_image_name} "
147+ return 0
148+ fi
149+ fi
119150 return 1
120151}
121152
0 commit comments