Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: tighten video batch validation and output checks

[._.]/ Adam Eivy1466ea695c0d
diff --git a/scripts/generate_minimax_h3.py b/scripts/generate_minimax_h3.py
index ebee08d76e..4e85faee9f 100644
--- a/scripts/generate_minimax_h3.py
+++ b/scripts/generate_minimax_h3.py
@@ -1031,11 +1031,14 @@ def render_outputs(pipe, args, images, save_mp4, batch_seeds=None):
preview = _install_h3_stepwise_preview(pipe, args)
encode = pipe.text_encoder.encode
encoded = None
-
- def encode_once(*values, **kwargs):
- nonlocal encoded
- if encoded is None:
- encoded = encode(*values, **kwargs)
+ encoded_key = None
+
+ def encode_once(prompt, images=None):
+ nonlocal encoded, encoded_key
+ key = (prompt, tuple(hash_conditioning_image(image) for image in (images or [])))
+ if key != encoded_key:
+ encoded = encode(prompt, images)
+ encoded_key = key
return encoded
if batch_seeds is not None:
@@ -1089,11 +1092,14 @@ def render_outputs(pipe, args, images, save_mp4, batch_seeds=None):
def main() -> int:
args = parse_args()
- batch_seeds = json.loads(args.batch_seeds) if args.batch_seeds else None
+ try:
+ batch_seeds = json.loads(args.batch_seeds) if args.batch_seeds else None
+ except ValueError:
+ raise SystemExit("--batch-seeds must be a JSON array of unsigned 32-bit integers") from None
if batch_seeds is not None and (not isinstance(batch_seeds, list)
or not 2 <= len(batch_seeds) <= 20
or any(type(seed) is not int or not 0 <= seed <= 2 ** 32 - 1 for seed in batch_seeds)):
- raise ValueError("--batch-seeds requires 2 to 20 unsigned 32-bit integers")
+ raise SystemExit("--batch-seeds requires 2 to 20 unsigned 32-bit integers")
validate_args(args)
# Read the keyframes first: everything below is a git probe, ~35 HF cache
# lookups and an mlx/transformers import, so an unreadable conditioning
diff --git a/server/services/videoGen/generateVideo.js b/server/services/videoGen/generateVideo.js
index 69a7e1c5a5..bc68c797c8 100644
--- a/server/services/videoGen/generateVideo.js
+++ b/server/services/videoGen/generateVideo.js
@@ -162,8 +162,8 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m
const { modelId: selectedModelId, model } = await resolveVideoModelSelection(modelId, { resolveModel: resolveVideoModel });
modelId = selectedModelId;
- validateVideoBatch({ batchSize, seed }, model);
if (!model) throw new ServerError(`Unknown video model: ${modelId}`, { status: 400, code: 'VALIDATION_ERROR' });
+ validateVideoBatch({ batchSize, seed }, model);
if (!isHardwareCompatible(model.hardwareCompatibility)) {
throw new ServerError(
`Video model "${modelId}" is unavailable on this machine: ${model.hardwareCompatibility.reasons.join(' · ')}`,
diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.js
index 9c139903c0..75dfed439d 100644
--- a/server/services/videoGen/local.test.js
+++ b/server/services/videoGen/local.test.js
@@ -5796,10 +5796,11 @@ describe('generateVideo — MiniMax H3 draft decode (#5423)', () => {
describe('resident video batches', () => {
it.each([
{ exitCode: 0, outputs: 2, complete: true },
+ { exitCode: 1, outputs: 0, complete: false, invalidOutput: true },
{ exitCode: 1, outputs: 1, complete: false },
{ exitCode: 0, outputs: 1, complete: false },
{ exitCode: null, signal: 'SIGTERM', outputs: 1, complete: false },
- ])('persists finished outputs and ends the queue job once ($exitCode, $signal, $outputs outputs)', async ({ exitCode, signal = null, outputs, complete }) => {
+ ])('persists finished outputs and ends the queue job once ($exitCode, $signal, $outputs outputs)', async ({ exitCode, signal = null, outputs, complete, invalidOutput }) => {
const { EventEmitter } = await import('node:events');
const { spawnDetached } = await import('../../lib/detachedSpawn.js');
const { atomicWrite } = await import('../../lib/fileUtils.js');
@@ -5826,6 +5827,9 @@ describe('resident video batches', () => {
const job = videoJobState.jobs.get(jobId);
const args = vi.mocked(spawnDetached).mock.calls.at(-1)[1];
expect(JSON.parse(args[args.indexOf('--batch-seeds') + 1])).toEqual([0, 1]);
+ if (invalidOutput) {
+ proc.stdout.emit('data', Buffer.from(JSON.stringify({ video_path: join(MOCK_PATHS.videos, 'other.mp4'), batch_index: 0, seed: 99 }) + '\n'));
+ }
if (complete) vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
for (const item of batch.slice(0, outputs)) {
proc.stdout.emit('data', Buffer.from(JSON.stringify({ video_path: join(MOCK_PATHS.videos, item.filename), batch_index: item.index, seed: item.seed }) + '\n'));
@@ -5843,12 +5847,15 @@ describe('resident video batches', () => {
proc.emit('close', exitCode, signal);
await vi.waitFor(() => expect(complete ? completed : failed).toHaveBeenCalledTimes(1));
expect(complete ? failed : completed).not.toHaveBeenCalled();
- const saved = vi.mocked(atomicWrite).mock.calls.at(-1)[1];
+ const saved = vi.mocked(atomicWrite).mock.calls.at(-1)?.[1] || [];
expect(saved.filter((item) => item.batchId === jobId)).toHaveLength(outputs);
- expect(saved[0].seed).toBe(outputs - 1);
- expect(saved[0].id).toMatch(/^[a-f0-9-]{36}$/);
+ if (outputs) {
+ expect(saved[0].seed).toBe(outputs - 1);
+ expect(saved[0].id).toMatch(/^[a-f0-9-]{36}$/);
+ }
const terminal = (complete ? completed : failed).mock.calls[0][0];
- expect(terminal.results.map((item) => item.seed)).toEqual(complete ? [0, 1] : [0]);
- expect(proc.kill).not.toHaveBeenCalled();
+ expect(terminal.results.map((item) => item.seed)).toEqual(complete ? [0, 1] : outputs ? [0] : []);
+ if (invalidOutput) expect(proc.kill).toHaveBeenCalledWith('SIGTERM');
+ else expect(proc.kill).not.toHaveBeenCalled();
});
});
diff --git a/server/services/videoGen/prepareParams.js b/server/services/videoGen/prepareParams.js
index c9de94672f..eec51fc7a8 100644
--- a/server/services/videoGen/prepareParams.js
+++ b/server/services/videoGen/prepareParams.js
@@ -316,7 +316,6 @@ export async function prepareVideoGenParams({ body, uploads, localOnlyParamKeys
capabilities,
effectiveModel.hardwareRequirements,
);
- validateVideoBatch({ ...body, backend }, effectiveModel);
// Validate modelId before staging (when supplied). Without this the queue
// would happily accept a typo'd modelId and fail asynchronously inside
// the worker — leaving a persisted, doomed queue entry.
@@ -327,6 +326,7 @@ export async function prepareVideoGenParams({ body, uploads, localOnlyParamKeys
{ status: 400, code: 'VIDEO_GEN_UNKNOWN_MODEL' },
);
}
+ validateVideoBatch({ ...body, backend }, effectiveModel);
if (effectiveModel && !isHardwareCompatible(effectiveModel.hardwareCompatibility)) {
await cleanupMultipartTemp(uploads);
throw new ServerError(