@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/index.js
CHANGED
|
@@ -338,7 +338,7 @@ import {
|
|
|
338
338
|
getSystemTotalMb,
|
|
339
339
|
LOW_MEMORY_TOTAL_MB_THRESHOLD,
|
|
340
340
|
assertConfiguredFfmpegBinariesExist,
|
|
341
|
-
resolveBrowserGpuMode,
|
|
341
|
+
resolveBrowserGpuMode as resolveBrowserGpuMode2,
|
|
342
342
|
probedHardwareGpu,
|
|
343
343
|
resolveHeadlessShellPath,
|
|
344
344
|
compositionRequiresWebGpu as compositionRequiresWebGpu2,
|
|
@@ -346,7 +346,8 @@ import {
|
|
|
346
346
|
explainDrawElementDisabled,
|
|
347
347
|
chromeMajorCeiling,
|
|
348
348
|
scaleProtocolTimeoutForComposition,
|
|
349
|
-
|
|
349
|
+
captureMemoryRetryWorkers as captureMemoryRetryWorkers2,
|
|
350
|
+
classifyCaptureFailure as classifyCaptureFailure4,
|
|
350
351
|
cloneCaptureWarning,
|
|
351
352
|
isMemoryExhaustionError as isMemoryExhaustionError2,
|
|
352
353
|
isTransientBrowserError as isTransientBrowserError2,
|
|
@@ -2587,8 +2588,7 @@ import {
|
|
|
2587
2588
|
initializeSession as initializeSession2,
|
|
2588
2589
|
prepareCaptureSessionForReuse as prepareCaptureSessionForReuse2,
|
|
2589
2590
|
resolveDeVerifyMinDb as resolveDeVerifyMinDb2,
|
|
2590
|
-
shouldDisableBrowserPoolForParallelWorker
|
|
2591
|
-
spawnStreamingEncoder as spawnStreamingEncoder2
|
|
2591
|
+
shouldDisableBrowserPoolForParallelWorker
|
|
2592
2592
|
} from "@hyperframes/engine";
|
|
2593
2593
|
|
|
2594
2594
|
// src/services/render/captureStageError.ts
|
|
@@ -2960,6 +2960,7 @@ function buildRenderPerfSummary(input) {
|
|
|
2960
2960
|
// src/services/render/captureStageError.ts
|
|
2961
2961
|
var CaptureStageError = class extends CaptureFailure {
|
|
2962
2962
|
browserConsole;
|
|
2963
|
+
memoryRetryUsed = false;
|
|
2963
2964
|
constructor(input) {
|
|
2964
2965
|
const classified = classifyCaptureFailure(input.cause);
|
|
2965
2966
|
super({
|
|
@@ -4547,6 +4548,8 @@ import {
|
|
|
4547
4548
|
captureFrameToBuffer,
|
|
4548
4549
|
captureFrameToBufferPipelined,
|
|
4549
4550
|
captureFramesBatchPipelined,
|
|
4551
|
+
captureMemoryRetryWorkers,
|
|
4552
|
+
classifyCaptureFailure as classifyCaptureFailure2,
|
|
4550
4553
|
closeCaptureSession,
|
|
4551
4554
|
createCaptureSession,
|
|
4552
4555
|
createFrameReorderBuffer,
|
|
@@ -4560,8 +4563,7 @@ import {
|
|
|
4560
4563
|
recaptureDrawElementFrameForVerify,
|
|
4561
4564
|
completeDeferredDrawElementInit,
|
|
4562
4565
|
initializeSession,
|
|
4563
|
-
prepareCaptureSessionForReuse
|
|
4564
|
-
spawnStreamingEncoder
|
|
4566
|
+
prepareCaptureSessionForReuse
|
|
4565
4567
|
} from "@hyperframes/engine";
|
|
4566
4568
|
|
|
4567
4569
|
// src/services/render/stallClock.ts
|
|
@@ -4583,6 +4585,17 @@ function createStallClock(now = () => Date.now()) {
|
|
|
4583
4585
|
};
|
|
4584
4586
|
}
|
|
4585
4587
|
|
|
4588
|
+
// src/services/render/stages/captureEncoder.ts
|
|
4589
|
+
import { spawnStreamingEncoder } from "@hyperframes/engine";
|
|
4590
|
+
function spawnCaptureEncoder(...[outputPath, options, signal, config]) {
|
|
4591
|
+
return spawnStreamingEncoder(
|
|
4592
|
+
outputPath,
|
|
4593
|
+
{ ...options, belowNormalPriority: true },
|
|
4594
|
+
signal,
|
|
4595
|
+
config
|
|
4596
|
+
);
|
|
4597
|
+
}
|
|
4598
|
+
|
|
4586
4599
|
// src/services/render/stages/captureStreamingStage.ts
|
|
4587
4600
|
var DEFAULT_CAPTURE_STALL_MS = 6e4;
|
|
4588
4601
|
var SESSION_INIT_STALL_MS = 3e5;
|
|
@@ -4982,7 +4995,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
4982
4995
|
let streamingEncoder = null;
|
|
4983
4996
|
let streamingEncoderClosed = false;
|
|
4984
4997
|
try {
|
|
4985
|
-
streamingEncoder = await
|
|
4998
|
+
streamingEncoder = await spawnCaptureEncoder(
|
|
4986
4999
|
videoOnlyPath,
|
|
4987
5000
|
streamingEncoderOptions,
|
|
4988
5001
|
abortSignal,
|
|
@@ -5026,6 +5039,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
5026
5039
|
let writtenFrames = 0;
|
|
5027
5040
|
let resumeFrom = 0;
|
|
5028
5041
|
let resumes = 0;
|
|
5042
|
+
let memoryRetryUsed = false;
|
|
5029
5043
|
let workerResults;
|
|
5030
5044
|
for (; ; ) {
|
|
5031
5045
|
const parallelReorder = createFrameReorderBuffer(resumeFrom, totalFrames);
|
|
@@ -5157,6 +5171,25 @@ async function runCaptureStreamingStage(input) {
|
|
|
5157
5171
|
resumes++;
|
|
5158
5172
|
continue;
|
|
5159
5173
|
}
|
|
5174
|
+
const stop = parallelDrainError ?? err;
|
|
5175
|
+
const memoryStop = abortSignal?.aborted !== true && captureLabel === "screenshot" && classifyCaptureFailure2(stop).kind === "memory_exhaustion";
|
|
5176
|
+
const fitWorkers = memoryStop && !memoryRetryUsed ? captureMemoryRetryWorkers(stop) : void 0;
|
|
5177
|
+
if (workerCount > 1 && fitWorkers !== void 0) {
|
|
5178
|
+
memoryRetryUsed = true;
|
|
5179
|
+
const nextWorkers = Math.min(fitWorkers, workerCount - 1);
|
|
5180
|
+
log.warn(
|
|
5181
|
+
"[Render] Capture stopped before memory ran out; resuming from the first unwritten frame with fewer workers.",
|
|
5182
|
+
{ fromWorkers: workerCount, toWorkers: nextWorkers, resumeFrom: writtenFrames }
|
|
5183
|
+
);
|
|
5184
|
+
workerCount = nextWorkers;
|
|
5185
|
+
resumeFrom = writtenFrames;
|
|
5186
|
+
continue;
|
|
5187
|
+
}
|
|
5188
|
+
if (memoryStop && memoryRetryUsed) {
|
|
5189
|
+
const failure = poolFailure(stop, probeSession);
|
|
5190
|
+
if (failure instanceof CaptureStageError) failure.memoryRetryUsed = true;
|
|
5191
|
+
throw failure;
|
|
5192
|
+
}
|
|
5160
5193
|
if (parallelDrainError) throw poolFailure(parallelDrainError, probeSession);
|
|
5161
5194
|
if (stalled && abortSignal?.aborted !== true) {
|
|
5162
5195
|
throw new ParallelCaptureStallError({
|
|
@@ -5487,7 +5520,7 @@ async function captureSegmentToEncoder(ctx, segment) {
|
|
|
5487
5520
|
}
|
|
5488
5521
|
}
|
|
5489
5522
|
var DEFAULT_DEPS = {
|
|
5490
|
-
spawnEncoder:
|
|
5523
|
+
spawnEncoder: spawnCaptureEncoder,
|
|
5491
5524
|
captureFrame: captureFrameToBuffer2,
|
|
5492
5525
|
concat: concatVideoFiles,
|
|
5493
5526
|
// Through the import binding, not captured: a value captured at module load
|
|
@@ -5872,10 +5905,13 @@ import { fpsToNumber as fpsToNumber4 } from "@hyperframes/core";
|
|
|
5872
5905
|
import {
|
|
5873
5906
|
calculateOptimalWorkers,
|
|
5874
5907
|
captureFrameToBuffer as captureFrameToBuffer3,
|
|
5908
|
+
clearStaticDedupAnchor,
|
|
5875
5909
|
closeCaptureSession as closeCaptureSession3,
|
|
5876
5910
|
computeWorkerSizing,
|
|
5877
5911
|
createCaptureSession as createCaptureSession3,
|
|
5878
|
-
initializeSession as initializeSession3
|
|
5912
|
+
initializeSession as initializeSession3,
|
|
5913
|
+
readChromeCpuSeconds,
|
|
5914
|
+
resolveBrowserGpuMode
|
|
5879
5915
|
} from "@hyperframes/engine";
|
|
5880
5916
|
var CAPTURE_CALIBRATION_TARGET_MS = 600;
|
|
5881
5917
|
var MAX_MEASURED_CAPTURE_COST_MULTIPLIER = 8;
|
|
@@ -5915,13 +5951,20 @@ function combineCaptureCostEstimates(staticCost, measuredCost) {
|
|
|
5915
5951
|
multiplier: measuredCost.multiplier,
|
|
5916
5952
|
reasons: [...measuredCost.reasons, ...staticCost.reasons],
|
|
5917
5953
|
p95Ms: measuredCost.p95Ms,
|
|
5918
|
-
medianMs: measuredCost.medianMs
|
|
5954
|
+
medianMs: measuredCost.medianMs,
|
|
5955
|
+
// A hint names work the samples can miss, such as a shader transition between two of them.
|
|
5956
|
+
coresPerWorker: staticCost.multiplier > 1 ? void 0 : measuredCost.coresPerWorker,
|
|
5957
|
+
browserRssMb: measuredCost.browserRssMb
|
|
5919
5958
|
};
|
|
5920
5959
|
}
|
|
5921
5960
|
function buildHeapAdvisoryWarning(sizing, requestedWorkers) {
|
|
5922
5961
|
if (requestedWorkers !== void 0 || !sizing.exceedsHeapAdvisory) return void 0;
|
|
5923
5962
|
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}.`;
|
|
5924
5963
|
}
|
|
5964
|
+
function coresToSizeBy(cost, protocolTimeout) {
|
|
5965
|
+
if (cost.browserRssMb === void 0) return void 0;
|
|
5966
|
+
return 2 * (cost.p95Ms ?? Infinity) < protocolTimeout ? cost.coresPerWorker : void 0;
|
|
5967
|
+
}
|
|
5925
5968
|
function resolveRenderWorkerCount(totalFrames, requestedWorkers, cfg, compiled, log = defaultLogger, measuredCaptureCost, onSizing) {
|
|
5926
5969
|
const reasonCodes = new Set(compiled.renderModeHints.reasons.map((r) => r.code));
|
|
5927
5970
|
if (reasonCodes.has("htmlInCanvas")) {
|
|
@@ -5943,7 +5986,9 @@ function resolveRenderWorkerCount(totalFrames, requestedWorkers, cfg, compiled,
|
|
|
5943
5986
|
);
|
|
5944
5987
|
const sizing = computeWorkerSizing(totalFrames, requestedWorkers, {
|
|
5945
5988
|
...cfg,
|
|
5946
|
-
captureCostMultiplier: captureCost.multiplier
|
|
5989
|
+
captureCostMultiplier: captureCost.multiplier,
|
|
5990
|
+
measuredCoresPerWorker: coresToSizeBy(captureCost, cfg.protocolTimeout),
|
|
5991
|
+
measuredBrowserRssMb: captureCost.browserRssMb
|
|
5947
5992
|
});
|
|
5948
5993
|
onSizing?.(sizing);
|
|
5949
5994
|
const workerCount = sizing.workers;
|
|
@@ -6042,7 +6087,7 @@ async function measureCaptureCostFromSession(session, totalFrames, fps, log, fir
|
|
|
6042
6087
|
}
|
|
6043
6088
|
} finally {
|
|
6044
6089
|
session.staticFrames = savedStaticFrames;
|
|
6045
|
-
session
|
|
6090
|
+
clearStaticDedupAnchor(session);
|
|
6046
6091
|
}
|
|
6047
6092
|
const estimate = estimateMeasuredCaptureCostMultiplier(samples);
|
|
6048
6093
|
if (estimate.p95Ms !== void 0) {
|
|
@@ -6053,11 +6098,20 @@ async function measureCaptureCostFromSession(session, totalFrames, fps, log, fir
|
|
|
6053
6098
|
samples
|
|
6054
6099
|
};
|
|
6055
6100
|
}
|
|
6101
|
+
function chromeCoresUsed(before, after, elapsedMs) {
|
|
6102
|
+
if (!before || !after || elapsedMs <= 0) return void 0;
|
|
6103
|
+
for (const pid of before.keys()) if (!after.has(pid)) return void 0;
|
|
6104
|
+
const total = (cpu) => [...cpu.values()].reduce((a, b) => a + b, 0);
|
|
6105
|
+
const cores = (total(after) - total(before)) / (elapsedMs / 1e3);
|
|
6106
|
+
return cores > 0 ? cores : void 0;
|
|
6107
|
+
}
|
|
6056
6108
|
function logCaptureCalibrationResult(calibration, log) {
|
|
6057
6109
|
if (calibration.estimate.multiplier > 1) {
|
|
6058
6110
|
log.warn("[Render] Measured slow frame capture during auto-worker calibration.", {
|
|
6059
6111
|
multiplier: calibration.estimate.multiplier,
|
|
6060
6112
|
p95Ms: calibration.estimate.p95Ms,
|
|
6113
|
+
coresPerWorker: calibration.estimate.coresPerWorker,
|
|
6114
|
+
browserRssMb: calibration.estimate.browserRssMb,
|
|
6061
6115
|
sampledFrames: calibration.samples.map((sample) => sample.frameIndex),
|
|
6062
6116
|
sampleMs: calibration.samples.map((sample) => Math.round(sample.captureTimeMs))
|
|
6063
6117
|
});
|
|
@@ -6121,6 +6175,12 @@ async function runCaptureCalibration(input) {
|
|
|
6121
6175
|
}
|
|
6122
6176
|
assertNotAborted();
|
|
6123
6177
|
log.info("Calibration session ready, capturing test frames...");
|
|
6178
|
+
const readCpu = () => readChromeCpuSeconds(() => session.browser.target().createCDPSession()).catch(
|
|
6179
|
+
() => void 0
|
|
6180
|
+
);
|
|
6181
|
+
const softwareGpu = await resolveBrowserGpuMode(sessionCfg.browserGpuMode) === "software";
|
|
6182
|
+
const cpuBefore = softwareGpu ? await readCpu() : void 0;
|
|
6183
|
+
const startedAt = performance.now();
|
|
6124
6184
|
const result = await measureCaptureCostFromSession(
|
|
6125
6185
|
session,
|
|
6126
6186
|
totalFrames,
|
|
@@ -6128,6 +6188,15 @@ async function runCaptureCalibration(input) {
|
|
|
6128
6188
|
log,
|
|
6129
6189
|
job.frameWindow?.startFrame
|
|
6130
6190
|
);
|
|
6191
|
+
const elapsedMs = performance.now() - startedAt;
|
|
6192
|
+
const cpuAfter = cpuBefore && await readCpu();
|
|
6193
|
+
result.estimate.coresPerWorker = chromeCoresUsed(cpuBefore, cpuAfter, elapsedMs);
|
|
6194
|
+
if (result.estimate.coresPerWorker !== void 0) {
|
|
6195
|
+
const before = session.chromeMemory?.stats().samples ?? 0;
|
|
6196
|
+
await session.chromeMemory?.sampleOnce();
|
|
6197
|
+
const memory = session.chromeMemory?.stats();
|
|
6198
|
+
if (memory && memory.samples > before) result.estimate.browserRssMb = memory.rssLastMb;
|
|
6199
|
+
}
|
|
6131
6200
|
logCaptureCalibrationResult(result, log);
|
|
6132
6201
|
return result;
|
|
6133
6202
|
};
|
|
@@ -9047,7 +9116,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
9047
9116
|
}
|
|
9048
9117
|
return { subCompositions };
|
|
9049
9118
|
}
|
|
9050
|
-
function promoteCssImportsToLinkTags(html) {
|
|
9119
|
+
function promoteCssImportsToLinkTags(html, budget) {
|
|
9051
9120
|
const { document: document2 } = parseHTML5(html);
|
|
9052
9121
|
const head = document2.querySelector("head");
|
|
9053
9122
|
if (!head) return html;
|
|
@@ -9056,18 +9125,16 @@ function promoteCssImportsToLinkTags(html) {
|
|
|
9056
9125
|
const styleEls = document2.querySelectorAll("style");
|
|
9057
9126
|
for (const styleEl of styleEls) {
|
|
9058
9127
|
const original = styleEl.textContent || "";
|
|
9059
|
-
|
|
9060
|
-
let
|
|
9061
|
-
importRe
|
|
9062
|
-
while ((match = importRe.exec(original)) !== null) {
|
|
9128
|
+
const rulesBetweenImports = [];
|
|
9129
|
+
let keptTo = 0;
|
|
9130
|
+
for (const match of original.matchAll(importRe)) {
|
|
9063
9131
|
const url = match[1] ?? "";
|
|
9064
9132
|
if (!url.startsWith("http://") && !url.startsWith("https://")) continue;
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
}
|
|
9133
|
+
rulesBetweenImports.push(original.slice(keptTo, match.index));
|
|
9134
|
+
keptTo = match.index + match[0].length;
|
|
9135
|
+
if (seenUrls.has(url)) continue;
|
|
9069
9136
|
seenUrls.add(url);
|
|
9070
|
-
|
|
9137
|
+
budget.chargeElements(ENTRY_PAGE, 2);
|
|
9071
9138
|
const preload = document2.createElement("link");
|
|
9072
9139
|
preload.setAttribute("rel", "preload");
|
|
9073
9140
|
preload.setAttribute("href", url);
|
|
@@ -9078,8 +9145,8 @@ function promoteCssImportsToLinkTags(html) {
|
|
|
9078
9145
|
link.setAttribute("href", url);
|
|
9079
9146
|
head.appendChild(link);
|
|
9080
9147
|
}
|
|
9081
|
-
if (
|
|
9082
|
-
styleEl.textContent =
|
|
9148
|
+
if (keptTo > 0) {
|
|
9149
|
+
styleEl.textContent = rulesBetweenImports.join("") + original.slice(keptTo);
|
|
9083
9150
|
}
|
|
9084
9151
|
}
|
|
9085
9152
|
return document2.toString();
|
|
@@ -10129,7 +10196,7 @@ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, ass
|
|
|
10129
10196
|
...options.abortSignal ? [options.abortSignal] : []
|
|
10130
10197
|
]);
|
|
10131
10198
|
const fontSheetHtml = await inlineExternalFontStylesheets(
|
|
10132
|
-
promoteCssImportsToLinkTags(sanitizedHtml),
|
|
10199
|
+
promoteCssImportsToLinkTags(sanitizedHtml, budget),
|
|
10133
10200
|
budget,
|
|
10134
10201
|
remoteFetches
|
|
10135
10202
|
);
|
|
@@ -13509,7 +13576,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
|
|
|
13509
13576
|
import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
13510
13577
|
import { join as join30 } from "node:path";
|
|
13511
13578
|
import {
|
|
13512
|
-
classifyCaptureFailure as
|
|
13579
|
+
classifyCaptureFailure as classifyCaptureFailure3,
|
|
13513
13580
|
frameFileExtension,
|
|
13514
13581
|
captureFrame,
|
|
13515
13582
|
captureFrameToBufferPipelined as captureFrameToBufferPipelined2,
|
|
@@ -13816,7 +13883,7 @@ function resolveCaptureRange(frameRange, totalFrames) {
|
|
|
13816
13883
|
return { rangeStart: frameRange?.startFrame ?? 0, rangeEnd: frameRange?.endFrame ?? totalFrames };
|
|
13817
13884
|
}
|
|
13818
13885
|
function planTransientResume(error, ctx) {
|
|
13819
|
-
const failure =
|
|
13886
|
+
const failure = classifyCaptureFailure3(error, { signal: ctx.abortSignal });
|
|
13820
13887
|
const missing = findMissingFrameRanges(ctx.rangeFrames, ctx.framesDir, ctx.frameExt);
|
|
13821
13888
|
const [firstMissing] = missing;
|
|
13822
13889
|
if (!firstMissing) return null;
|
|
@@ -13912,8 +13979,7 @@ import {
|
|
|
13912
13979
|
cloneCaptureWarnings as cloneCaptureWarnings2,
|
|
13913
13980
|
createCaptureSession as createCaptureSession7,
|
|
13914
13981
|
initTransparentBackground as initTransparentBackground2,
|
|
13915
|
-
initializeSession as initializeSession7
|
|
13916
|
-
spawnStreamingEncoder as spawnStreamingEncoder3
|
|
13982
|
+
initializeSession as initializeSession7
|
|
13917
13983
|
} from "@hyperframes/engine";
|
|
13918
13984
|
import { fpsToNumber as fpsToNumber7 } from "@hyperframes/core";
|
|
13919
13985
|
|
|
@@ -14704,7 +14770,7 @@ async function runCaptureHdrStage(input) {
|
|
|
14704
14770
|
}))
|
|
14705
14771
|
});
|
|
14706
14772
|
}
|
|
14707
|
-
hdrEncoder = await
|
|
14773
|
+
hdrEncoder = await spawnCaptureEncoder(
|
|
14708
14774
|
videoOnlyPath,
|
|
14709
14775
|
{
|
|
14710
14776
|
fps: job.config.fps,
|
|
@@ -14943,8 +15009,7 @@ import {
|
|
|
14943
15009
|
formatFfmpegError,
|
|
14944
15010
|
MIXED_AUDIO_FILENAME as MIXED_AUDIO_FILENAME2,
|
|
14945
15011
|
resolveConfig,
|
|
14946
|
-
runFfmpeg as runFfmpeg6
|
|
14947
|
-
spawnStreamingEncoder as spawnStreamingEncoder4
|
|
15012
|
+
runFfmpeg as runFfmpeg6
|
|
14948
15013
|
} from "@hyperframes/engine";
|
|
14949
15014
|
import {
|
|
14950
15015
|
clearGifFramesBeforeNext,
|
|
@@ -15084,10 +15149,7 @@ function startEncodeProgress(job, stage, onProgress) {
|
|
|
15084
15149
|
function resolveEngineConfig(input) {
|
|
15085
15150
|
return input.engineConfig ?? input.job.config.producerConfig ?? resolveConfig();
|
|
15086
15151
|
}
|
|
15087
|
-
function
|
|
15088
|
-
return Math.max(1, Math.floor(cpuCount) - Math.floor(workerCount));
|
|
15089
|
-
}
|
|
15090
|
-
function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
|
|
15152
|
+
function videoEncoderOptions(input, engineCfg) {
|
|
15091
15153
|
const { job, preset } = input;
|
|
15092
15154
|
return {
|
|
15093
15155
|
fps: job.config.fps,
|
|
@@ -15107,8 +15169,7 @@ function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
|
|
|
15107
15169
|
// keyframes that survive `-f concat -c copy` at assemble time. In-process
|
|
15108
15170
|
// renders leave both undefined → preserves the existing open-GOP output.
|
|
15109
15171
|
lockGopForChunkConcat: input.lockGopForChunkConcat === true,
|
|
15110
|
-
gopSize: input.gopSize
|
|
15111
|
-
softwareEncoderThreads
|
|
15172
|
+
gopSize: input.gopSize
|
|
15112
15173
|
};
|
|
15113
15174
|
}
|
|
15114
15175
|
function canEncodeWhileCapturing(input, workerCount, cpuCount) {
|
|
@@ -15124,9 +15185,8 @@ async function readLandedFrame(workerPath, mergedPath) {
|
|
|
15124
15185
|
}
|
|
15125
15186
|
return readFile2(mergedPath);
|
|
15126
15187
|
}
|
|
15127
|
-
function encodeWhileCapturing(input, totalFrames
|
|
15188
|
+
function encodeWhileCapturing(input, totalFrames) {
|
|
15128
15189
|
const engineCfg = resolveEngineConfig(input);
|
|
15129
|
-
const softwareEncoderThreads = captureBudget ? overlapEncoderThreads(captureBudget.workerCount, captureBudget.cpuCount) : void 0;
|
|
15130
15190
|
const stop = new AbortController();
|
|
15131
15191
|
const signal = input.abortSignal ? AbortSignal.any([input.abortSignal, stop.signal]) : stop.signal;
|
|
15132
15192
|
const landed = /* @__PURE__ */ new Map();
|
|
@@ -15139,10 +15199,10 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
|
|
|
15139
15199
|
};
|
|
15140
15200
|
signal.addEventListener("abort", nudge, { once: true });
|
|
15141
15201
|
let reportFed = null;
|
|
15142
|
-
const encoder =
|
|
15202
|
+
const encoder = spawnCaptureEncoder(
|
|
15143
15203
|
input.videoOnlyPath,
|
|
15144
15204
|
{
|
|
15145
|
-
...videoEncoderOptions(input, engineCfg
|
|
15205
|
+
...videoEncoderOptions(input, engineCfg),
|
|
15146
15206
|
imageFormat: "jpeg"
|
|
15147
15207
|
},
|
|
15148
15208
|
signal,
|
|
@@ -15523,8 +15583,14 @@ var RenderQualityError = class extends Error {
|
|
|
15523
15583
|
);
|
|
15524
15584
|
this.warnings = warnings;
|
|
15525
15585
|
this.name = "RenderQualityError";
|
|
15586
|
+
const failed = warnings.filter((warning) => warning.code === "sub_timeline_script_failure");
|
|
15587
|
+
if (failed.length > 0 && failed.every((warning) => warning.details?.scriptThrew === true)) {
|
|
15588
|
+
this.code = "COMPOSITION_SCRIPT_FAILED";
|
|
15589
|
+
}
|
|
15526
15590
|
}
|
|
15527
15591
|
warnings;
|
|
15592
|
+
/** Set only when the composition's own script threw: rendering it again fails the same way. */
|
|
15593
|
+
code;
|
|
15528
15594
|
};
|
|
15529
15595
|
var MIN_CPUS_TO_CAPTURE_DURING_MIX = 4;
|
|
15530
15596
|
function applyRenderWarningPolicy(job, captureWarnings, log = defaultLogger) {
|
|
@@ -15754,7 +15820,7 @@ function isRecoverableParallelCaptureError(error) {
|
|
|
15754
15820
|
if (error instanceof RenderStageStalledError) return true;
|
|
15755
15821
|
const message = normalizeErrorMessage(error);
|
|
15756
15822
|
if (!message.includes("[Parallel] Capture failed")) return false;
|
|
15757
|
-
const kind =
|
|
15823
|
+
const kind = classifyCaptureFailure4(error).kind;
|
|
15758
15824
|
return kind === "transient_browser" || kind === "protocol_timeout";
|
|
15759
15825
|
}
|
|
15760
15826
|
function describeMemoryExhaustion(error, ctx) {
|
|
@@ -15786,6 +15852,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15786
15852
|
let attempt = 0;
|
|
15787
15853
|
let transientRetriesUsed = 0;
|
|
15788
15854
|
let initializationRetriesUsed = 0;
|
|
15855
|
+
let memoryRetriesUsed = 0;
|
|
15789
15856
|
let pendingTransientRetry = false;
|
|
15790
15857
|
const rangeStart = options.frameRangeStart ?? 0;
|
|
15791
15858
|
while (true) {
|
|
@@ -15885,7 +15952,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15885
15952
|
attempt++;
|
|
15886
15953
|
} catch (caught) {
|
|
15887
15954
|
const error = attemptSignal?.aborted && !options.abortSignal?.aborted ? attemptSignal.reason : caught;
|
|
15888
|
-
const failure =
|
|
15955
|
+
const failure = classifyCaptureFailure4(error, { signal: options.abortSignal });
|
|
15889
15956
|
if (failure.kind === "cancelled") {
|
|
15890
15957
|
throw error;
|
|
15891
15958
|
}
|
|
@@ -15935,6 +16002,24 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15935
16002
|
pendingTransientRetry = true;
|
|
15936
16003
|
continue;
|
|
15937
16004
|
}
|
|
16005
|
+
const fitWorkers = memoryRetriesUsed === 0 && failure.kind === "memory_exhaustion" ? captureMemoryRetryWorkers2(error) : void 0;
|
|
16006
|
+
if (options.allowRetry && currentWorkers > 1 && fitWorkers !== void 0) {
|
|
16007
|
+
memoryRetriesUsed++;
|
|
16008
|
+
const nextWorkers2 = Math.min(fitWorkers, currentWorkers - 1);
|
|
16009
|
+
options.log.warn(
|
|
16010
|
+
"[Render] Capture stopped before memory ran out; retrying missing frames with fewer workers.",
|
|
16011
|
+
{
|
|
16012
|
+
fromWorkers: currentWorkers,
|
|
16013
|
+
toWorkers: nextWorkers2,
|
|
16014
|
+
missingFrames: remainingCount,
|
|
16015
|
+
error: failure.message
|
|
16016
|
+
}
|
|
16017
|
+
);
|
|
16018
|
+
currentWorkers = nextWorkers2;
|
|
16019
|
+
missingRanges = remaining;
|
|
16020
|
+
attempt++;
|
|
16021
|
+
continue;
|
|
16022
|
+
}
|
|
15938
16023
|
if (!madeProgress) {
|
|
15939
16024
|
options.log.warn(
|
|
15940
16025
|
"[Render] Capture attempt made no forward progress; composition is likely structurally broken, not retrying.",
|
|
@@ -17044,7 +17129,7 @@ async function executeRenderPipeline(input) {
|
|
|
17044
17129
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
17045
17130
|
code: "start_browsers"
|
|
17046
17131
|
});
|
|
17047
|
-
let resolvedBrowserGpuMode = await
|
|
17132
|
+
let resolvedBrowserGpuMode = await resolveBrowserGpuMode2(cfg.browserGpuMode, {
|
|
17048
17133
|
chromePath: resolveHeadlessShellPath(cfg),
|
|
17049
17134
|
browserTimeout: cfg.browserTimeout
|
|
17050
17135
|
});
|
|
@@ -18264,6 +18349,7 @@ async function executeRenderPipeline(input) {
|
|
|
18264
18349
|
const isParallelStall = isParallelCaptureStallError(err);
|
|
18265
18350
|
const isEncoderDeath = isRetryableEncoderDeath(err);
|
|
18266
18351
|
const isCancellation = err instanceof RenderCancelledError || executionSignal.aborted === true;
|
|
18352
|
+
if (err instanceof CaptureStageError && err.memoryRetryUsed) throw err;
|
|
18267
18353
|
if (!shouldRetryViaPinnedFallback({
|
|
18268
18354
|
isVerifyError,
|
|
18269
18355
|
isDeCaptureError,
|
|
@@ -18407,10 +18493,7 @@ async function executeRenderPipeline(input) {
|
|
|
18407
18493
|
assertNotAborted,
|
|
18408
18494
|
onProgress
|
|
18409
18495
|
};
|
|
18410
|
-
const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames
|
|
18411
|
-
workerCount: capturePlan.workerCount,
|
|
18412
|
-
cpuCount: cpuBudget()
|
|
18413
|
-
}) : null;
|
|
18496
|
+
const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames) : null;
|
|
18414
18497
|
const captureFrameStart = Date.now();
|
|
18415
18498
|
const invokeDiskCapture = (diskPlan) => observeRenderStage(
|
|
18416
18499
|
observability,
|
|
@@ -21462,7 +21545,7 @@ import { join as join49 } from "node:path";
|
|
|
21462
21545
|
import {
|
|
21463
21546
|
assertSwiftShader,
|
|
21464
21547
|
BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
|
|
21465
|
-
classifyCaptureFailure as
|
|
21548
|
+
classifyCaptureFailure as classifyCaptureFailure5,
|
|
21466
21549
|
computeWorkerSizing as computeWorkerSizing2,
|
|
21467
21550
|
closeCaptureSession as closeCaptureSession11,
|
|
21468
21551
|
createCaptureSession as createCaptureSession11,
|
|
@@ -22468,7 +22551,7 @@ function observedChunkCaptureMode(perfs) {
|
|
|
22468
22551
|
}
|
|
22469
22552
|
var PROBE_SELECTED_SCREENSHOT = "[renderChunk] probe selected screenshot capture";
|
|
22470
22553
|
function shouldRetryChunkCaptureWithScreenshot(error) {
|
|
22471
|
-
const failure =
|
|
22554
|
+
const failure = classifyCaptureFailure5(error);
|
|
22472
22555
|
if (failure.kind === "cancelled" || failure.kind === "memory_exhaustion") return false;
|
|
22473
22556
|
return /HeadlessExperimental\.beginFrame/i.test(failure.message) || /beginFrame probe timeout/i.test(failure.message) || failure.message.includes(PROBE_SELECTED_SCREENSHOT) || /Another frame is pending|Frame still pending/i.test(failure.message);
|
|
22474
22557
|
}
|
|
@@ -22959,10 +23042,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22959
23042
|
const captureSession = session;
|
|
22960
23043
|
session = null;
|
|
22961
23044
|
verifyStarted = Date.now();
|
|
22962
|
-
overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, cpuBudget2()) ? encodeWhileCapturing(encodeInput, framesInChunk
|
|
22963
|
-
workerCount: chunkWorkerCount,
|
|
22964
|
-
cpuCount: cpuBudget2()
|
|
22965
|
-
}) : null;
|
|
23045
|
+
overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, cpuBudget2()) ? encodeWhileCapturing(encodeInput, framesInChunk) : null;
|
|
22966
23046
|
await observeRenderStage(
|
|
22967
23047
|
new RenderObservabilityRecorder({ pipelineStartMs: start, log }),
|
|
22968
23048
|
"capture_chunk",
|
|
@@ -23237,7 +23317,8 @@ var SAFE_RENDER_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
23237
23317
|
"VARIABLES_INVALID",
|
|
23238
23318
|
"OUTPUT_DIMENSIONS_MISMATCH",
|
|
23239
23319
|
"COMPOSITION_TOO_LARGE",
|
|
23240
|
-
"COMPILE_TIMEOUT"
|
|
23320
|
+
"COMPILE_TIMEOUT",
|
|
23321
|
+
"COMPOSITION_SCRIPT_FAILED"
|
|
23241
23322
|
]);
|
|
23242
23323
|
function extractSafeRenderErrorCode(error) {
|
|
23243
23324
|
if (typeof error !== "object" || error === null || !("code" in error)) return void 0;
|
|
@@ -24143,7 +24224,11 @@ async function startHealthWorker(options = {}) {
|
|
|
24143
24224
|
);
|
|
24144
24225
|
}
|
|
24145
24226
|
const worker = new Worker4(entry, {
|
|
24146
|
-
workerData: {
|
|
24227
|
+
workerData: {
|
|
24228
|
+
port,
|
|
24229
|
+
hostname: options.hostname || "127.0.0.1",
|
|
24230
|
+
closeAfterMs: options.closeAfterMs
|
|
24231
|
+
},
|
|
24147
24232
|
// Keep stdio inherited so the worker's console logs land in the pod logs
|
|
24148
24233
|
// alongside the main thread's.
|
|
24149
24234
|
stdout: false,
|
|
@@ -24666,6 +24751,14 @@ function createSseProgressReporter(stream, requestId) {
|
|
|
24666
24751
|
});
|
|
24667
24752
|
};
|
|
24668
24753
|
}
|
|
24754
|
+
function renderFailureLogFields(job, safeError) {
|
|
24755
|
+
const failedPhase = job.errorDetails?.observability?.failedPhase;
|
|
24756
|
+
const errorCode = safeError?.errorCode;
|
|
24757
|
+
return {
|
|
24758
|
+
...failedPhase ? { failedPhase } : {},
|
|
24759
|
+
...errorCode ? { errorCode } : {}
|
|
24760
|
+
};
|
|
24761
|
+
}
|
|
24669
24762
|
async function writeRenderStreamFailure(input) {
|
|
24670
24763
|
const { error, job, stream, requestId, startedAtMs, log } = input;
|
|
24671
24764
|
if (error instanceof RenderCancelledError) {
|
|
@@ -24687,7 +24780,8 @@ async function writeRenderStreamFailure(input) {
|
|
|
24687
24780
|
requestId,
|
|
24688
24781
|
elapsedMs,
|
|
24689
24782
|
error: errorMsg,
|
|
24690
|
-
stage: job.currentStage
|
|
24783
|
+
stage: job.currentStage,
|
|
24784
|
+
...renderFailureLogFields(job, safeError)
|
|
24691
24785
|
});
|
|
24692
24786
|
await stream.writeSSE({
|
|
24693
24787
|
data: JSON.stringify({
|
|
@@ -24832,7 +24926,8 @@ function createRenderHandlers(options = {}) {
|
|
|
24832
24926
|
requestId,
|
|
24833
24927
|
durationMs,
|
|
24834
24928
|
error: errorMsg,
|
|
24835
|
-
stage: job.currentStage
|
|
24929
|
+
stage: job.currentStage,
|
|
24930
|
+
...renderFailureLogFields(job, safeError)
|
|
24836
24931
|
});
|
|
24837
24932
|
return c.json(
|
|
24838
24933
|
{
|
|
@@ -25115,7 +25210,7 @@ function startServer(options = {}) {
|
|
|
25115
25210
|
server.setTimeout(0);
|
|
25116
25211
|
server.requestTimeout = 0;
|
|
25117
25212
|
server.keepAliveTimeout = 0;
|
|
25118
|
-
const healthWorkerPromise = process.env.PRODUCER_DISABLE_HEALTH_WORKER === "1" ? Promise.resolve(null) : startHealthWorker({ logger: log }).catch((err) => {
|
|
25213
|
+
const healthWorkerPromise = process.env.PRODUCER_DISABLE_HEALTH_WORKER === "1" ? Promise.resolve(null) : startHealthWorker({ logger: log, hostname }).catch((err) => {
|
|
25119
25214
|
log.error(`[server] health worker failed to start: ${err.message}`);
|
|
25120
25215
|
return null;
|
|
25121
25216
|
});
|