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: address opencode review findings on the fal.ai video backend

[._.]/ Adam Eivy8c6188ede319
diff --git a/client/src/components/settings/ImageGenTab.jsx b/client/src/components/settings/ImageGenTab.jsx
index ab091439fd..7bdb525f55 100644
--- a/client/src/components/settings/ImageGenTab.jsx
+++ b/client/src/components/settings/ImageGenTab.jsx
@@ -461,7 +461,7 @@ export function ImageGenTab() {
...videoGenSliceRef.current,
mode: videoGenMode || null,
displaySleep: videoGenDisplaySleep,
- fal: { ...videoGenSliceRef.current.fal, apiKey: falApiKey.trim() },
+ fal: { ...videoGenSliceRef.current.fal, apiKey: falApiKey.trim() || undefined },
},
};
try {
diff --git a/client/src/components/settings/ImageGenTab.test.jsx b/client/src/components/settings/ImageGenTab.test.jsx
index 05b9588692..225ab8a52f 100644
--- a/client/src/components/settings/ImageGenTab.test.jsx
+++ b/client/src/components/settings/ImageGenTab.test.jsx
@@ -245,7 +245,7 @@ describe('ImageGenTab grouped tabs', () => {
await waitFor(() => expect(updateSettings).toHaveBeenCalled());
const patch = updateSettings.mock.calls[0][0];
expect(patch.videoGen).toEqual({
- mode: 'local', defaultModelId: 'ltx23_distilled_q4', displaySleep: true, fal: { apiKey: '' },
+ mode: 'local', defaultModelId: 'ltx23_distilled_q4', displaySleep: true, fal: {},
});
});
});
diff --git a/server/services/mediaJobQueue/index.js b/server/services/mediaJobQueue/index.js
index 1b1d0211e7..61bd9bba9a 100644
--- a/server/services/mediaJobQueue/index.js
+++ b/server/services/mediaJobQueue/index.js
@@ -45,7 +45,7 @@ import { trainingEvents } from '../loraTraining/events.js';
import { audioGenEvents } from '../audioGen/events.js';
import { getSettings } from '../settings.js';
import { IMAGE_GEN_MODE, CLOUD_IMAGE_GEN_MODES } from '../imageGen/modes.js';
-import { VIDEO_GEN_MODE } from '../../lib/generationModes.js';
+import { VIDEO_GEN_MODE, CLOUD_VIDEO_GEN_MODES } from '../../lib/generationModes.js';
import { REMOTE_MEDIA_MODULES, isRemoteMediaJob } from './remoteMediaJob.js';
import { routedJobParams } from '../federatedMedia/routedJobParams.js';
@@ -58,7 +58,7 @@ import { routedJobParams } from '../federatedMedia/routedJobParams.js';
// renders combined).
const isCloudImageJob = (j) =>
(j.kind === 'image' && CLOUD_IMAGE_GEN_MODES.includes(j.params?.mode))
- || (j.kind === 'video' && (j.params?.mode === IMAGE_GEN_MODE.GROK || j.params?.mode === VIDEO_GEN_MODE.FAL));
+ || (j.kind === 'video' && CLOUD_VIDEO_GEN_MODES.includes(j.params?.mode));
// The federated-kind map and its predicate live in ./remoteMediaJob.js so light
// consumers (sanitizeJob, route handlers) can ask "is this routed?" without
@@ -197,7 +197,7 @@ async function resolveLiveParams(job, safeParams) {
// mflux training runs in the same venv as local image renders, so the
// live settings pythonPath wins there too. flux2 training resolves its
// own venv (resolveFlux2Python) inside runTraining — skip it here.
- const usesLocalPython = (job.kind === 'video' && job.params?.mode !== IMAGE_GEN_MODE.GROK && job.params?.mode !== VIDEO_GEN_MODE.FAL)
+ const usesLocalPython = (job.kind === 'video' && !CLOUD_VIDEO_GEN_MODES.includes(job.params?.mode))
|| (job.kind === 'image' && !CLOUD_IMAGE_GEN_MODES.includes(job.params?.mode))
|| (job.kind === 'training' && job.params?.runtime === 'mflux');
if (!usesLocalPython) return;
diff --git a/server/services/videoGen/fal.js b/server/services/videoGen/fal.js
index cc8bdffbf0..6ff3d87f1f 100644
--- a/server/services/videoGen/fal.js
+++ b/server/services/videoGen/fal.js
@@ -28,6 +28,14 @@ import { videoGenEvents } from './events.js';
import { finalizeGeneratedVideo } from './generateVideoHelpers.js';
import { mutateVideoHistory } from './history.js';
import { getSettings } from '../settings.js';
+import { nearestAspectRatio } from '../imageGen/modes.js';
+
+// fal.ai's aspect_ratio set for the minimax hailuo-02 models this provider
+// targets — matches the free-tool automation's FAL_ASPECT_RATIOS
+// (services/fableLoom/falVideoAutomation.js) so both fal.ai paths agree on
+// what the backend actually accepts.
+export const FAL_ASPECT_RATIOS = Object.freeze(['16:9', '9:16', '1:1']);
+export const deriveAspectRatio = (width, height) => nearestAspectRatio(width, height, FAL_ASPECT_RATIOS);
export const FAL_QUEUE_BASE = 'https://queue.fal.run';
@@ -146,7 +154,7 @@ async function fetchFalResult({ responseUrl, apiKey }) {
export async function generateVideo({
apiKey: providedApiKey, settings, modelId: requestedModelId,
- prompt = '', negativePrompt, duration, aspectRatio,
+ prompt = '', negativePrompt, duration, aspectRatio, width, height,
sourceImagePath = null, jobId: providedJobId = null,
}) {
await ensureDir(PATHS.videos);
@@ -170,6 +178,10 @@ export async function generateVideo({
const jobId = providedJobId || randomUUID();
const filename = `${jobId}.mp4`;
const outputPath = join(PATHS.videos, filename);
+ // An explicit aspectRatio always wins (e.g. FableLoom's visualConditioning
+ // render parameters); otherwise derive the nearest fal-supported ratio from
+ // the request's width/height, same as grok's deriveAspectRatio.
+ const effectiveAspectRatio = FAL_ASPECT_RATIOS.includes(aspectRatio) ? aspectRatio : deriveAspectRatio(width, height);
const meta = {
id: jobId,
@@ -177,7 +189,7 @@ export async function generateVideo({
negativePrompt: negativePrompt || '',
modelId: `fal:${modelId}`,
...(duration ? { duration } : {}),
- ...(aspectRatio ? { aspectRatio } : {}),
+ ...(effectiveAspectRatio ? { aspectRatio: effectiveAspectRatio } : {}),
filename,
createdAt: new Date().toISOString(),
mode: sourceImagePath ? 'image' : 'text',
@@ -190,7 +202,7 @@ export async function generateVideo({
activeJobs.set(jobId, { ...meta, generationId: jobId, totalSteps: 1, step: 0, progress: 0 });
broadcastSse(job, { type: 'status', message: 'Submitting to fal.ai…' });
- runFalVideo(job, jobId, { apiKey, modelId, prompt, duration, aspectRatio, sourceImagePath, outputPath, filename, meta })
+ runFalVideo(job, jobId, { apiKey, modelId, prompt, duration, aspectRatio: effectiveAspectRatio, sourceImagePath, outputPath, filename, meta })
.catch((err) => {
console.log(`❌ fal video run failed [${jobId.slice(0, 8)}]: ${err?.message}`);
});
diff --git a/server/services/videoGen/fal.test.js b/server/services/videoGen/fal.test.js
index 1cccc988d5..1e4205e4a0 100644
--- a/server/services/videoGen/fal.test.js
+++ b/server/services/videoGen/fal.test.js
@@ -75,6 +75,18 @@ describe('videoGen/fal — resolveFalApiKey', () => {
});
});
+describe('videoGen/fal — deriveAspectRatio', () => {
+ it('maps width/height to the nearest fal-supported ratio', () => {
+ expect(fal.deriveAspectRatio(1920, 1080)).toBe('16:9');
+ expect(fal.deriveAspectRatio(1080, 1920)).toBe('9:16');
+ expect(fal.deriveAspectRatio(1024, 1024)).toBe('1:1');
+ });
+
+ it('returns null for absent/invalid dimensions', () => {
+ expect(fal.deriveAspectRatio(undefined, undefined)).toBeNull();
+ });
+});
+
describe('videoGen/fal — _internals.buildRequestBody', () => {
it('includes only the fields that were actually supplied', () => {
expect(fal._internals.buildRequestBody({ prompt: ' a fox running ' })).toEqual({ prompt: 'a fox running' });
@@ -131,6 +143,29 @@ describe('videoGen/fal — generateVideo', () => {
vi.unstubAllGlobals();
});
+ it('derives aspect_ratio from width/height when none is supplied explicitly', async () => {
+ const fetchMock = vi.fn(async (url, opts) => {
+ if (url === 'https://queue.fal.run/fal-ai/x') {
+ expect(JSON.parse(opts.body)).toEqual({ prompt: 'portrait clip', aspect_ratio: '9:16' });
+ return jsonResponse({ request_id: 'r2', status_url: 'https://queue.fal.run/fal-ai/x/requests/r2/status', response_url: 'https://queue.fal.run/fal-ai/x/requests/r2' });
+ }
+ if (url === 'https://queue.fal.run/fal-ai/x/requests/r2/status') return jsonResponse({ status: 'COMPLETED' });
+ if (url === 'https://queue.fal.run/fal-ai/x/requests/r2') return jsonResponse({ video: { url: 'https://cdn.fal.ai/out.mp4' } });
+ if (url === 'https://cdn.fal.ai/out.mp4') {
+ return { ok: true, status: 200, arrayBuffer: async () => Uint8Array.from(Buffer.from('bytes')).buffer };
+ }
+ throw new Error(`unexpected fetch: ${url}`);
+ });
+ vi.stubGlobal('fetch', fetchMock);
+
+ await fal.generateVideo({
+ apiKey: 'test-key', modelId: 'fal-ai/x', prompt: 'portrait clip', width: 1080, height: 1920,
+ });
+ for (let i = 0; i < 50 && fetchMock.mock.calls.length < 1; i += 1) await flush();
+ expect(fetchMock).toHaveBeenCalled();
+ vi.unstubAllGlobals();
+ });
+
it('resolves the API key from live settings when the caller supplies neither apiKey nor settings (the mediaJobQueue dispatch shape)', async () => {
getSettingsMock.mockResolvedValue({ videoGen: { fal: { apiKey: 'live-key' } } });
const fetchMock = vi.fn(async (url, opts) => {
diff --git a/server/services/videoGen/prepareParams.js b/server/services/videoGen/prepareParams.js
index b6e1ad06f1..de243b1970 100644
--- a/server/services/videoGen/prepareParams.js
+++ b/server/services/videoGen/prepareParams.js
@@ -773,7 +773,9 @@ async function resolvePreparedParams({
}
return {
backend,
- fal: settings.videoGen?.fal || {},
+ // No CLI-config sibling to grok's `grok` field: fal.js re-resolves the
+ // API key from live settings itself (see its generateVideo comment) so
+ // the secret never rides through job.params/media-jobs.json.
effectiveModel: { id: 'fal', supportedModes: ['text', 'image'] },
sourceImagePath,
uploadedTempPath,
diff --git a/server/services/videoGen/submitJob.js b/server/services/videoGen/submitJob.js
index 017a104e66..ef727d4057 100644
--- a/server/services/videoGen/submitJob.js
+++ b/server/services/videoGen/submitJob.js
@@ -201,6 +201,8 @@ const submitValidatedVideoGenJob = async (body, uploads) => {
aspectRatio: body.visualConditioning?.render?.parameters?.aspectRatio,
prompt: body.prompt,
negativePrompt: body.negativePrompt || '',
+ width: body.width,
+ height: body.height,
duration: body.falDuration,
sourceImagePath,
uploadedTempPath,