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: reject a least-squares fit whose denominator is float dust, not zero (#3801)

[._.]/ Adam Eivya4da7e0fcd19
diff --git a/client/src/hooks/useMediaJobProgress.js b/client/src/hooks/useMediaJobProgress.js
index aef68f6b92..033a7931d6 100644
--- a/client/src/hooks/useMediaJobProgress.js
+++ b/client/src/hooks/useMediaJobProgress.js
@@ -71,7 +71,10 @@ export default function useMediaJobProgress(jobId, { kind = 'image' } = {}) {
statusMsg: job.statusMsg || prev.statusMsg,
// Reload mid-render: the queue retained the estimate, so the ETA comes
// back immediately instead of after the next (minutes-away) step.
- etaMs: typeof job.etaMs === 'number' ? job.etaMs : prev.etaMs,
+ // Same absent-vs-explicit rule as the socket frames: a key the
+ // snapshot doesn't carry leaves the current value alone, an explicit
+ // null clears it.
+ etaMs: job.etaMs !== undefined ? job.etaMs : prev.etaMs,
filename: job.result?.filename || prev.filename,
path: job.result?.path || prev.path,
error: job.error || prev.error,
diff --git a/server/services/videoGen/eta.js b/server/services/videoGen/eta.js
index 3977135b9c..052757829c 100644
--- a/server/services/videoGen/eta.js
+++ b/server/services/videoGen/eta.js
@@ -120,9 +120,12 @@ export const fitRenderCost = (samples) => {
const sumXY = samples.reduce((a, s, i) => a + xs[i] * s.durationMs, 0);
const sumXX = xs.reduce((a, x) => a + x * x, 0);
const denom = n * sumXX - sumX * sumX;
- // Zero denominator = every sample has the same work units, so the fit is a
- // vertical line with no recoverable slope.
- if (denom === 0) return null;
+ // A vanishing denominator = every sample has (near enough) the same work
+ // units, so the fit is a vertical line with no recoverable slope. Compared
+ // against a relative epsilon rather than exactly 0: identical inputs still
+ // leave float dust in `n·Σx² − (Σx)²`, and dividing by 1e-9 of dust yields
+ // an astronomical slope that would be reported as a confident ETA of years.
+ if (!(denom > n * sumXX * 1e-12)) return null;
const perUnitMs = ((n * sumXY - sumX * sumY) / denom) / WORK_FIT_SCALE;
if (!Number.isFinite(perUnitMs) || perUnitMs <= 0) return null;
const fixedMs = (sumY - perUnitMs * WORK_FIT_SCALE * sumX) / n;
diff --git a/server/services/videoGen/eta.test.js b/server/services/videoGen/eta.test.js
index e5032c7d38..baa41b8612 100644
--- a/server/services/videoGen/eta.test.js
+++ b/server/services/videoGen/eta.test.js
@@ -61,6 +61,12 @@ describe('fitRenderCost', () => {
expect(fitRenderCost(samples)).toBeNull();
});
+ it('refuses to fit identical real-scale work units, where the denominator is float dust rather than 0', () => {
+ const work = 768 * 512 * 121 * 30;
+ const samples = [1_000_000, 1_200_000, 1_400_000].map((ms) => ({ workUnits: work, durationMs: ms }));
+ expect(fitRenderCost(samples)).toBeNull();
+ });
+
it('rejects a non-positive slope (noise, not a cost curve)', () => {
const samples = [{ workUnits: 10, durationMs: 900 }, { workUnits: 20, durationMs: 600 }, { workUnits: 30, durationMs: 300 }];
expect(fitRenderCost(samples)).toBeNull();