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.

Agent: refuse a video past five parts at plan and submit, with the backend's sentence

Bowen Xue785283f918a6
diff --git a/freevideo_engine/agent/errors.py b/freevideo_engine/agent/errors.py
index 68d5ac9..bbfad5e 100644
--- a/freevideo_engine/agent/errors.py
+++ b/freevideo_engine/agent/errors.py
@@ -64,6 +64,7 @@ ERRORS = {
'chain_unavailable': (503, True, 'The continuous generation backend is unavailable.', 'Start FreeVideo with the continuous generation backend enabled, then retry.'),
'chain_missing': (409, True, 'The saved chain receipt is unavailable.', 'Restore the chain receipt and retry resume, or submit a new job.'),
'join_failed': (409, True, 'The generated blocks could not be joined; completed blocks are retained.', 'POST /freevideo/agent/v1/jobs/{id}/resume to retry joining the completed blocks.'),
+ 'chain_too_long': (422, False, 'This video can have up to 5 parts. Make it shorter.', 'Submit a new job with a smaller seconds; continue_from counts the parts of the video it continues.'),
'chain_rejected': (409, False, 'The continuous backend rejected this generation.', 'Read GET /freevideo/agent/v1/capabilities and submit a supported generation request.'),
'invalid_wait': (422, False, 'wait must be a finite nonnegative number of seconds.', 'Use wait=0 or wait=25; larger valid values are clamped to 25 seconds.'),
'invalid_resume': (422, False, 'resume accepts an empty object or an optional ref only.', 'Send {} or {"ref":"resume-1"}; submit a new job to change generation parameters.'),
diff --git a/freevideo_engine/agent/guide.py b/freevideo_engine/agent/guide.py
index bce4f84..8474c3c 100644
--- a/freevideo_engine/agent/guide.py
+++ b/freevideo_engine/agent/guide.py
@@ -108,7 +108,7 @@ GUIDE = {
'session_routes': [dict(operation=name, method=method, path=path, description=summary)
for name, (method, path, summary) in SESSION_OPERATIONS.items()],
'filming': [
- 'Filming is for a film of several shots, each picked from takes. One video of any length is one generate '
+ 'Filming is for a film of several shots, each picked from takes. One video of up to 60 seconds is one generate '
'job (longer requests continue and join automatically); to polish an idea first, run enhance, then generate.',
'Use drama plan → start → get → sheet → choose/reshoot → finish; inspect todo after every change.',
'At start tell the user the estimated total time; on over_budget decide whether to ask them; '
@@ -381,6 +381,8 @@ GUIDE['agent_jobs'] += [
'before uploading. Unknown fields are rejected and every batch is validated before it is recorded.',
'limits.seconds in the status reply is what this installation can make now. While continuation is false, '
'one block (15 s) is the longest video; plan and submit refuse longer requests with continuation_unavailable.',
+ 'One video has at most 5 parts (60 s in one request). continue_from counts the parts of the video it '
+ 'continues; plan and submit refuse a longer one and name the longest seconds that still fits.',
'features in the status reply names what this installation offers; false means not usable now (for example '
'chain.auto while continuation is false), and a missing name means not offered here.',
]
diff --git a/freevideo_engine/agent/jobs.py b/freevideo_engine/agent/jobs.py
index f677139..1e3eb75 100644
--- a/freevideo_engine/agent/jobs.py
+++ b/freevideo_engine/agent/jobs.py
@@ -105,6 +105,46 @@ def cut_problems(spec, seconds, prefix='', *, editor=None):
return [dict(problem, got=got, message=problem['message'].replace('received None', 'received ' + got))]
+def parts_problems(spec, runner, prefix='', *, editor=None, work=None):
+ """One video continues through a limited number of parts; say so before anything is generated.
+
+ The chain backend refuses the same request when the chain is created, with the same sentence.
+ `work` is the saved video continue_from names (output-relative), or None while it cannot be told.
+ """
+ if runner is None or spec['kind'] != 'generate' or spec.get('refine_from'):
+ return []
+ from ..chain_plan import plan
+ from ..chain_runner import ChainTooLong
+ from ..chain_store import reference
+ limit, continued = runner.max_parts, bool(spec.get('continue_from'))
+ count = lambda seconds: len(plan(seconds, continued=continued)['blocks'])
+ try:
+ with runner.lock:
+ if editor is not None:
+ rows = [dict(id=b['id'], after=reference(b.get('after')), before=reference(b.get('before')))
+ for b in editor['blocks']]
+ earlier, needed = 0, max(runner._depths(dict(id=None, blocks=rows)).values())
+ else:
+ # A source the backend has no record of counts as one part, as it does there.
+ earlier = (runner._work_parts(work, ()) if work else 1) if continued else 0
+ needed = earlier + count(spec['seconds'])
+ except (ValueError, KeyError, TypeError):
+ return [] # Not a chain the backend accepts; it says why when the chain is created.
+ if needed <= limit:
+ return []
+ if editor is not None:
+ problem, got = schema.diagnostic(prefix + '/target', 'a range that takes at most %d parts' % limit, None), '%d parts' % needed
+ else:
+ fit = next((s for s in range(int(spec['seconds']), 1, -1) if earlier + count(s) <= limit), None)
+ if fit is None:
+ problem = schema.diagnostic(prefix + '/continue_from', 'a video of fewer than %d parts' % limit, None)
+ got = 'a video of %d parts' % earlier
+ else:
+ problem, got = schema.diagnostic(prefix + '/seconds', 'at most %d' % fit, spec['seconds']), None
+ message = problem['message'] if got is None else problem['message'].replace('received None', 'received ' + got)
+ return [dict(problem, got=got or problem['got'], message='%s %s' % (ChainTooLong(needed, limit), message))]
+
+
def continuation_unavailable():
return chain_error('continuation_unavailable', 'This backend cannot continue multiple video blocks.',
'Submit a new job with seconds<=15, or enable a backend with continuation inputs and resume.')
@@ -537,6 +577,8 @@ class Jobs:
if dependency not in known:
problems.append(schema.diagnostic(prefix + '/after', 'existing jobs or earlier batch refs', dependency))
problems.extend(continuation_problems(normalized, prefix, editor=editor))
+ problems.extend(parts_problems(normalized, self.port.chain_runner(), prefix, editor=editor,
+ work=self.continued_work(normalized)))
problems.extend(cut_problems(normalized, normalized.get('seconds'), prefix, editor=editor))
try:
self.port.check(normalized)
@@ -1103,6 +1145,13 @@ class Jobs:
return self.port.library_video(item['library'])
return self.port.input_path(item['file'])
+ def continued_work(self, spec):
+ """The saved video a request continues, as the chain backend names it; None while it cannot be told."""
+ try:
+ return self.port.output_relative(self.source_video(spec['continue_from'])) if spec.get('continue_from') else None
+ except Exception:
+ return None
+
def media_file(self, row, item, name, *, target=None):
"""Resolve one media item to a file relative to ComfyUI input (frames, imports, edits)."""
folder = 'freevideo/agent/' + row['id']
@@ -1212,7 +1261,7 @@ class Jobs:
else bool(row['spec'].get('continue_from')) or not single_block(payload['seconds'])) and not self.continuation_ready():
raise continuation_unavailable()
self.touch(row, chain_submission='creating', status='queued', queued_at=self.clock())
- from ..chain_runner import ChainBusy
+ from ..chain_runner import ChainBusy, ChainTooLong
try:
if resume:
chain = runner.resume(row['chain_id'], client_id='agent:' + row['id'])
@@ -1223,6 +1272,11 @@ class Jobs:
self.touch(row, status='waiting')
return
raise
+ except ChainTooLong as error:
+ # Submit and plan refuse this up front; a source that was still being made can only be counted here.
+ row['resume_pending'] = False
+ self.finish(row, 'failed', error=errors.build('chain_too_long', validation=True, message=str(error)))
+ return
except Exception:
row['resume_pending'] = False
if resume:
diff --git a/freevideo_engine/agent/mcp.py b/freevideo_engine/agent/mcp.py
index 4855fb1..ea8dc38 100644
--- a/freevideo_engine/agent/mcp.py
+++ b/freevideo_engine/agent/mcp.py
@@ -44,7 +44,7 @@ def tool_list():
dict(name='freevideo_prompt_guide', title='H3 prompt guide', description='How to write prompts: sections, shots and cuts, camera motion, dialogue, references, short-drama tips, and a full example.', annotations=read),
dict(name='freevideo_schema', title='Job JSON Schemas', description='JSON Schemas of every job kind and of image edit recipes.', annotations=read),
dict(name='freevideo_plan', title='Plan a job', description="Validate a job without running it: actual frames/seconds, sampling passes, warnings and a time estimate from this computer's history. Same fields as freevideo_generate.", annotations=read),
- dict(name='freevideo_generate', title='Generate a video', description='Generate one video with audio from an H3 prompt, of any length: a longer request continues and joins into one file automatically. Use this for any single video, also after freevideo_enhance_prompt; the drama tools are only for a film of several separately chosen shots. Optionally from first/last frames or references (files, local paths, or frames of earlier jobs). Returns the job; with wait, its result (video path and URL).', annotations=write),
+ dict(name='freevideo_generate', title='Generate a video', description='Generate one video with audio from an H3 prompt, up to 60 seconds: a longer request continues and joins into one file automatically. Use this for any single video, also after freevideo_enhance_prompt; the drama tools are only for a film of several separately chosen shots. Optionally from first/last frames or references (files, local paths, or frames of earlier jobs). Returns the job; with wait, its result (video path and URL).', annotations=write),
dict(name='freevideo_submit_batch', title='Submit a storyboard', description='Submit several jobs at once. Each row is a job object with "kind" (generate default, assemble, vlm, enhance) and an optional "ref"; later rows use "@ref" wherever a job id is expected (from_job, after, clips, refine_from). FreeVideo runs them in dependency order.', annotations=write),
dict(name='freevideo_job', title='Job status', description='Status, progress, result or error of a job.', annotations=read),
dict(name='freevideo_wait', title='Wait for a job or the user', description="Wait at most 25 seconds for a job (with id) or, without id, for the user's words in this session. Returns early when the user says something (inbox). If the job is still active, call it again with the same ID; do not resubmit.", annotations=read),
diff --git a/freevideo_engine/agent/routes.py b/freevideo_engine/agent/routes.py
index 25ec2f6..f49e8c7 100644
--- a/freevideo_engine/agent/routes.py
+++ b/freevideo_engine/agent/routes.py
@@ -209,8 +209,10 @@ def plan(port, value, jobs=None):
result = dict(spec={k: v for k, v in spec.items() if k != 'depends_on'}, warnings=[])
if spec['kind'] != 'generate' or spec.get('refine_from'):
return result
- from .jobs import continuation_problems, cut_problems
+ from .jobs import continuation_problems, cut_problems, parts_problems
problems = continuation_problems(spec) + cut_problems(spec, spec['seconds'])
+ if jobs is not None:
+ problems += parts_problems(spec, jobs.port.chain_runner(), work=jobs.continued_work(spec))
if problems:
raise specs.SpecError(problems)
if jobs is not None: