This commit is contained in:
2026-03-22 00:59:03 -07:00
parent 3e922f7b3a
commit 6d1a4d8bfc
2 changed files with 132 additions and 38 deletions

View File

@@ -4,7 +4,7 @@ local msg = require 'mp.msg'
local M = {}
local MEDEIA_LUA_VERSION = '2026-03-21.4'
local MEDEIA_LUA_VERSION = '2026-03-22.1'
-- Expose a tiny breadcrumb for debugging which script version is loaded.
pcall(mp.set_property, 'user-data/medeia-lua-version', MEDEIA_LUA_VERSION)
@@ -880,7 +880,7 @@ local function _is_pipeline_helper_ready()
helper_version = mp.get_property_native('user-data/medeia-pipeline-helper-version')
end
helper_version = tostring(helper_version or '')
if helper_version ~= '2026-03-22.5' then
if helper_version ~= '2026-03-22.6' then
return false
end
@@ -947,7 +947,7 @@ local function _helper_ready_diagnostics()
end
return 'ready=' .. tostring(ready or '')
.. ' helper_version=' .. tostring(helper_version or '')
.. ' required_version=2026-03-22.5'
.. ' required_version=2026-03-22.6'
.. ' last_value=' .. tostring(_helper_ready_last_value or '')
.. ' last_seen_age=' .. tostring(age)
end
@@ -1037,8 +1037,53 @@ local function attempt_start_pipeline_helper_async(callback)
return
end
local args = { python, '-m', 'MPV.pipeline_helper', '--ipc', get_mpv_ipc_path(), '--timeout', '30' }
_lua_log('attempt_start_pipeline_helper_async: spawning helper python=' .. tostring(python))
local helper_script = ''
local repo_root = _detect_repo_root()
if repo_root ~= '' then
local direct = utils.join_path(repo_root, 'MPV/pipeline_helper.py')
if _path_exists(direct) then
helper_script = direct
end
end
if helper_script == '' then
local candidates = {}
local seen = {}
local source_dir = _get_lua_source_path():match('(.*)[/\\]') or ''
local script_dir = mp.get_script_directory() or ''
local cwd = utils.getcwd() or ''
_append_unique_path(candidates, seen, find_file_upwards(source_dir, 'MPV/pipeline_helper.py', 8))
_append_unique_path(candidates, seen, find_file_upwards(script_dir, 'MPV/pipeline_helper.py', 8))
_append_unique_path(candidates, seen, find_file_upwards(cwd, 'MPV/pipeline_helper.py', 8))
for _, candidate in ipairs(candidates) do
if _path_exists(candidate) then
helper_script = candidate
break
end
end
end
if helper_script == '' then
_lua_log('attempt_start_pipeline_helper_async: pipeline_helper.py not found')
finish(false)
return
end
local launch_root = repo_root
if launch_root == '' then
launch_root = helper_script:match('(.*)[/\\]MPV[/\\]') or (helper_script:match('(.*)[/\\]') or '')
end
local bootstrap = table.concat({
'import os, runpy, sys',
'script = sys.argv[1]',
'root = sys.argv[2]',
'if root:',
' os.chdir(root)',
' sys.path.insert(0, root) if root not in sys.path else None',
'sys.argv = [script] + sys.argv[3:]',
'runpy.run_path(script, run_name="__main__")',
}, '\n')
local args = { python, '-c', bootstrap, helper_script, launch_root, '--ipc', get_mpv_ipc_path(), '--timeout', '30' }
_lua_log('attempt_start_pipeline_helper_async: spawning helper python=' .. tostring(python) .. ' script=' .. tostring(helper_script) .. ' root=' .. tostring(launch_root))
-- Spawn detached; don't wait for it here (async).
local ok, result, detail = _run_subprocess_command({ name = 'subprocess', args = args, detach = true })
@@ -1056,7 +1101,9 @@ local function attempt_start_pipeline_helper_async(callback)
end
-- Wait for helper to become ready in background (non-blocking).
local deadline = mp.get_time() + 3.0
-- 12 s gives Python time to kill a stale lock holder (PS scan + taskkill)
-- and publish its first ready heartbeat before we give up.
local deadline = mp.get_time() + 12.0
local timer
timer = mp.add_periodic_timer(0.1, function()
if _is_pipeline_helper_ready() then
@@ -1068,6 +1115,9 @@ local function attempt_start_pipeline_helper_async(callback)
if mp.get_time() >= deadline then
timer:kill()
_lua_log('attempt_start_pipeline_helper_async: timeout waiting for ready')
-- Reset debounce so the next attempt is not immediate; gives the
-- still-running Python helper time to die or acquire the lock.
_helper_start_debounce_ts = mp.get_time()
finish(false)
end
end)