Skip to content

Free, open-source AI video generator for Mac. Run LTX-2.5 and MiniMax H3 (Hailuo) locally on Apple Silicon: text-to-video and image-to-video with sound, lip-sync, character LoRA training, songs from lyrics (YuE2) and image editing (Qwen-Image-Edit). One-click install via Pinokio. Offline: no cloud, no API key, no NVIDIA GPU.

feat(agent): auto-pause local engine during LTX renders

mrbizarro97783d2f600b
diff --git a/agent/engine.py b/agent/engine.py
index 3ac960e..5b733ea 100644
--- a/agent/engine.py
+++ b/agent/engine.py
@@ -63,6 +63,19 @@ class EngineConfig:
# chat is instant. Use only when the Mac has headroom
# (no concurrent renders, or a small chat model).
mode: str = "plan_sleep"
+ # When True (default), the panel auto-stops the local engine the moment
+ # the LTX worker picks up a render job, and auto-restarts it once the
+ # queue drains. Solves the 64 GB Mac swap-thrash problem where the
+ # chat model (~7-22 GB resident) and the LTX renderer (~22-30 GB)
+ # compete for unified memory and the system pages out denoise tensors.
+ # Only applies when kind == "phosphene_local"; cloud engines (anthropic,
+ # ollama-on-localhost, custom) don't compete for RAM and are never
+ # paused. Caveat: an agent in `interactive` mode that's mid-turn when
+ # a render starts will see its in-flight engine.chat() fail; the
+ # runtime surfaces this and the user retries after the queue drains.
+ # In `plan_sleep` mode the agent always finishes before submitting,
+ # so no conflict.
+ auto_pause_during_renders: bool = True
def to_public_dict(self) -> dict:
"""Strip the api_key for safe display in /agent/config GETs."""
diff --git a/mlx_ltx_panel.py b/mlx_ltx_panel.py
index df5c991..f72a596 100644
--- a/mlx_ltx_panel.py
+++ b/mlx_ltx_panel.py
@@ -3389,6 +3389,13 @@ def run_job_inner(job: dict) -> None:
# ---- worker thread -----------------------------------------------------------
def worker_loop() -> None:
+ # Auto-pause bookkeeping. When the local agent engine is running and
+ # the user has `auto_pause_during_renders=True` (default), we stop
+ # mlx-lm.server before the LTX render starts and restart it after
+ # the queue drains. The flag survives across multiple jobs in the
+ # same batch so the engine isn't reload-thrashed between shots —
+ # one stop at the start of a render burst, one start at the end.
+ auto_paused = False
while True:
with QUEUE_COND:
while not STATE["queue"] or STATE["paused"]:
@@ -3405,6 +3412,27 @@ def worker_loop() -> None:
caffeinate_on()
persist_queue()
+ # Auto-pause local engine before the render starts. Kept inside
+ # the per-iteration body (NOT lifted to the top of the loop) so
+ # the pause never fires when the queue has been empty all along
+ # — only when there's actual work about to run. Idempotent:
+ # subsequent iterations within the same batch see is_running()
+ # return False and skip the stop.
+ if not auto_paused:
+ try:
+ _agent_cfg = _load_agent_config()
+ if (getattr(_agent_cfg, "auto_pause_during_renders", True)
+ and getattr(_agent_cfg, "kind", "") == "phosphene_local"
+ and agent_local_server.is_running()):
+ agent_local_server.stop("auto-pause: LTX render starting")
+ auto_paused = True
+ push("[engine] paused for render — will resume when queue drains")
+ except Exception as exc: # noqa: BLE001
+ # Auto-pause is a nicety; if it errors, the render still
+ # runs (the user just pays the swap tax). Surface the
+ # reason in the job log for diagnosis without aborting.
+ push(f"[engine] auto-pause check failed (continuing): {exc}")
+
try:
run_job_inner(job)
job["status"] = "done"
@@ -3429,6 +3457,25 @@ def worker_loop() -> None:
STATE["pgid"] = None
persist_queue()
+ # Resume the local engine ONLY when the queue is fully drained
+ # (no current job, nothing queued). If more jobs follow this
+ # one we stay paused — restarting between every shot would
+ # cost ~10 s × N reloads for nothing. The next iteration of
+ # the outer loop will block on QUEUE_COND.wait until either
+ # a new job arrives (still paused, fine) or… well, this
+ # branch fires here on the way out.
+ if auto_paused:
+ with LOCK:
+ queue_drained = (not STATE["queue"]) and (STATE["current"] is None)
+ if queue_drained:
+ try:
+ _agent_local_start()
+ push("[engine] resumed after render")
+ auto_paused = False
+ except Exception as exc: # noqa: BLE001
+ push(f"[engine] resume failed (try Settings → Agent → Start): {exc}")
+ auto_paused = False # don't keep retrying on every job
+
# ---- Agentic Flows integration -----------------------------------------------
#