This commit is contained in:
2026-03-21 17:23:26 -07:00
parent 4160e1cca4
commit f09f66ff9a
2 changed files with 156 additions and 37 deletions

View File

@@ -847,8 +847,9 @@ local _last_ipc_error = ''
local _last_ipc_last_req_json = ''
local _last_ipc_last_resp_json = ''
-- Debounce helper start attempts (window in seconds)
local _helper_start_debounce_ts = 0
-- Debounce helper start attempts (window in seconds).
-- Initialize below zero so the very first startup attempt is never rejected.
local _helper_start_debounce_ts = -1000
local HELPER_START_DEBOUNCE = 2.0
-- Track ready-heartbeat freshness so stale or non-timestamp values don't mask a stopped helper
@@ -891,10 +892,12 @@ local function _is_pipeline_helper_ready()
if age <= HELPER_READY_STALE_SECONDS then
return true
end
return false
end
end
-- Fall back to the last time we observed a new value so stale data does not appear fresh.
-- Fall back only for non-timestamp values so stale helper timestamps from a
-- previous session do not look fresh right after Lua reload.
if _helper_ready_last_seen_ts > 0 and (now - _helper_ready_last_seen_ts) <= HELPER_READY_STALE_SECONDS then
return true
end
@@ -963,12 +966,17 @@ local function attempt_start_pipeline_helper_async(callback)
-- Debounce: don't spawn multiple helpers in quick succession
local now = mp.get_time()
if (now - _helper_start_debounce_ts) < HELPER_START_DEBOUNCE then
if _helper_start_debounce_ts > -1 and (now - _helper_start_debounce_ts) < HELPER_START_DEBOUNCE then
_lua_log('attempt_start_pipeline_helper_async: debounced (recent attempt)')
callback(false)
return
end
_helper_start_debounce_ts = now
-- Clear any stale ready heartbeat from an earlier helper instance before spawning.
pcall(mp.set_property, PIPELINE_READY_PROP, '')
_helper_ready_last_value = ''
_helper_ready_last_seen_ts = 0
local python = _resolve_python_exe(true)
if not python or python == '' then
@@ -2137,7 +2145,8 @@ local function _capture_screenshot()
end
if selected_store == '' then
mp.osd_message('Select a store first (Store button)', 2)
_pending_screenshot = { path = out_path }
_open_store_picker_for_pending_screenshot()
return
end
@@ -2614,6 +2623,7 @@ _refresh_store_cache = function(timeout_seconds, on_complete)
local prev_count = (type(_cached_store_names) == 'table') and #_cached_store_names or 0
local prev_key = _store_names_key(_cached_store_names)
local had_previous = prev_count > 0
local cached_json = mp.get_property('user-data/medeia-store-choices-cached')
_lua_log('stores: cache_read cached_json=' .. tostring(cached_json) .. ' len=' .. tostring(cached_json and #cached_json or 0))
@@ -2632,8 +2642,15 @@ _refresh_store_cache = function(timeout_seconds, on_complete)
out[#out + 1] = name
end
end
if #out == 0 and had_previous then
_lua_log('stores: ignoring empty cache payload; keeping previous store list')
if type(on_complete) == 'function' then
on_complete(true, false)
end
return true
end
_cached_store_names = out
_store_cache_loaded = true
_store_cache_loaded = (#out > 0) or _store_cache_loaded
local preview = ''
if #out > 0 then
preview = table.concat(out, ', ')
@@ -2694,15 +2711,21 @@ _refresh_store_cache = function(timeout_seconds, on_complete)
out[#out + 1] = name
end
end
_cached_store_names = out
_store_cache_loaded = true
local preview = ''
if #out > 0 then
preview = table.concat(out, ', ')
if #out == 0 and had_previous then
_lua_log('stores: helper returned empty store list; keeping previous store list')
success = true
changed = false
else
_cached_store_names = out
_store_cache_loaded = (#out > 0) or _store_cache_loaded
local preview = ''
if #out > 0 then
preview = table.concat(out, ', ')
end
_lua_log('stores: loaded ' .. tostring(#out) .. ' stores via helper request: ' .. tostring(preview))
success = true
changed = (#out ~= prev_count) or (_store_names_key(out) ~= prev_key)
end
_lua_log('stores: loaded ' .. tostring(#out) .. ' stores via helper request: ' .. tostring(preview))
success = true
changed = (#out ~= prev_count) or (_store_names_key(out) ~= prev_key)
else
_lua_log(
'stores: failed to load store choices via helper; success='