Skip to content

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.

Enable agent API by default and isolate startup failures

Bowen Xue22d4ab36a86d
diff --git a/__init__.py b/__init__.py
index ef16ef7..43f0a9a 100644
--- a/__init__.py
+++ b/__init__.py
@@ -33,7 +33,11 @@ async def comfy_entrypoint():
share_routes()
from .freevideo_engine.comfy_metadata import register as workflow_backfill
workflow_backfill()
- from .freevideo_engine.agent.routes import register as agent_routes
- agent_routes()
+ try:
+ from .freevideo_engine.agent.routes import register as agent_routes
+ agent_routes()
+ except Exception as error:
+ import logging
+ logging.warning('[FreeVideo] Agent routes not registered: %s', error)
from .freevideo_engine.comfy_nodes import FreeVideoExtension
return FreeVideoExtension()
diff --git a/freevideo_engine/agent/__init__.py b/freevideo_engine/agent/__init__.py
index af92663..4fd5b4f 100644
--- a/freevideo_engine/agent/__init__.py
+++ b/freevideo_engine/agent/__init__.py
@@ -1,8 +1,8 @@
"""Agent-native control of FreeVideo: job specs, media tools, headless edits and MCP.
-The agent features are held back for now: they stay off, with no routes, token,
-commands or controls, unless FREEVIDEO_AGENT=1 is set where ComfyUI runs (and
-for the agent and mcp commands)."""
+Agent features are enabled by default. Set FREEVIDEO_AGENT=0 (or false, no, off)
+where ComfyUI runs and for the managed commands to disable the agent API, token,
+commands and controls."""
import os
API_VERSION = 1
@@ -10,6 +10,6 @@ SWITCH = 'FREEVIDEO_AGENT'
def enabled(environ=None):
- """Whether the agent features are on: FREEVIDEO_AGENT=1 (or true, yes, on)."""
+ """On by default; only FREEVIDEO_AGENT=0/false/no/off explicitly disables it."""
value = (os.environ if environ is None else environ).get(SWITCH, '')
- return value.strip().lower() in ('1', 'true', 'yes', 'on')
+ return value.strip().lower() not in ('0', 'false', 'no', 'off')
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index 7b98b7e..25ec2f6 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -298,7 +298,8 @@ def register():
from aiohttp import web
from server import PromptServer
server = PromptServer.instance
- if server is None or getattr(server, '_freevideo_agent', None) is not None:
+ if (server is None or getattr(server, '_freevideo_agent', None) is not None
+ or getattr(server, '_freevideo_agent_registered', False)):
return
from .. import proxy_identity
hop_secret = os.environ.pop(proxy_identity.ENV, '')
@@ -313,18 +314,25 @@ def register():
async def off(request):
return web.json_response({'enabled': False}, headers={'Cache-Control': 'no-store'})
return
- from .comfy import ComfyPort
- port = ComfyPort(server)
- jobs = Jobs(port, port.output_root / 'FreeVideo' / '.agent' / 'jobs')
- server._freevideo_agent = jobs
- from .sessions import Confirmations, Sessions
- sessions = Sessions(port.output_root / 'FreeVideo' / '.agent' / 'sessions')
- server._freevideo_agent_sessions = sessions
- # The user's stop also cancels this session's queued and running agent work and pauses its productions.
- sessions.on_stop.append(lambda sid: asyncio.to_thread(jobs.stop_session, sid))
- # Operations an agent runs only after the user approves them; the page changes the policy.
- confirmations = Confirmations(port.output_root / 'FreeVideo' / '.agent' / 'confirm.json', sessions)
- jobs.productions.gate = confirmations.gate
+ startup_failed = False
+ try:
+ from .comfy import ComfyPort
+ from .sessions import Confirmations, Sessions
+ port = ComfyPort(server)
+ jobs = Jobs(port, port.output_root / 'FreeVideo' / '.agent' / 'jobs')
+ sessions = Sessions(port.output_root / 'FreeVideo' / '.agent' / 'sessions')
+ # The user's stop also cancels this session's queued and running agent work and pauses its productions.
+ sessions.on_stop.append(lambda sid: asyncio.to_thread(jobs.stop_session, sid))
+ # Operations an agent runs only after the user approves them; the page changes the policy.
+ confirmations = Confirmations(port.output_root / 'FreeVideo' / '.agent' / 'confirm.json', sessions)
+ jobs.productions.gate = confirmations.gate
+ except Exception as error:
+ # Optional agent state must never prevent the studio or other routes from loading.
+ logging.getLogger(__name__).warning('[FreeVideo] Agent startup unavailable: %s', error)
+ startup_failed = True
+ else:
+ server._freevideo_agent = jobs
+ server._freevideo_agent_sessions = sessions
tokens = {}
token_failures = set()
thumbnails = asyncio.Semaphore(1)
@@ -349,7 +357,10 @@ def register():
def prepare_token(root):
# Startup and public connection help share authentication's Windows cache.
- return expected(root) if os.name == 'nt' else ensure_token(root)
+ try:
+ return expected(root) if os.name == 'nt' else ensure_token(root)
+ except (OSError, ValueError):
+ raise TokenUnavailable() from None
def reply(value, status=200):
return web.json_response(value, status=status, headers={'Cache-Control': 'no-store'},
@@ -384,6 +395,8 @@ def register():
attached = None
suffix = ''
try:
+ if startup_failed:
+ raise JobError('not_ready', 'Agent startup unavailable')
suffix = request.match_info.route.resource.canonical
suffix = suffix[len(PREFIX):] if suffix.startswith(PREFIX) else suffix
method = 'GET' if request.method == 'HEAD' else request.method
@@ -1453,6 +1466,11 @@ def register():
return web.FileResponse(path, headers={'Content-Type': kind, 'Cache-Control': 'private, no-store',
'Content-Disposition': 'attachment', 'X-Content-Type-Options': 'nosniff'})
+ server._freevideo_agent_registered = True
+ if startup_failed:
+ # Keep the guarded 503 routes, but publish no partial stores, token or scheduler.
+ return
+
async def scheduler():
while True:
try:
@@ -1479,5 +1497,5 @@ def register():
args.port), pid=os.getpid(), api=PREFIX, started_at=time.time())
path = token_path(root).with_name('endpoint.json')
path.write_text(json.dumps(endpoint), encoding='utf-8')
- except Exception: # noqa: BLE001 - discovery is a convenience; the API works without it
- pass
+ except Exception as error: # noqa: BLE001 - discovery is a convenience; the API works without it
+ logging.getLogger(__name__).warning('[FreeVideo] Agent discovery unavailable: %s', error)
diff --git a/freevideo_engine/comfy_library.py b/freevideo_engine/comfy_library.py
index f7b748b..d852c22 100644
--- a/freevideo_engine/comfy_library.py
+++ b/freevideo_engine/comfy_library.py
@@ -101,7 +101,12 @@ def list_videos(output_directory, *, before=None, limit=24):
summary['encoder_file'].pop('path', None)
if not (root / summary['report']).is_file():
summary['report'] = None
- agent = _agent(path.parent) if agent_enabled() else None
+ try:
+ agent = _agent(path.parent) if agent_enabled() else None
+ except Exception as error:
+ # Optional attribution must not hide an otherwise valid saved video.
+ logging.getLogger(__name__).warning('[FreeVideo] Agent label unavailable: %s', error)
+ agent = None
if agent:
summary['agent'] = agent
rows.append(dict(summary, id=key[1], bytes=info.st_size,
diff --git a/freevideo_engine/managed.py b/freevideo_engine/managed.py
index a721d82..7954b11 100644
--- a/freevideo_engine/managed.py
+++ b/freevideo_engine/managed.py
@@ -73,6 +73,7 @@ def _main(argv=None):
if agent_enabled() else '') + '\n'
'Examples:\n ./freevideo\n ./freevideo server --listen 0.0.0.0\n ./freevideo setup --plan\n'
' ./freevideo test --suite quick\n ./freevideo generate --prompt-file prompt.txt --out video.mp4\n\n'
+ 'Agent commands are enabled by default; set FREEVIDEO_AGENT=0 to disable them.\n\n'
'Use COMMAND --help for options. Windows: .\\setup.ps1 / .\\test.ps1 / .\\freevideo.ps1; Linux: ./setup.sh / ./test.sh / ./freevideo.')
return 0
if not rest: