@hyperframes/producer 0.10.4 → 0.10.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/compileWorker.js +11 -13
- package/dist/distributed.js +74 -45
- package/dist/healthWorkerThread.js +11 -5
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +66 -66
- package/dist/index.js +155 -60
- package/dist/public-server.js +152 -54
- package/dist/services/healthWorker.d.ts +8 -11
- package/dist/services/healthWorkerThread.d.ts +1 -1
- package/dist/services/render/captureCost.d.ts +4 -0
- package/dist/services/render/captureStageError.d.ts +1 -0
- package/dist/services/render/stages/captureEncoder.d.ts +3 -0
- package/dist/services/render/stages/captureSegmentedStage.d.ts +3 -2
- package/dist/services/render/stages/captureStreamingStage.d.ts +4 -3
- package/dist/services/render/stages/encodeStage.d.ts +1 -26
- package/dist/services/renderOrchestrator.d.ts +2 -0
- package/package.json +8 -8
package/dist/public-server.js
CHANGED
|
@@ -380,7 +380,7 @@ import {
|
|
|
380
380
|
getSystemTotalMb,
|
|
381
381
|
LOW_MEMORY_TOTAL_MB_THRESHOLD,
|
|
382
382
|
assertConfiguredFfmpegBinariesExist,
|
|
383
|
-
resolveBrowserGpuMode,
|
|
383
|
+
resolveBrowserGpuMode as resolveBrowserGpuMode2,
|
|
384
384
|
probedHardwareGpu,
|
|
385
385
|
resolveHeadlessShellPath,
|
|
386
386
|
compositionRequiresWebGpu as compositionRequiresWebGpu2,
|
|
@@ -388,7 +388,8 @@ import {
|
|
|
388
388
|
explainDrawElementDisabled,
|
|
389
389
|
chromeMajorCeiling,
|
|
390
390
|
scaleProtocolTimeoutForComposition,
|
|
391
|
-
|
|
391
|
+
captureMemoryRetryWorkers as captureMemoryRetryWorkers2,
|
|
392
|
+
classifyCaptureFailure as classifyCaptureFailure4,
|
|
392
393
|
cloneCaptureWarning,
|
|
393
394
|
isMemoryExhaustionError as isMemoryExhaustionError2,
|
|
394
395
|
isTransientBrowserError as isTransientBrowserError2,
|
|
@@ -2625,8 +2626,7 @@ import {
|
|
|
2625
2626
|
initializeSession as initializeSession2,
|
|
2626
2627
|
prepareCaptureSessionForReuse as prepareCaptureSessionForReuse2,
|
|
2627
2628
|
resolveDeVerifyMinDb as resolveDeVerifyMinDb2,
|
|
2628
|
-
shouldDisableBrowserPoolForParallelWorker
|
|
2629
|
-
spawnStreamingEncoder as spawnStreamingEncoder2
|
|
2629
|
+
shouldDisableBrowserPoolForParallelWorker
|
|
2630
2630
|
} from "@hyperframes/engine";
|
|
2631
2631
|
|
|
2632
2632
|
// src/services/render/captureStageError.ts
|
|
@@ -2998,6 +2998,7 @@ function buildRenderPerfSummary(input) {
|
|
|
2998
2998
|
// src/services/render/captureStageError.ts
|
|
2999
2999
|
var CaptureStageError = class extends CaptureFailure {
|
|
3000
3000
|
browserConsole;
|
|
3001
|
+
memoryRetryUsed = false;
|
|
3001
3002
|
constructor(input) {
|
|
3002
3003
|
const classified = classifyCaptureFailure(input.cause);
|
|
3003
3004
|
super({
|
|
@@ -4585,6 +4586,8 @@ import {
|
|
|
4585
4586
|
captureFrameToBuffer,
|
|
4586
4587
|
captureFrameToBufferPipelined,
|
|
4587
4588
|
captureFramesBatchPipelined,
|
|
4589
|
+
captureMemoryRetryWorkers,
|
|
4590
|
+
classifyCaptureFailure as classifyCaptureFailure2,
|
|
4588
4591
|
closeCaptureSession,
|
|
4589
4592
|
createCaptureSession,
|
|
4590
4593
|
createFrameReorderBuffer,
|
|
@@ -4598,8 +4601,7 @@ import {
|
|
|
4598
4601
|
recaptureDrawElementFrameForVerify,
|
|
4599
4602
|
completeDeferredDrawElementInit,
|
|
4600
4603
|
initializeSession,
|
|
4601
|
-
prepareCaptureSessionForReuse
|
|
4602
|
-
spawnStreamingEncoder
|
|
4604
|
+
prepareCaptureSessionForReuse
|
|
4603
4605
|
} from "@hyperframes/engine";
|
|
4604
4606
|
|
|
4605
4607
|
// src/services/render/stallClock.ts
|
|
@@ -4621,6 +4623,17 @@ function createStallClock(now = () => Date.now()) {
|
|
|
4621
4623
|
};
|
|
4622
4624
|
}
|
|
4623
4625
|
|
|
4626
|
+
// src/services/render/stages/captureEncoder.ts
|
|
4627
|
+
import { spawnStreamingEncoder } from "@hyperframes/engine";
|
|
4628
|
+
function spawnCaptureEncoder(...[outputPath, options, signal, config]) {
|
|
4629
|
+
return spawnStreamingEncoder(
|
|
4630
|
+
outputPath,
|
|
4631
|
+
{ ...options, belowNormalPriority: true },
|
|
4632
|
+
signal,
|
|
4633
|
+
config
|
|
4634
|
+
);
|
|
4635
|
+
}
|
|
4636
|
+
|
|
4624
4637
|
// src/services/render/stages/captureStreamingStage.ts
|
|
4625
4638
|
var DEFAULT_CAPTURE_STALL_MS = 6e4;
|
|
4626
4639
|
var SESSION_INIT_STALL_MS = 3e5;
|
|
@@ -5020,7 +5033,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
5020
5033
|
let streamingEncoder = null;
|
|
5021
5034
|
let streamingEncoderClosed = false;
|
|
5022
5035
|
try {
|
|
5023
|
-
streamingEncoder = await
|
|
5036
|
+
streamingEncoder = await spawnCaptureEncoder(
|
|
5024
5037
|
videoOnlyPath,
|
|
5025
5038
|
streamingEncoderOptions,
|
|
5026
5039
|
abortSignal,
|
|
@@ -5064,6 +5077,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
5064
5077
|
let writtenFrames = 0;
|
|
5065
5078
|
let resumeFrom = 0;
|
|
5066
5079
|
let resumes = 0;
|
|
5080
|
+
let memoryRetryUsed = false;
|
|
5067
5081
|
let workerResults;
|
|
5068
5082
|
for (; ; ) {
|
|
5069
5083
|
const parallelReorder = createFrameReorderBuffer(resumeFrom, totalFrames);
|
|
@@ -5195,6 +5209,25 @@ async function runCaptureStreamingStage(input) {
|
|
|
5195
5209
|
resumes++;
|
|
5196
5210
|
continue;
|
|
5197
5211
|
}
|
|
5212
|
+
const stop = parallelDrainError ?? err;
|
|
5213
|
+
const memoryStop = abortSignal?.aborted !== true && captureLabel === "screenshot" && classifyCaptureFailure2(stop).kind === "memory_exhaustion";
|
|
5214
|
+
const fitWorkers = memoryStop && !memoryRetryUsed ? captureMemoryRetryWorkers(stop) : void 0;
|
|
5215
|
+
if (workerCount > 1 && fitWorkers !== void 0) {
|
|
5216
|
+
memoryRetryUsed = true;
|
|
5217
|
+
const nextWorkers = Math.min(fitWorkers, workerCount - 1);
|
|
5218
|
+
log.warn(
|
|
5219
|
+
"[Render] Capture stopped before memory ran out; resuming from the first unwritten frame with fewer workers.",
|
|
5220
|
+
{ fromWorkers: workerCount, toWorkers: nextWorkers, resumeFrom: writtenFrames }
|
|
5221
|
+
);
|
|
5222
|
+
workerCount = nextWorkers;
|
|
5223
|
+
resumeFrom = writtenFrames;
|
|
5224
|
+
continue;
|
|
5225
|
+
}
|
|
5226
|
+
if (memoryStop && memoryRetryUsed) {
|
|
5227
|
+
const failure = poolFailure(stop, probeSession);
|
|
5228
|
+
if (failure instanceof CaptureStageError) failure.memoryRetryUsed = true;
|
|
5229
|
+
throw failure;
|
|
5230
|
+
}
|
|
5198
5231
|
if (parallelDrainError) throw poolFailure(parallelDrainError, probeSession);
|
|
5199
5232
|
if (stalled && abortSignal?.aborted !== true) {
|
|
5200
5233
|
throw new ParallelCaptureStallError({
|
|
@@ -5525,7 +5558,7 @@ async function captureSegmentToEncoder(ctx, segment) {
|
|
|
5525
5558
|
}
|
|
5526
5559
|
}
|
|
5527
5560
|
var DEFAULT_DEPS = {
|
|
5528
|
-
spawnEncoder:
|
|
5561
|
+
spawnEncoder: spawnCaptureEncoder,
|
|
5529
5562
|
captureFrame: captureFrameToBuffer2,
|
|
5530
5563
|
concat: concatVideoFiles,
|
|
5531
5564
|
// Through the import binding, not captured: a value captured at module load
|
|
@@ -5910,10 +5943,13 @@ import { fpsToNumber as fpsToNumber4 } from "@hyperframes/core";
|
|
|
5910
5943
|
import {
|
|
5911
5944
|
calculateOptimalWorkers,
|
|
5912
5945
|
captureFrameToBuffer as captureFrameToBuffer3,
|
|
5946
|
+
clearStaticDedupAnchor,
|
|
5913
5947
|
closeCaptureSession as closeCaptureSession3,
|
|
5914
5948
|
computeWorkerSizing,
|
|
5915
5949
|
createCaptureSession as createCaptureSession3,
|
|
5916
|
-
initializeSession as initializeSession3
|
|
5950
|
+
initializeSession as initializeSession3,
|
|
5951
|
+
readChromeCpuSeconds,
|
|
5952
|
+
resolveBrowserGpuMode
|
|
5917
5953
|
} from "@hyperframes/engine";
|
|
5918
5954
|
var CAPTURE_CALIBRATION_TARGET_MS = 600;
|
|
5919
5955
|
var MAX_MEASURED_CAPTURE_COST_MULTIPLIER = 8;
|
|
@@ -5953,13 +5989,20 @@ function combineCaptureCostEstimates(staticCost, measuredCost) {
|
|
|
5953
5989
|
multiplier: measuredCost.multiplier,
|
|
5954
5990
|
reasons: [...measuredCost.reasons, ...staticCost.reasons],
|
|
5955
5991
|
p95Ms: measuredCost.p95Ms,
|
|
5956
|
-
medianMs: measuredCost.medianMs
|
|
5992
|
+
medianMs: measuredCost.medianMs,
|
|
5993
|
+
// A hint names work the samples can miss, such as a shader transition between two of them.
|
|
5994
|
+
coresPerWorker: staticCost.multiplier > 1 ? void 0 : measuredCost.coresPerWorker,
|
|
5995
|
+
browserRssMb: measuredCost.browserRssMb
|
|
5957
5996
|
};
|
|
5958
5997
|
}
|
|
5959
5998
|
function buildHeapAdvisoryWarning(sizing, requestedWorkers) {
|
|
5960
5999
|
if (requestedWorkers !== void 0 || !sizing.exceedsHeapAdvisory) return void 0;
|
|
5961
6000
|
return `[Render] ${sizing.workers} capture workers may exceed this process's V8 heap (limit ${sizing.heapLimitMb}MB supports ~${sizing.heapBasedWorkers}). If the render dies with "JavaScript heap out of memory", raise the heap (NODE_OPTIONS=--max-old-space-size=8192) or pass --workers ${sizing.heapBasedWorkers}.`;
|
|
5962
6001
|
}
|
|
6002
|
+
function coresToSizeBy(cost, protocolTimeout) {
|
|
6003
|
+
if (cost.browserRssMb === void 0) return void 0;
|
|
6004
|
+
return 2 * (cost.p95Ms ?? Infinity) < protocolTimeout ? cost.coresPerWorker : void 0;
|
|
6005
|
+
}
|
|
5963
6006
|
function resolveRenderWorkerCount(totalFrames, requestedWorkers, cfg, compiled, log = defaultLogger, measuredCaptureCost, onSizing) {
|
|
5964
6007
|
const reasonCodes = new Set(compiled.renderModeHints.reasons.map((r) => r.code));
|
|
5965
6008
|
if (reasonCodes.has("htmlInCanvas")) {
|
|
@@ -5981,7 +6024,9 @@ function resolveRenderWorkerCount(totalFrames, requestedWorkers, cfg, compiled,
|
|
|
5981
6024
|
);
|
|
5982
6025
|
const sizing = computeWorkerSizing(totalFrames, requestedWorkers, {
|
|
5983
6026
|
...cfg,
|
|
5984
|
-
captureCostMultiplier: captureCost.multiplier
|
|
6027
|
+
captureCostMultiplier: captureCost.multiplier,
|
|
6028
|
+
measuredCoresPerWorker: coresToSizeBy(captureCost, cfg.protocolTimeout),
|
|
6029
|
+
measuredBrowserRssMb: captureCost.browserRssMb
|
|
5985
6030
|
});
|
|
5986
6031
|
onSizing?.(sizing);
|
|
5987
6032
|
const workerCount = sizing.workers;
|
|
@@ -6080,7 +6125,7 @@ async function measureCaptureCostFromSession(session, totalFrames, fps, log, fir
|
|
|
6080
6125
|
}
|
|
6081
6126
|
} finally {
|
|
6082
6127
|
session.staticFrames = savedStaticFrames;
|
|
6083
|
-
session
|
|
6128
|
+
clearStaticDedupAnchor(session);
|
|
6084
6129
|
}
|
|
6085
6130
|
const estimate = estimateMeasuredCaptureCostMultiplier(samples);
|
|
6086
6131
|
if (estimate.p95Ms !== void 0) {
|
|
@@ -6091,11 +6136,20 @@ async function measureCaptureCostFromSession(session, totalFrames, fps, log, fir
|
|
|
6091
6136
|
samples
|
|
6092
6137
|
};
|
|
6093
6138
|
}
|
|
6139
|
+
function chromeCoresUsed(before, after, elapsedMs) {
|
|
6140
|
+
if (!before || !after || elapsedMs <= 0) return void 0;
|
|
6141
|
+
for (const pid of before.keys()) if (!after.has(pid)) return void 0;
|
|
6142
|
+
const total = (cpu) => [...cpu.values()].reduce((a, b) => a + b, 0);
|
|
6143
|
+
const cores = (total(after) - total(before)) / (elapsedMs / 1e3);
|
|
6144
|
+
return cores > 0 ? cores : void 0;
|
|
6145
|
+
}
|
|
6094
6146
|
function logCaptureCalibrationResult(calibration, log) {
|
|
6095
6147
|
if (calibration.estimate.multiplier > 1) {
|
|
6096
6148
|
log.warn("[Render] Measured slow frame capture during auto-worker calibration.", {
|
|
6097
6149
|
multiplier: calibration.estimate.multiplier,
|
|
6098
6150
|
p95Ms: calibration.estimate.p95Ms,
|
|
6151
|
+
coresPerWorker: calibration.estimate.coresPerWorker,
|
|
6152
|
+
browserRssMb: calibration.estimate.browserRssMb,
|
|
6099
6153
|
sampledFrames: calibration.samples.map((sample) => sample.frameIndex),
|
|
6100
6154
|
sampleMs: calibration.samples.map((sample) => Math.round(sample.captureTimeMs))
|
|
6101
6155
|
});
|
|
@@ -6159,6 +6213,12 @@ async function runCaptureCalibration(input) {
|
|
|
6159
6213
|
}
|
|
6160
6214
|
assertNotAborted();
|
|
6161
6215
|
log.info("Calibration session ready, capturing test frames...");
|
|
6216
|
+
const readCpu = () => readChromeCpuSeconds(() => session.browser.target().createCDPSession()).catch(
|
|
6217
|
+
() => void 0
|
|
6218
|
+
);
|
|
6219
|
+
const softwareGpu = await resolveBrowserGpuMode(sessionCfg.browserGpuMode) === "software";
|
|
6220
|
+
const cpuBefore = softwareGpu ? await readCpu() : void 0;
|
|
6221
|
+
const startedAt = performance.now();
|
|
6162
6222
|
const result = await measureCaptureCostFromSession(
|
|
6163
6223
|
session,
|
|
6164
6224
|
totalFrames,
|
|
@@ -6166,6 +6226,15 @@ async function runCaptureCalibration(input) {
|
|
|
6166
6226
|
log,
|
|
6167
6227
|
job.frameWindow?.startFrame
|
|
6168
6228
|
);
|
|
6229
|
+
const elapsedMs = performance.now() - startedAt;
|
|
6230
|
+
const cpuAfter = cpuBefore && await readCpu();
|
|
6231
|
+
result.estimate.coresPerWorker = chromeCoresUsed(cpuBefore, cpuAfter, elapsedMs);
|
|
6232
|
+
if (result.estimate.coresPerWorker !== void 0) {
|
|
6233
|
+
const before = session.chromeMemory?.stats().samples ?? 0;
|
|
6234
|
+
await session.chromeMemory?.sampleOnce();
|
|
6235
|
+
const memory = session.chromeMemory?.stats();
|
|
6236
|
+
if (memory && memory.samples > before) result.estimate.browserRssMb = memory.rssLastMb;
|
|
6237
|
+
}
|
|
6169
6238
|
logCaptureCalibrationResult(result, log);
|
|
6170
6239
|
return result;
|
|
6171
6240
|
};
|
|
@@ -9069,7 +9138,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
9069
9138
|
}
|
|
9070
9139
|
return { subCompositions };
|
|
9071
9140
|
}
|
|
9072
|
-
function promoteCssImportsToLinkTags(html) {
|
|
9141
|
+
function promoteCssImportsToLinkTags(html, budget) {
|
|
9073
9142
|
const { document: document2 } = parseHTML5(html);
|
|
9074
9143
|
const head = document2.querySelector("head");
|
|
9075
9144
|
if (!head) return html;
|
|
@@ -9078,18 +9147,16 @@ function promoteCssImportsToLinkTags(html) {
|
|
|
9078
9147
|
const styleEls = document2.querySelectorAll("style");
|
|
9079
9148
|
for (const styleEl of styleEls) {
|
|
9080
9149
|
const original = styleEl.textContent || "";
|
|
9081
|
-
|
|
9082
|
-
let
|
|
9083
|
-
importRe
|
|
9084
|
-
while ((match = importRe.exec(original)) !== null) {
|
|
9150
|
+
const rulesBetweenImports = [];
|
|
9151
|
+
let keptTo = 0;
|
|
9152
|
+
for (const match of original.matchAll(importRe)) {
|
|
9085
9153
|
const url = match[1] ?? "";
|
|
9086
9154
|
if (!url.startsWith("http://") && !url.startsWith("https://")) continue;
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
}
|
|
9155
|
+
rulesBetweenImports.push(original.slice(keptTo, match.index));
|
|
9156
|
+
keptTo = match.index + match[0].length;
|
|
9157
|
+
if (seenUrls.has(url)) continue;
|
|
9091
9158
|
seenUrls.add(url);
|
|
9092
|
-
|
|
9159
|
+
budget.chargeElements(ENTRY_PAGE, 2);
|
|
9093
9160
|
const preload = document2.createElement("link");
|
|
9094
9161
|
preload.setAttribute("rel", "preload");
|
|
9095
9162
|
preload.setAttribute("href", url);
|
|
@@ -9100,8 +9167,8 @@ function promoteCssImportsToLinkTags(html) {
|
|
|
9100
9167
|
link.setAttribute("href", url);
|
|
9101
9168
|
head.appendChild(link);
|
|
9102
9169
|
}
|
|
9103
|
-
if (
|
|
9104
|
-
styleEl.textContent =
|
|
9170
|
+
if (keptTo > 0) {
|
|
9171
|
+
styleEl.textContent = rulesBetweenImports.join("") + original.slice(keptTo);
|
|
9105
9172
|
}
|
|
9106
9173
|
}
|
|
9107
9174
|
return document2.toString();
|
|
@@ -10148,7 +10215,7 @@ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, ass
|
|
|
10148
10215
|
...options.abortSignal ? [options.abortSignal] : []
|
|
10149
10216
|
]);
|
|
10150
10217
|
const fontSheetHtml = await inlineExternalFontStylesheets(
|
|
10151
|
-
promoteCssImportsToLinkTags(sanitizedHtml),
|
|
10218
|
+
promoteCssImportsToLinkTags(sanitizedHtml, budget),
|
|
10152
10219
|
budget,
|
|
10153
10220
|
remoteFetches
|
|
10154
10221
|
);
|
|
@@ -13491,7 +13558,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
|
|
|
13491
13558
|
import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
13492
13559
|
import { join as join30 } from "node:path";
|
|
13493
13560
|
import {
|
|
13494
|
-
classifyCaptureFailure as
|
|
13561
|
+
classifyCaptureFailure as classifyCaptureFailure3,
|
|
13495
13562
|
frameFileExtension,
|
|
13496
13563
|
captureFrame,
|
|
13497
13564
|
captureFrameToBufferPipelined as captureFrameToBufferPipelined2,
|
|
@@ -13798,7 +13865,7 @@ function resolveCaptureRange(frameRange, totalFrames) {
|
|
|
13798
13865
|
return { rangeStart: frameRange?.startFrame ?? 0, rangeEnd: frameRange?.endFrame ?? totalFrames };
|
|
13799
13866
|
}
|
|
13800
13867
|
function planTransientResume(error, ctx) {
|
|
13801
|
-
const failure =
|
|
13868
|
+
const failure = classifyCaptureFailure3(error, { signal: ctx.abortSignal });
|
|
13802
13869
|
const missing = findMissingFrameRanges(ctx.rangeFrames, ctx.framesDir, ctx.frameExt);
|
|
13803
13870
|
const [firstMissing] = missing;
|
|
13804
13871
|
if (!firstMissing) return null;
|
|
@@ -13894,8 +13961,7 @@ import {
|
|
|
13894
13961
|
cloneCaptureWarnings as cloneCaptureWarnings2,
|
|
13895
13962
|
createCaptureSession as createCaptureSession7,
|
|
13896
13963
|
initTransparentBackground as initTransparentBackground2,
|
|
13897
|
-
initializeSession as initializeSession7
|
|
13898
|
-
spawnStreamingEncoder as spawnStreamingEncoder3
|
|
13964
|
+
initializeSession as initializeSession7
|
|
13899
13965
|
} from "@hyperframes/engine";
|
|
13900
13966
|
import { fpsToNumber as fpsToNumber7 } from "@hyperframes/core";
|
|
13901
13967
|
|
|
@@ -14686,7 +14752,7 @@ async function runCaptureHdrStage(input) {
|
|
|
14686
14752
|
}))
|
|
14687
14753
|
});
|
|
14688
14754
|
}
|
|
14689
|
-
hdrEncoder = await
|
|
14755
|
+
hdrEncoder = await spawnCaptureEncoder(
|
|
14690
14756
|
videoOnlyPath,
|
|
14691
14757
|
{
|
|
14692
14758
|
fps: job.config.fps,
|
|
@@ -14925,8 +14991,7 @@ import {
|
|
|
14925
14991
|
formatFfmpegError,
|
|
14926
14992
|
MIXED_AUDIO_FILENAME as MIXED_AUDIO_FILENAME2,
|
|
14927
14993
|
resolveConfig,
|
|
14928
|
-
runFfmpeg as runFfmpeg6
|
|
14929
|
-
spawnStreamingEncoder as spawnStreamingEncoder4
|
|
14994
|
+
runFfmpeg as runFfmpeg6
|
|
14930
14995
|
} from "@hyperframes/engine";
|
|
14931
14996
|
import {
|
|
14932
14997
|
clearGifFramesBeforeNext,
|
|
@@ -15066,10 +15131,7 @@ function startEncodeProgress(job, stage, onProgress) {
|
|
|
15066
15131
|
function resolveEngineConfig(input) {
|
|
15067
15132
|
return input.engineConfig ?? input.job.config.producerConfig ?? resolveConfig();
|
|
15068
15133
|
}
|
|
15069
|
-
function
|
|
15070
|
-
return Math.max(1, Math.floor(cpuCount) - Math.floor(workerCount));
|
|
15071
|
-
}
|
|
15072
|
-
function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
|
|
15134
|
+
function videoEncoderOptions(input, engineCfg) {
|
|
15073
15135
|
const { job, preset } = input;
|
|
15074
15136
|
return {
|
|
15075
15137
|
fps: job.config.fps,
|
|
@@ -15089,8 +15151,7 @@ function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
|
|
|
15089
15151
|
// keyframes that survive `-f concat -c copy` at assemble time. In-process
|
|
15090
15152
|
// renders leave both undefined → preserves the existing open-GOP output.
|
|
15091
15153
|
lockGopForChunkConcat: input.lockGopForChunkConcat === true,
|
|
15092
|
-
gopSize: input.gopSize
|
|
15093
|
-
softwareEncoderThreads
|
|
15154
|
+
gopSize: input.gopSize
|
|
15094
15155
|
};
|
|
15095
15156
|
}
|
|
15096
15157
|
function canEncodeWhileCapturing(input, workerCount, cpuCount) {
|
|
@@ -15106,9 +15167,8 @@ async function readLandedFrame(workerPath, mergedPath) {
|
|
|
15106
15167
|
}
|
|
15107
15168
|
return readFile2(mergedPath);
|
|
15108
15169
|
}
|
|
15109
|
-
function encodeWhileCapturing(input, totalFrames
|
|
15170
|
+
function encodeWhileCapturing(input, totalFrames) {
|
|
15110
15171
|
const engineCfg = resolveEngineConfig(input);
|
|
15111
|
-
const softwareEncoderThreads = captureBudget ? overlapEncoderThreads(captureBudget.workerCount, captureBudget.cpuCount) : void 0;
|
|
15112
15172
|
const stop = new AbortController();
|
|
15113
15173
|
const signal = input.abortSignal ? AbortSignal.any([input.abortSignal, stop.signal]) : stop.signal;
|
|
15114
15174
|
const landed = /* @__PURE__ */ new Map();
|
|
@@ -15121,10 +15181,10 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
|
|
|
15121
15181
|
};
|
|
15122
15182
|
signal.addEventListener("abort", nudge, { once: true });
|
|
15123
15183
|
let reportFed = null;
|
|
15124
|
-
const encoder =
|
|
15184
|
+
const encoder = spawnCaptureEncoder(
|
|
15125
15185
|
input.videoOnlyPath,
|
|
15126
15186
|
{
|
|
15127
|
-
...videoEncoderOptions(input, engineCfg
|
|
15187
|
+
...videoEncoderOptions(input, engineCfg),
|
|
15128
15188
|
imageFormat: "jpeg"
|
|
15129
15189
|
},
|
|
15130
15190
|
signal,
|
|
@@ -15505,8 +15565,14 @@ var RenderQualityError = class extends Error {
|
|
|
15505
15565
|
);
|
|
15506
15566
|
this.warnings = warnings;
|
|
15507
15567
|
this.name = "RenderQualityError";
|
|
15568
|
+
const failed = warnings.filter((warning) => warning.code === "sub_timeline_script_failure");
|
|
15569
|
+
if (failed.length > 0 && failed.every((warning) => warning.details?.scriptThrew === true)) {
|
|
15570
|
+
this.code = "COMPOSITION_SCRIPT_FAILED";
|
|
15571
|
+
}
|
|
15508
15572
|
}
|
|
15509
15573
|
warnings;
|
|
15574
|
+
/** Set only when the composition's own script threw: rendering it again fails the same way. */
|
|
15575
|
+
code;
|
|
15510
15576
|
};
|
|
15511
15577
|
var MIN_CPUS_TO_CAPTURE_DURING_MIX = 4;
|
|
15512
15578
|
function applyRenderWarningPolicy(job, captureWarnings, log = defaultLogger) {
|
|
@@ -15736,7 +15802,7 @@ function isRecoverableParallelCaptureError(error) {
|
|
|
15736
15802
|
if (error instanceof RenderStageStalledError) return true;
|
|
15737
15803
|
const message = normalizeErrorMessage(error);
|
|
15738
15804
|
if (!message.includes("[Parallel] Capture failed")) return false;
|
|
15739
|
-
const kind =
|
|
15805
|
+
const kind = classifyCaptureFailure4(error).kind;
|
|
15740
15806
|
return kind === "transient_browser" || kind === "protocol_timeout";
|
|
15741
15807
|
}
|
|
15742
15808
|
function describeMemoryExhaustion(error, ctx) {
|
|
@@ -15768,6 +15834,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15768
15834
|
let attempt = 0;
|
|
15769
15835
|
let transientRetriesUsed = 0;
|
|
15770
15836
|
let initializationRetriesUsed = 0;
|
|
15837
|
+
let memoryRetriesUsed = 0;
|
|
15771
15838
|
let pendingTransientRetry = false;
|
|
15772
15839
|
const rangeStart = options.frameRangeStart ?? 0;
|
|
15773
15840
|
while (true) {
|
|
@@ -15867,7 +15934,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15867
15934
|
attempt++;
|
|
15868
15935
|
} catch (caught) {
|
|
15869
15936
|
const error = attemptSignal?.aborted && !options.abortSignal?.aborted ? attemptSignal.reason : caught;
|
|
15870
|
-
const failure =
|
|
15937
|
+
const failure = classifyCaptureFailure4(error, { signal: options.abortSignal });
|
|
15871
15938
|
if (failure.kind === "cancelled") {
|
|
15872
15939
|
throw error;
|
|
15873
15940
|
}
|
|
@@ -15917,6 +15984,24 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15917
15984
|
pendingTransientRetry = true;
|
|
15918
15985
|
continue;
|
|
15919
15986
|
}
|
|
15987
|
+
const fitWorkers = memoryRetriesUsed === 0 && failure.kind === "memory_exhaustion" ? captureMemoryRetryWorkers2(error) : void 0;
|
|
15988
|
+
if (options.allowRetry && currentWorkers > 1 && fitWorkers !== void 0) {
|
|
15989
|
+
memoryRetriesUsed++;
|
|
15990
|
+
const nextWorkers2 = Math.min(fitWorkers, currentWorkers - 1);
|
|
15991
|
+
options.log.warn(
|
|
15992
|
+
"[Render] Capture stopped before memory ran out; retrying missing frames with fewer workers.",
|
|
15993
|
+
{
|
|
15994
|
+
fromWorkers: currentWorkers,
|
|
15995
|
+
toWorkers: nextWorkers2,
|
|
15996
|
+
missingFrames: remainingCount,
|
|
15997
|
+
error: failure.message
|
|
15998
|
+
}
|
|
15999
|
+
);
|
|
16000
|
+
currentWorkers = nextWorkers2;
|
|
16001
|
+
missingRanges = remaining;
|
|
16002
|
+
attempt++;
|
|
16003
|
+
continue;
|
|
16004
|
+
}
|
|
15920
16005
|
if (!madeProgress) {
|
|
15921
16006
|
options.log.warn(
|
|
15922
16007
|
"[Render] Capture attempt made no forward progress; composition is likely structurally broken, not retrying.",
|
|
@@ -17026,7 +17111,7 @@ async function executeRenderPipeline(input) {
|
|
|
17026
17111
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
17027
17112
|
code: "start_browsers"
|
|
17028
17113
|
});
|
|
17029
|
-
let resolvedBrowserGpuMode = await
|
|
17114
|
+
let resolvedBrowserGpuMode = await resolveBrowserGpuMode2(cfg.browserGpuMode, {
|
|
17030
17115
|
chromePath: resolveHeadlessShellPath(cfg),
|
|
17031
17116
|
browserTimeout: cfg.browserTimeout
|
|
17032
17117
|
});
|
|
@@ -18246,6 +18331,7 @@ async function executeRenderPipeline(input) {
|
|
|
18246
18331
|
const isParallelStall = isParallelCaptureStallError(err);
|
|
18247
18332
|
const isEncoderDeath = isRetryableEncoderDeath(err);
|
|
18248
18333
|
const isCancellation = err instanceof RenderCancelledError || executionSignal.aborted === true;
|
|
18334
|
+
if (err instanceof CaptureStageError && err.memoryRetryUsed) throw err;
|
|
18249
18335
|
if (!shouldRetryViaPinnedFallback({
|
|
18250
18336
|
isVerifyError,
|
|
18251
18337
|
isDeCaptureError,
|
|
@@ -18389,10 +18475,7 @@ async function executeRenderPipeline(input) {
|
|
|
18389
18475
|
assertNotAborted,
|
|
18390
18476
|
onProgress
|
|
18391
18477
|
};
|
|
18392
|
-
const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames
|
|
18393
|
-
workerCount: capturePlan.workerCount,
|
|
18394
|
-
cpuCount: cpuBudget()
|
|
18395
|
-
}) : null;
|
|
18478
|
+
const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames) : null;
|
|
18396
18479
|
const captureFrameStart = Date.now();
|
|
18397
18480
|
const invokeDiskCapture = (diskPlan) => observeRenderStage(
|
|
18398
18481
|
observability,
|
|
@@ -18983,7 +19066,11 @@ async function startHealthWorker(options = {}) {
|
|
|
18983
19066
|
);
|
|
18984
19067
|
}
|
|
18985
19068
|
const worker = new Worker4(entry, {
|
|
18986
|
-
workerData: {
|
|
19069
|
+
workerData: {
|
|
19070
|
+
port,
|
|
19071
|
+
hostname: options.hostname || "127.0.0.1",
|
|
19072
|
+
closeAfterMs: options.closeAfterMs
|
|
19073
|
+
},
|
|
18987
19074
|
// Keep stdio inherited so the worker's console logs land in the pod logs
|
|
18988
19075
|
// alongside the main thread's.
|
|
18989
19076
|
stdout: false,
|
|
@@ -19514,7 +19601,8 @@ var SAFE_RENDER_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
19514
19601
|
"VARIABLES_INVALID",
|
|
19515
19602
|
"OUTPUT_DIMENSIONS_MISMATCH",
|
|
19516
19603
|
"COMPOSITION_TOO_LARGE",
|
|
19517
|
-
"COMPILE_TIMEOUT"
|
|
19604
|
+
"COMPILE_TIMEOUT",
|
|
19605
|
+
"COMPOSITION_SCRIPT_FAILED"
|
|
19518
19606
|
]);
|
|
19519
19607
|
function extractSafeRenderErrorCode(error) {
|
|
19520
19608
|
if (typeof error !== "object" || error === null || !("code" in error)) return void 0;
|
|
@@ -19969,6 +20057,14 @@ function createSseProgressReporter(stream, requestId) {
|
|
|
19969
20057
|
});
|
|
19970
20058
|
};
|
|
19971
20059
|
}
|
|
20060
|
+
function renderFailureLogFields(job, safeError) {
|
|
20061
|
+
const failedPhase = job.errorDetails?.observability?.failedPhase;
|
|
20062
|
+
const errorCode = safeError?.errorCode;
|
|
20063
|
+
return {
|
|
20064
|
+
...failedPhase ? { failedPhase } : {},
|
|
20065
|
+
...errorCode ? { errorCode } : {}
|
|
20066
|
+
};
|
|
20067
|
+
}
|
|
19972
20068
|
async function writeRenderStreamFailure(input) {
|
|
19973
20069
|
const { error, job, stream, requestId, startedAtMs, log } = input;
|
|
19974
20070
|
if (error instanceof RenderCancelledError) {
|
|
@@ -19990,7 +20086,8 @@ async function writeRenderStreamFailure(input) {
|
|
|
19990
20086
|
requestId,
|
|
19991
20087
|
elapsedMs,
|
|
19992
20088
|
error: errorMsg,
|
|
19993
|
-
stage: job.currentStage
|
|
20089
|
+
stage: job.currentStage,
|
|
20090
|
+
...renderFailureLogFields(job, safeError)
|
|
19994
20091
|
});
|
|
19995
20092
|
await stream.writeSSE({
|
|
19996
20093
|
data: JSON.stringify({
|
|
@@ -20135,7 +20232,8 @@ function createRenderHandlers(options = {}) {
|
|
|
20135
20232
|
requestId,
|
|
20136
20233
|
durationMs,
|
|
20137
20234
|
error: errorMsg,
|
|
20138
|
-
stage: job.currentStage
|
|
20235
|
+
stage: job.currentStage,
|
|
20236
|
+
...renderFailureLogFields(job, safeError)
|
|
20139
20237
|
});
|
|
20140
20238
|
return c.json(
|
|
20141
20239
|
{
|
|
@@ -20418,7 +20516,7 @@ function startServer(options = {}) {
|
|
|
20418
20516
|
server.setTimeout(0);
|
|
20419
20517
|
server.requestTimeout = 0;
|
|
20420
20518
|
server.keepAliveTimeout = 0;
|
|
20421
|
-
const healthWorkerPromise = process.env.PRODUCER_DISABLE_HEALTH_WORKER === "1" ? Promise.resolve(null) : startHealthWorker({ logger: log }).catch((err) => {
|
|
20519
|
+
const healthWorkerPromise = process.env.PRODUCER_DISABLE_HEALTH_WORKER === "1" ? Promise.resolve(null) : startHealthWorker({ logger: log, hostname }).catch((err) => {
|
|
20422
20520
|
log.error(`[server] health worker failed to start: ${err.message}`);
|
|
20423
20521
|
return null;
|
|
20424
20522
|
});
|
|
@@ -17,13 +17,6 @@
|
|
|
17
17
|
* the probe `timeoutSeconds` (5s in prod prior to the companion change)
|
|
18
18
|
* triggers a SIGKILL even when the process is still alive — just busy.
|
|
19
19
|
*
|
|
20
|
-
* Today's incident (2026-06-26): an infinite GSAP timeline caused the
|
|
21
|
-
* distributed planner to try to enumerate ~300_000_000_000 frames, and
|
|
22
|
-
* the sidecar got killed mid-arithmetic. Miguel's upstream `plan()`
|
|
23
|
-
* duration guard kills that input class at the source. This module is
|
|
24
|
-
* defense-in-depth: future wedge classes (sync I/O on video-heavy comps,
|
|
25
|
-
* runaway loops, GC pauses) shouldn't kill an otherwise-alive pod either.
|
|
26
|
-
*
|
|
27
20
|
* Contract
|
|
28
21
|
* --------
|
|
29
22
|
*
|
|
@@ -33,10 +26,10 @@
|
|
|
33
26
|
* which is a strict subset of process liveness. If the entire Node process
|
|
34
27
|
* is dead the OS tears down both threads' sockets simultaneously, so the
|
|
35
28
|
* worker_thread's listener stops answering and k8s correctly kills the pod.
|
|
36
|
-
* -
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
29
|
+
* - The listener binds the address it is given (`startServer` passes the main
|
|
30
|
+
* server's own), loopback when given none, and answers in the shape the
|
|
31
|
+
* main-thread `/health` always returned. A connection with no whole request
|
|
32
|
+
* within a few seconds, or idle after one, is closed; connections are capped.
|
|
40
33
|
*
|
|
41
34
|
* The main thread still serves `/health` on the main port (9847) for
|
|
42
35
|
* backwards compatibility; k8s probe config in `heygen-com/app` can migrate
|
|
@@ -45,6 +38,10 @@
|
|
|
45
38
|
export interface HealthWorkerOptions {
|
|
46
39
|
/** Port the worker_thread health endpoint listens on. Default 9848 / env. */
|
|
47
40
|
port?: number;
|
|
41
|
+
/** Address the endpoint listens on. Default `127.0.0.1`. */
|
|
42
|
+
hostname?: string;
|
|
43
|
+
/** How long a connection may go without a whole request, or sit idle. Default 5000 ms. */
|
|
44
|
+
closeAfterMs?: number;
|
|
48
45
|
/**
|
|
49
46
|
* Optional logger; falls back to console. Note: the worker thread itself
|
|
50
47
|
* cannot use the parent's logger directly (separate isolate), so it logs
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Worker-thread entry for the off-main-thread /health endpoint.
|
|
3
3
|
*
|
|
4
|
-
* Runs a minimal `node:http` server bound to `workerData.port` that answers
|
|
4
|
+
* Runs a minimal `node:http` server bound to `workerData.port` on `workerData.hostname` that answers
|
|
5
5
|
* `GET /health` with `{ status, uptime, timestamp, thread: "worker" }`.
|
|
6
6
|
*
|
|
7
7
|
* Lifecycle:
|
|
@@ -18,6 +18,9 @@ export interface CaptureCostEstimate {
|
|
|
18
18
|
reasons: string[];
|
|
19
19
|
p95Ms?: number;
|
|
20
20
|
medianMs?: number;
|
|
21
|
+
coresPerWorker?: number;
|
|
22
|
+
/** The browser's memory after the samples, which a page can allocate on its first drawn frame. */
|
|
23
|
+
browserRssMb?: number;
|
|
21
24
|
}
|
|
22
25
|
export interface CaptureCalibrationSample {
|
|
23
26
|
frameIndex: number;
|
|
@@ -74,6 +77,7 @@ firstFrame?: number): Promise<{
|
|
|
74
77
|
estimate: CaptureCostEstimate;
|
|
75
78
|
samples: CaptureCalibrationSample[];
|
|
76
79
|
}>;
|
|
80
|
+
export declare function chromeCoresUsed(before: ReadonlyMap<number, number> | undefined, after: ReadonlyMap<number, number> | undefined, elapsedMs: number): number | undefined;
|
|
77
81
|
export declare function logCaptureCalibrationResult(calibration: {
|
|
78
82
|
estimate: CaptureCostEstimate;
|
|
79
83
|
samples: CaptureCalibrationSample[];
|
|
@@ -2,6 +2,7 @@ import { CaptureFailure } from "@hyperframes/engine";
|
|
|
2
2
|
import { EncoderInterruptedError } from "./encoderInterruption.js";
|
|
3
3
|
export declare class CaptureStageError extends CaptureFailure {
|
|
4
4
|
readonly browserConsole: string[];
|
|
5
|
+
memoryRetryUsed: boolean;
|
|
5
6
|
constructor(input: {
|
|
6
7
|
cause: unknown;
|
|
7
8
|
browserConsole: string[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { spawnStreamingEncoder } from "@hyperframes/engine";
|
|
2
|
+
/** Starts an encoder that runs while frames are still being captured, one step below the capture's priority. */
|
|
3
|
+
export declare function spawnCaptureEncoder(...[outputPath, options, signal, config]: Parameters<typeof spawnStreamingEncoder>): ReturnType<typeof spawnStreamingEncoder>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { captureFrameToBuffer, closeCaptureSession, concatVideoFiles,
|
|
1
|
+
import { captureFrameToBuffer, closeCaptureSession, concatVideoFiles, type BeforeCaptureHook, type CaptureOptions, type CapturePerfSummary, type CaptureSession, type EngineConfig } from "@hyperframes/engine";
|
|
2
2
|
import type { FileServerHandle } from "../../fileServer.js";
|
|
3
3
|
import type { ProducerLogger } from "../../../logger.js";
|
|
4
4
|
import type { ProgressCallback, RenderJob } from "../../renderOrchestrator.js";
|
|
5
5
|
import type { SdrSegmentedCapturePlan } from "../capturePlan.js";
|
|
6
6
|
import type { SegmentVideoFrames } from "../segmentVideoFrames.js";
|
|
7
7
|
import { type StreamingEncoderOptions } from "./captureStreamingStage.js";
|
|
8
|
+
import { spawnCaptureEncoder } from "./captureEncoder.js";
|
|
8
9
|
export interface SegmentedStageDeps {
|
|
9
|
-
spawnEncoder: typeof
|
|
10
|
+
spawnEncoder: typeof spawnCaptureEncoder;
|
|
10
11
|
captureFrame: typeof captureFrameToBuffer;
|
|
11
12
|
concat: typeof concatVideoFiles;
|
|
12
13
|
closeSession: typeof closeCaptureSession;
|
|
@@ -38,10 +38,11 @@
|
|
|
38
38
|
* Safe at runtime; a subsequent change will move the capture helpers
|
|
39
39
|
* into a shared module so the stages can import without reaching back.
|
|
40
40
|
*/
|
|
41
|
-
import { type BeforeCaptureHook, type CaptureOptions, type CapturePerfSummary, type CaptureSession, type EngineConfig
|
|
41
|
+
import { type BeforeCaptureHook, type CaptureOptions, type CapturePerfSummary, type CaptureSession, type EngineConfig } from "@hyperframes/engine";
|
|
42
42
|
import type { FileServerHandle } from "../../fileServer.js";
|
|
43
43
|
import type { ProducerLogger } from "../../../logger.js";
|
|
44
44
|
import type { ProgressCallback, RenderJob } from "../../renderOrchestrator.js";
|
|
45
|
+
import { spawnCaptureEncoder } from "./captureEncoder.js";
|
|
45
46
|
import type { SdrStreamingCapturePlan } from "../capturePlan.js";
|
|
46
47
|
export declare function resolveCaptureStallTimeoutMs(): number;
|
|
47
48
|
export type StalledSession = {
|
|
@@ -72,7 +73,7 @@ export declare function createSessionInitBudget(input: {
|
|
|
72
73
|
* passes it through so the stage doesn't have to reach back for the
|
|
73
74
|
* preset's internal shape.
|
|
74
75
|
*/
|
|
75
|
-
export type StreamingEncoderOptions = Parameters<typeof
|
|
76
|
+
export type StreamingEncoderOptions = Parameters<typeof spawnCaptureEncoder>[1];
|
|
76
77
|
export interface CaptureStreamingStageInput {
|
|
77
78
|
fileServer: FileServerHandle;
|
|
78
79
|
workDir: string;
|
|
@@ -91,7 +92,7 @@ export interface CaptureStreamingStageInput {
|
|
|
91
92
|
probeSession: CaptureSession | null;
|
|
92
93
|
/** For the spawn-failure log message context only. */
|
|
93
94
|
outputFormat: string;
|
|
94
|
-
/** Pre-built encoder options; passed straight to `
|
|
95
|
+
/** Pre-built encoder options; passed straight to `spawnCaptureEncoder`. */
|
|
95
96
|
streamingEncoderOptions: StreamingEncoderOptions;
|
|
96
97
|
/**
|
|
97
98
|
* What the parallel workers capture with — "drawElement", "BeginFrame" or
|