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

feat: refine single-dimension canvas matching and clamp fps frame scaling (#4681)

[._.]/ Adam Eivyf239c2676318
diff --git a/server/services/federatedMedia/remoteSubmission.js b/server/services/federatedMedia/remoteSubmission.js
index afc10493e4..f38f7de297 100644
--- a/server/services/federatedMedia/remoteSubmission.js
+++ b/server/services/federatedMedia/remoteSubmission.js
@@ -40,7 +40,9 @@ export function negotiateVideoConstraints(request, capability) {
console.log(`🌐 Federated render: adjusted fps from ${requestedFps} to ${bestFps} for ${capability.modelName || capability.modelId}`);
// Rescale frame count to preserve clip duration (matches local reconciler)
if (negotiated.numFrames !== undefined && Number.isFinite(Number(negotiated.numFrames)) && requestedFps > 0) {
- const rescaledFrames = Math.max(1, Math.round((Number(negotiated.numFrames) / requestedFps) * bestFps));
+ const maxNumFrames = capability.maxNumFrames != null ? Number(capability.maxNumFrames) : 600;
+ const maxAllowed = Math.min(600, maxNumFrames > 0 ? maxNumFrames : 600);
+ const rescaledFrames = Math.min(maxAllowed, Math.max(1, Math.round((Number(negotiated.numFrames) / requestedFps) * bestFps)));
negotiated = { ...negotiated, numFrames: rescaledFrames };
}
negotiated = { ...negotiated, fps: bestFps };
@@ -121,20 +123,32 @@ export function negotiateVideoConstraints(request, capability) {
&& Number(opt.w) >= 64 && Number(opt.w) <= 2048 && Number(opt.h) >= 64 && Number(opt.h) <= 2048,
);
if (validOptions.length > 0) {
- const currentWidth = negotiated.width ?? validOptions[0].w;
- const currentHeight = negotiated.height ?? validOptions[0].h;
- const requestedAspect = Number(currentWidth) / Number(currentHeight);
- const requestedArea = Number(currentWidth) * Number(currentHeight);
- const bestOption = validOptions.reduce((best, option) => {
- const aspectDiff = Math.abs((Number(option.w) / Number(option.h)) - requestedAspect);
- const areaDiff = Math.abs((Number(option.w) * Number(option.h)) - requestedArea);
- if (!best) return { option, aspectDiff, areaDiff };
- if (aspectDiff < best.aspectDiff - 0.001) return { option, aspectDiff, areaDiff };
- if (Math.abs(aspectDiff - best.aspectDiff) <= 0.001 && areaDiff < best.areaDiff) {
- return { option, aspectDiff, areaDiff };
- }
- return best;
- }, null)?.option;
+ let bestOption = null;
+ if (negotiated.width !== undefined && negotiated.height !== undefined) {
+ const requestedAspect = Number(negotiated.width) / Number(negotiated.height);
+ const requestedArea = Number(negotiated.width) * Number(negotiated.height);
+ bestOption = validOptions.reduce((best, option) => {
+ const aspectDiff = Math.abs((Number(option.w) / Number(option.h)) - requestedAspect);
+ const areaDiff = Math.abs((Number(option.w) * Number(option.h)) - requestedArea);
+ if (!best) return { option, aspectDiff, areaDiff };
+ if (aspectDiff < best.aspectDiff - 0.001) return { option, aspectDiff, areaDiff };
+ if (Math.abs(aspectDiff - best.aspectDiff) <= 0.001 && areaDiff < best.areaDiff) {
+ return { option, aspectDiff, areaDiff };
+ }
+ return best;
+ }, null)?.option;
+ } else if (negotiated.width !== undefined) {
+ const reqW = Number(negotiated.width);
+ bestOption = validOptions.reduce((closest, opt) =>
+ Math.abs(Number(opt.w) - reqW) < Math.abs(Number(closest.w) - reqW) ? opt : closest,
+ validOptions[0]);
+ } else {
+ const reqH = Number(negotiated.height);
+ bestOption = validOptions.reduce((closest, opt) =>
+ Math.abs(Number(opt.h) - reqH) < Math.abs(Number(closest.h) - reqH) ? opt : closest,
+ validOptions[0]);
+ }
+
if (bestOption && (negotiated.width !== Number(bestOption.w) || negotiated.height !== Number(bestOption.h))) {
console.log(`🌐 Federated render: adjusted resolution from ${negotiated.width ?? '?'}x${negotiated.height ?? '?'} to ${bestOption.w}x${bestOption.h} for ${capability.modelName || capability.modelId}`);
negotiated = { ...negotiated, width: Number(bestOption.w), height: Number(bestOption.h) };
@@ -145,8 +159,9 @@ export function negotiateVideoConstraints(request, capability) {
// Defensive validation against the wire schema bounds before persisting/returning
const validationResult = partialVideoJobSubmissionSchema.safeParse(negotiated);
if (!validationResult.success) {
+ const issueMessages = validationResult.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join(', ');
throw new ServerError(
- `Negotiated video parameters violate schema: ${validationResult.error.message}`,
+ `Negotiated video parameters violate schema: ${issueMessages}`,
{ status: 400, code: 'MEDIA_PROVIDER_INPUT_UNSUPPORTED' },
);
}
diff --git a/server/services/federatedMedia/remoteSubmission.test.js b/server/services/federatedMedia/remoteSubmission.test.js
index e17af4cdfe..a8fa57b34f 100644
--- a/server/services/federatedMedia/remoteSubmission.test.js
+++ b/server/services/federatedMedia/remoteSubmission.test.js
@@ -94,6 +94,39 @@ describe('negotiateVideoConstraints', () => {
expect(snapped.height).toBe(768);
});
+ it('snaps width and height when only one dimension is supplied', () => {
+ const capability = {
+ modelId: 'minimax_h3',
+ resolutionOptions: [
+ { label: '21:9', w: 1536, h: 672 },
+ { label: '16:9', w: 1344, h: 768 },
+ { label: '9:16', w: 768, h: 1344 },
+ ],
+ };
+
+ const snappedHeight = negotiateVideoConstraints({ height: 750 }, capability);
+ expect(snappedHeight.width).toBe(1344);
+ expect(snappedHeight.height).toBe(768);
+
+ const snappedWidth = negotiateVideoConstraints({ width: 800 }, capability);
+ expect(snappedWidth.width).toBe(768);
+ expect(snappedWidth.height).toBe(1344);
+ });
+
+ it('clamps rescaled frame count to maxNumFrames and 600', () => {
+ const capability = {
+ modelId: 'wan22',
+ frameStride: 4,
+ fpsOptions: [24],
+ maxNumFrames: 300,
+ };
+
+ // 250 frames at 16 fps -> rescaled to (250/16)*24 = 375 -> clamped to maxNumFrames 300 -> snapped to stride 297
+ const result = negotiateVideoConstraints({ numFrames: 250, fps: 16 }, capability);
+ expect(result.fps).toBe(24);
+ expect(result.numFrames).toBe(297);
+ });
+
it('tie-breaks equal aspect ratios by closest area and ignores out-of-bounds options', () => {
const capability = {
modelId: 'custom',