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: handle frameOptions empty case, stride floor clamp, and safeParse validation (#4681)

[._.]/ Adam Eivyd0cdcdfcf750
diff --git a/server/services/federatedMedia/remoteSubmission.js b/server/services/federatedMedia/remoteSubmission.js
index 1d264862ce..b430fc00d4 100644
--- a/server/services/federatedMedia/remoteSubmission.js
+++ b/server/services/federatedMedia/remoteSubmission.js
@@ -42,16 +42,19 @@ export function negotiateVideoConstraints(request, capability) {
.map(Number)
.filter((opt) => Number.isInteger(opt) && opt >= 1 && opt <= 600 && (maxNumFrames === null || opt <= maxNumFrames))
.sort((a, b) => a - b);
- if (validOptions.length > 0) {
- // Snap down to largest option <= requested; if below minimum option, snap UP to minimum legal option.
- const optionsBelow = validOptions.filter((opt) => opt <= requestedFrames);
- const best = optionsBelow.length > 0
- ? optionsBelow[optionsBelow.length - 1]
- : validOptions[0];
- if (best !== requestedFrames) {
- console.log(`🌐 Federated render: adjusted numFrames from ${requestedFrames} to ${best} for ${capability.modelName || capability.modelId}`);
- negotiated = { ...negotiated, numFrames: best };
- }
+ if (validOptions.length === 0) {
+ throw new ServerError(
+ `Requested frame count (${requestedFrames}) cannot be satisfied by ${capability.modelName || capability.modelId}`,
+ { status: 400, code: 'MEDIA_PROVIDER_INPUT_UNSUPPORTED' },
+ );
+ }
+ // Discrete frameOptions models snap to nearestOption (consistent with local reconciler)
+ const best = validOptions.reduce((closest, opt) =>
+ Math.abs(opt - requestedFrames) < Math.abs(closest - requestedFrames) ? opt : closest,
+ validOptions[0]);
+ if (best !== requestedFrames) {
+ console.log(`🌐 Federated render: adjusted numFrames from ${requestedFrames} to ${best} for ${capability.modelName || capability.modelId}`);
+ negotiated = { ...negotiated, numFrames: best };
}
} else {
const frameStride = capability.frameStride != null ? Number(capability.frameStride) : null;
@@ -61,24 +64,20 @@ export function negotiateVideoConstraints(request, capability) {
if (hasStride || hasMax) {
let legalFrames = requestedFrames;
+ const minLegal = hasStride ? frameStride + 1 : 1;
if (hasStride) {
- const minLegal = frameStride + 1;
+ // Continuous stride models snap down to n*stride + 1 per issue #4681 specification
+ // (never up, to avoid spending unbudgeted provider GPU compute on continuous ranges).
legalFrames = Math.floor((legalFrames - 1) / frameStride) * frameStride + 1;
- if (legalFrames < minLegal) {
- throw new ServerError(
- `Requested frame count (${requestedFrames}) cannot be satisfied by ${capability.modelName || capability.modelId} (minimum ${minLegal})`,
- { status: 400, code: 'MEDIA_PROVIDER_INPUT_UNSUPPORTED' },
- );
- }
}
if (hasMax && legalFrames > maxNumFrames) {
legalFrames = hasStride
? Math.floor((maxNumFrames - 1) / frameStride) * frameStride + 1
: maxNumFrames;
}
- if (legalFrames < 1) {
+ if (legalFrames < minLegal || legalFrames < 1) {
throw new ServerError(
- `Requested frame count (${requestedFrames}) cannot be satisfied by ${capability.modelName || capability.modelId}`,
+ `Requested frame count (${requestedFrames}) cannot be satisfied by ${capability.modelName || capability.modelId} (minimum ${minLegal})`,
{ status: 400, code: 'MEDIA_PROVIDER_INPUT_UNSUPPORTED' },
);
}
@@ -133,7 +132,13 @@ export function negotiateVideoConstraints(request, capability) {
}
// Defensive validation against the wire schema bounds before persisting/returning
- federatedMediaVideoJobSubmissionSchema.partial().parse(negotiated);
+ const validationResult = federatedMediaVideoJobSubmissionSchema.partial().safeParse(negotiated);
+ if (!validationResult.success) {
+ throw new ServerError(
+ `Negotiated video parameters violate schema: ${validationResult.error.message}`,
+ { status: 400, code: 'MEDIA_PROVIDER_INPUT_UNSUPPORTED' },
+ );
+ }
return negotiated;
}
diff --git a/server/services/federatedMedia/remoteSubmission.test.js b/server/services/federatedMedia/remoteSubmission.test.js
index ec008e9f73..6c0525c6a5 100644
--- a/server/services/federatedMedia/remoteSubmission.test.js
+++ b/server/services/federatedMedia/remoteSubmission.test.js
@@ -45,25 +45,39 @@ describe('negotiateVideoConstraints', () => {
expect(negotiateVideoConstraints({ numFrames: 40 }, {}).numFrames).toBe(40);
});
- it('snaps numFrames down to the nearest discrete option when frameOptions is present', () => {
+ it('snaps numFrames to the nearest discrete option when frameOptions is present', () => {
const capability = {
modelId: 'minimax_h3',
frameOptions: [107, 124, 141, 158],
};
- expect(negotiateVideoConstraints({ numFrames: 121 }, capability).numFrames).toBe(107);
+ expect(negotiateVideoConstraints({ numFrames: 50 }, capability).numFrames).toBe(107);
+ expect(negotiateVideoConstraints({ numFrames: 121 }, capability).numFrames).toBe(124);
expect(negotiateVideoConstraints({ numFrames: 124 }, capability).numFrames).toBe(124);
expect(negotiateVideoConstraints({ numFrames: 130 }, capability).numFrames).toBe(124);
expect(negotiateVideoConstraints({ numFrames: 200 }, capability).numFrames).toBe(158);
});
- it('snaps up to minimum frameOption when requested numFrames is below minimum option', () => {
+ it('rejects when maxNumFrames filters out all frameOptions', () => {
const capability = {
modelId: 'minimax_h3',
frameOptions: [107, 124, 141, 158],
+ maxNumFrames: 100,
};
- expect(negotiateVideoConstraints({ numFrames: 50 }, capability).numFrames).toBe(107);
+ expect(() => negotiateVideoConstraints({ numFrames: 50 }, capability))
+ .toThrow(/cannot be satisfied/);
+ });
+
+ it('rejects when maxNumFrames pushes stride count below minLegal', () => {
+ const capability = {
+ modelId: 'wan22',
+ frameStride: 8,
+ maxNumFrames: 5,
+ };
+
+ expect(() => negotiateVideoConstraints({ numFrames: 40 }, capability))
+ .toThrow(/cannot be satisfied.*minimum 9/);
});
it('snaps width and height to closest aspect ratio when resolutionOptions is present', () => {