Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.
Bound generation lease waits and classify engine contention
Bowen Xue2c03c29204f8
diff --git a/freevideo_engine/failure_details.py b/freevideo_engine/failure_details.pyindex 407d905..920a1da 100644--- a/freevideo_engine/failure_details.py+++ b/freevideo_engine/failure_details.py@@ -6,6 +6,7 @@ import reimport sysfrom .long_paths import io_path, plain_text+from .locking import ENGINE_BUSYfrom .diagnostics import Redactorfrom .tiers import STEP_CACHES, TIERS, on_mac, table_levelfrom .two_pass import SCALES@@ -13,6 +14,11 @@ from .two_pass import SCALESSTEP_OUTPUT = '\n\nFull step output:\n'QUALITY_LEVELS = (('Light', '轻量'), ('Medium', '标准'), ('High', '精细'), ('Max', '极致')) # tiers.TIERS order+ENGINE_BUSY_TITLE = ('FreeVideo is busy with another task', 'FreeVideo 正在处理另一个任务')+ENGINE_BUSY_DETAIL = (+ 'Try again when it finishes. If nothing else is running, close duplicate FreeVideo instances, then try again.',+ '请在它完成后重试。若没有其他任务在进行,请关闭重复运行的 FreeVideo 后重试。',+)IMAGE_PACK_FAILURES = {@@ -354,6 +360,12 @@ def launcher_failure(value, *, zh=False, other_disk=False, disk_name='', can_repif not value:return dict(title='', detail='', action='', kind='')text = _without_ready_curl_diagnostics(str(value))+ # Match only the cause position, never an echoed input or a log line below it.+ causes = [line.strip() for line in text.splitlines() if line.strip()]+ index = 1 if causes and re.fullmatch(r'FreeVideo generation failed(?: \(exit -?\d+\))?', causes[0]) else 0+ cause = re.sub(r'^(?:[A-Za-z_][\w.]*(?:Error|Exception)):\s*', '', causes[index]) if len(causes) > index else ''+ if cause == ENGINE_BUSY:+ return dict(title=ENGINE_BUSY_TITLE[zh], detail=ENGINE_BUSY_DETAIL[zh], action='', kind='engine-busy')from .offline_errors import alias_failure, guidanceif alias_failure(text):return dict(title=guidance('title', zh), detail=guidance('runtime-alias', zh),@@ -707,6 +719,11 @@ def generation_failure(run, exit_code=None, *, repair=None):lines = ['FreeVideo generation failed' + (' (exit %s)' % exit_code if exit_code is not None else '')]report = _report(run)redactor.structured(report) # Collect prompt values without showing the request.+ # Read the whole bounded log, not a tail that could hide other output.+ # A legacy managed failure has exactly this one nonempty line and exit 1.+ if exit_code == 1 and [line for line in _read(run / 'generate.log', 8192).splitlines()+ if line.strip()] == [ENGINE_BUSY]:+ lines.append(ENGINE_BUSY)# What the worker found when cuDNN refused its own files, ahead of the trace.explained = _runtime_explanation(report, REPAIR_MARK)if explained:diff --git a/freevideo_engine/locking.py b/freevideo_engine/locking.pyindex 9110dd8..9524bc6 100644--- a/freevideo_engine/locking.py+++ b/freevideo_engine/locking.py@@ -6,10 +6,12 @@ therefore still excludes every device. Without this split one measurementoccupied an entire multi-GPU host."""from contextlib import contextmanager+import mathimport osfrom pathlib import Pathimport reimport sys+import timefrom .paths import data_root@@ -17,6 +19,7 @@ from .system import windowsfrom .processes import inherited_fdLOCK_PATH = Path(os.environ.get('FREEVIDEO_LOCK_PATH', data_root() / 'engine.lock'))LOCK_ENV = 'FREEVIDEO_RUNTIME_LOCK_FD'+ENGINE_BUSY = 'Setup, testing or generation is already using this installation/GPU lock. Retry after it finishes.'def lock_holders(paths):@@ -56,7 +59,10 @@ def device_lock_path(device, path=None):@contextmanager-def runtime_lock(path=None, *, inherit=True, shared=False):+def runtime_lock(path=None, *, inherit=True, shared=False, wait_seconds=0):+ """Take a lease, optionally waiting a bounded time for acquisition only."""+ if not math.isfinite(wait_seconds) or wait_seconds < 0:+ raise ValueError('Runtime lock wait must be finite and nonnegative')path = Path(path or os.environ.get('FREEVIDEO_LOCK_PATH', data_root() / 'engine.lock'))path.parent.mkdir(parents=True, exist_ok=True)inherited = inherited_fd() if inherit else None@@ -71,23 +77,36 @@ def runtime_lock(path=None, *, inherit=True, shared=False):try:# An inherited descriptor shares the parent's open-file description.# Close our descriptor on exit; do not unlock the parent's live work.- if windows():- if inherited is None:- import msvcrt- if path.stat().st_size == 0:- stream.write(b'\0')- stream.flush()- stream.seek(0)- try:- msvcrt.locking(stream.fileno(),- msvcrt.LK_NBRLCK if shared else msvcrt.LK_NBLCK, 1)- except OSError as error:- raise BlockingIOError('Another process holds the installation lease') from error- # The parent holds the byte-range lock; its Job Object owns this- # worker tree. Closing a duplicated child handle must not unlock it.- else:- import fcntl- fcntl.flock(stream, (fcntl.LOCK_SH if shared else fcntl.LOCK_EX) | fcntl.LOCK_NB)+ deadline = time.monotonic() + wait_seconds+ while True:+ try:+ if windows():+ if inherited is None:+ import msvcrt+ if path.stat().st_size == 0:+ stream.write(b'\0')+ stream.flush()+ stream.seek(0)+ try:+ msvcrt.locking(stream.fileno(),+ msvcrt.LK_NBRLCK if shared else msvcrt.LK_NBLCK, 1)+ except OSError as error:+ raise BlockingIOError('Another process holds the installation lease') from error+ # The parent holds the byte-range lock; its Job Object owns this+ # worker tree. Closing a duplicated child handle must not unlock it.+ else:+ import fcntl+ fcntl.flock(stream, (fcntl.LOCK_SH if shared else fcntl.LOCK_EX) | fcntl.LOCK_NB)+ break+ except BlockingIOError:+ remaining = deadline - time.monotonic()+ if remaining <= 0:+ raise+ time.sleep(min(0.075, remaining))+ # A delayed wakeup must not start another attempt after budget.+ if time.monotonic() >= deadline:+ raise+ # The body is outside the retry loop: a failed request must never rerun.yield stream.fileno()finally:# Releasing the lease must not discard completed work. Taking it stilldiff --git a/freevideo_engine/managed.py b/freevideo_engine/managed.pyindex 7954b11..25ef5a8 100644--- a/freevideo_engine/managed.py+++ b/freevideo_engine/managed.py@@ -9,7 +9,7 @@ import sysfrom .agent import enabled as agent_enabledfrom .bootstrap import DEFAULT_ROOTfrom . import __version__-from .locking import runtime_lock, LOCK_ENV+from .locking import runtime_lock, LOCK_ENV, ENGINE_BUSYfrom . import processesfrom .system import windows@@ -117,7 +117,7 @@ def _main(argv=None):or (command == 'doctor' and '--probe' not in tail) or '--help' in tail or '-h' in tail)snapshot = json.loads(config.read_text(encoding='utf-8'))lock_path = os.environ.get('FREEVIDEO_LOCK_PATH', str(Path(snapshot['root']) / 'engine.lock'))- with nullcontext() if readonly else runtime_lock(lock_path) as descriptor:+ with nullcontext() if readonly else runtime_lock(lock_path, wait_seconds=3 if command == 'generate' else 0) as descriptor:machine = json.loads(config.read_text(encoding='utf-8'))if machine != snapshot:raise ValueError('Installation changed while starting. Rerun the command.')@@ -140,7 +140,7 @@ def main(argv=None):try:return _main(argv)except BlockingIOError:- print('Setup, testing or generation is already using this installation/GPU lock. Retry after it finishes.', file=sys.stderr)+ print(ENGINE_BUSY, file=sys.stderr)return 1except KeyboardInterrupt:print('Cancelled. Workers stopped; existing outputs and reports retained.', file=sys.stderr)diff --git a/web/error_panel.js b/web/error_panel.jsindex c268f97..cab18bc 100644--- a/web/error_panel.js+++ b/web/error_panel.js@@ -12,6 +12,10 @@ const record = value => value && typeof value === 'object' && !Array.isArray(val// The engine's own messages for errors people can fix themselves.const PLAIN_ERRORS = [+ {key: 'engine-busy', message: 'Setup, testing or generation is already using this installation/GPU lock. Retry after it finishes.',+ title: ['FreeVideo is busy with another task', 'FreeVideo 正在处理另一个任务'],+ summary: ['Try again when it finishes. If nothing else is running, close duplicate FreeVideo instances, then try again.',+ '请在它完成后重试。若没有其他任务在进行,请关闭重复运行的 FreeVideo 后重试。']},{key: 'continuation-missing', message: 'The previous video has no usable continuation data. Generate it again with this version of FreeVideo.',title: ['This video cannot be continued', '这个视频暂时不能接续'],summary: ['Generate the previous video again, then continue it.', '请重新生成上一段视频,再接续。']},