@hyperframes/producer 0.10.4 → 0.10.6
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/dist/distributed.js +63 -32
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +66 -66
- package/dist/index.js +138 -45
- package/dist/public-server.js +135 -39
- 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
|
};
|
|
@@ -13509,7 +13578,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
|
|
|
13509
13578
|
import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
13510
13579
|
import { join as join30 } from "node:path";
|
|
13511
13580
|
import {
|
|
13512
|
-
classifyCaptureFailure as
|
|
13581
|
+
classifyCaptureFailure as classifyCaptureFailure3,
|
|
13513
13582
|
frameFileExtension,
|
|
13514
13583
|
captureFrame,
|
|
13515
13584
|
captureFrameToBufferPipelined as captureFrameToBufferPipelined2,
|
|
@@ -13816,7 +13885,7 @@ function resolveCaptureRange(frameRange, totalFrames) {
|
|
|
13816
13885
|
return { rangeStart: frameRange?.startFrame ?? 0, rangeEnd: frameRange?.endFrame ?? totalFrames };
|
|
13817
13886
|
}
|
|
13818
13887
|
function planTransientResume(error, ctx) {
|
|
13819
|
-
const failure =
|
|
13888
|
+
const failure = classifyCaptureFailure3(error, { signal: ctx.abortSignal });
|
|
13820
13889
|
const missing = findMissingFrameRanges(ctx.rangeFrames, ctx.framesDir, ctx.frameExt);
|
|
13821
13890
|
const [firstMissing] = missing;
|
|
13822
13891
|
if (!firstMissing) return null;
|
|
@@ -13912,8 +13981,7 @@ import {
|
|
|
13912
13981
|
cloneCaptureWarnings as cloneCaptureWarnings2,
|
|
13913
13982
|
createCaptureSession as createCaptureSession7,
|
|
13914
13983
|
initTransparentBackground as initTransparentBackground2,
|
|
13915
|
-
initializeSession as initializeSession7
|
|
13916
|
-
spawnStreamingEncoder as spawnStreamingEncoder3
|
|
13984
|
+
initializeSession as initializeSession7
|
|
13917
13985
|
} from "@hyperframes/engine";
|
|
13918
13986
|
import { fpsToNumber as fpsToNumber7 } from "@hyperframes/core";
|
|
13919
13987
|
|
|
@@ -14704,7 +14772,7 @@ async function runCaptureHdrStage(input) {
|
|
|
14704
14772
|
}))
|
|
14705
14773
|
});
|
|
14706
14774
|
}
|
|
14707
|
-
hdrEncoder = await
|
|
14775
|
+
hdrEncoder = await spawnCaptureEncoder(
|
|
14708
14776
|
videoOnlyPath,
|
|
14709
14777
|
{
|
|
14710
14778
|
fps: job.config.fps,
|
|
@@ -14943,8 +15011,7 @@ import {
|
|
|
14943
15011
|
formatFfmpegError,
|
|
14944
15012
|
MIXED_AUDIO_FILENAME as MIXED_AUDIO_FILENAME2,
|
|
14945
15013
|
resolveConfig,
|
|
14946
|
-
runFfmpeg as runFfmpeg6
|
|
14947
|
-
spawnStreamingEncoder as spawnStreamingEncoder4
|
|
15014
|
+
runFfmpeg as runFfmpeg6
|
|
14948
15015
|
} from "@hyperframes/engine";
|
|
14949
15016
|
import {
|
|
14950
15017
|
clearGifFramesBeforeNext,
|
|
@@ -15084,10 +15151,7 @@ function startEncodeProgress(job, stage, onProgress) {
|
|
|
15084
15151
|
function resolveEngineConfig(input) {
|
|
15085
15152
|
return input.engineConfig ?? input.job.config.producerConfig ?? resolveConfig();
|
|
15086
15153
|
}
|
|
15087
|
-
function
|
|
15088
|
-
return Math.max(1, Math.floor(cpuCount) - Math.floor(workerCount));
|
|
15089
|
-
}
|
|
15090
|
-
function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
|
|
15154
|
+
function videoEncoderOptions(input, engineCfg) {
|
|
15091
15155
|
const { job, preset } = input;
|
|
15092
15156
|
return {
|
|
15093
15157
|
fps: job.config.fps,
|
|
@@ -15107,8 +15171,7 @@ function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
|
|
|
15107
15171
|
// keyframes that survive `-f concat -c copy` at assemble time. In-process
|
|
15108
15172
|
// renders leave both undefined → preserves the existing open-GOP output.
|
|
15109
15173
|
lockGopForChunkConcat: input.lockGopForChunkConcat === true,
|
|
15110
|
-
gopSize: input.gopSize
|
|
15111
|
-
softwareEncoderThreads
|
|
15174
|
+
gopSize: input.gopSize
|
|
15112
15175
|
};
|
|
15113
15176
|
}
|
|
15114
15177
|
function canEncodeWhileCapturing(input, workerCount, cpuCount) {
|
|
@@ -15124,9 +15187,8 @@ async function readLandedFrame(workerPath, mergedPath) {
|
|
|
15124
15187
|
}
|
|
15125
15188
|
return readFile2(mergedPath);
|
|
15126
15189
|
}
|
|
15127
|
-
function encodeWhileCapturing(input, totalFrames
|
|
15190
|
+
function encodeWhileCapturing(input, totalFrames) {
|
|
15128
15191
|
const engineCfg = resolveEngineConfig(input);
|
|
15129
|
-
const softwareEncoderThreads = captureBudget ? overlapEncoderThreads(captureBudget.workerCount, captureBudget.cpuCount) : void 0;
|
|
15130
15192
|
const stop = new AbortController();
|
|
15131
15193
|
const signal = input.abortSignal ? AbortSignal.any([input.abortSignal, stop.signal]) : stop.signal;
|
|
15132
15194
|
const landed = /* @__PURE__ */ new Map();
|
|
@@ -15139,10 +15201,10 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
|
|
|
15139
15201
|
};
|
|
15140
15202
|
signal.addEventListener("abort", nudge, { once: true });
|
|
15141
15203
|
let reportFed = null;
|
|
15142
|
-
const encoder =
|
|
15204
|
+
const encoder = spawnCaptureEncoder(
|
|
15143
15205
|
input.videoOnlyPath,
|
|
15144
15206
|
{
|
|
15145
|
-
...videoEncoderOptions(input, engineCfg
|
|
15207
|
+
...videoEncoderOptions(input, engineCfg),
|
|
15146
15208
|
imageFormat: "jpeg"
|
|
15147
15209
|
},
|
|
15148
15210
|
signal,
|
|
@@ -15523,8 +15585,14 @@ var RenderQualityError = class extends Error {
|
|
|
15523
15585
|
);
|
|
15524
15586
|
this.warnings = warnings;
|
|
15525
15587
|
this.name = "RenderQualityError";
|
|
15588
|
+
const failed = warnings.filter((warning) => warning.code === "sub_timeline_script_failure");
|
|
15589
|
+
if (failed.length > 0 && failed.every((warning) => warning.details?.scriptThrew === true)) {
|
|
15590
|
+
this.code = "COMPOSITION_SCRIPT_FAILED";
|
|
15591
|
+
}
|
|
15526
15592
|
}
|
|
15527
15593
|
warnings;
|
|
15594
|
+
/** Set only when the composition's own script threw: rendering it again fails the same way. */
|
|
15595
|
+
code;
|
|
15528
15596
|
};
|
|
15529
15597
|
var MIN_CPUS_TO_CAPTURE_DURING_MIX = 4;
|
|
15530
15598
|
function applyRenderWarningPolicy(job, captureWarnings, log = defaultLogger) {
|
|
@@ -15754,7 +15822,7 @@ function isRecoverableParallelCaptureError(error) {
|
|
|
15754
15822
|
if (error instanceof RenderStageStalledError) return true;
|
|
15755
15823
|
const message = normalizeErrorMessage(error);
|
|
15756
15824
|
if (!message.includes("[Parallel] Capture failed")) return false;
|
|
15757
|
-
const kind =
|
|
15825
|
+
const kind = classifyCaptureFailure4(error).kind;
|
|
15758
15826
|
return kind === "transient_browser" || kind === "protocol_timeout";
|
|
15759
15827
|
}
|
|
15760
15828
|
function describeMemoryExhaustion(error, ctx) {
|
|
@@ -15786,6 +15854,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15786
15854
|
let attempt = 0;
|
|
15787
15855
|
let transientRetriesUsed = 0;
|
|
15788
15856
|
let initializationRetriesUsed = 0;
|
|
15857
|
+
let memoryRetriesUsed = 0;
|
|
15789
15858
|
let pendingTransientRetry = false;
|
|
15790
15859
|
const rangeStart = options.frameRangeStart ?? 0;
|
|
15791
15860
|
while (true) {
|
|
@@ -15885,7 +15954,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15885
15954
|
attempt++;
|
|
15886
15955
|
} catch (caught) {
|
|
15887
15956
|
const error = attemptSignal?.aborted && !options.abortSignal?.aborted ? attemptSignal.reason : caught;
|
|
15888
|
-
const failure =
|
|
15957
|
+
const failure = classifyCaptureFailure4(error, { signal: options.abortSignal });
|
|
15889
15958
|
if (failure.kind === "cancelled") {
|
|
15890
15959
|
throw error;
|
|
15891
15960
|
}
|
|
@@ -15935,6 +16004,24 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15935
16004
|
pendingTransientRetry = true;
|
|
15936
16005
|
continue;
|
|
15937
16006
|
}
|
|
16007
|
+
const fitWorkers = memoryRetriesUsed === 0 && failure.kind === "memory_exhaustion" ? captureMemoryRetryWorkers2(error) : void 0;
|
|
16008
|
+
if (options.allowRetry && currentWorkers > 1 && fitWorkers !== void 0) {
|
|
16009
|
+
memoryRetriesUsed++;
|
|
16010
|
+
const nextWorkers2 = Math.min(fitWorkers, currentWorkers - 1);
|
|
16011
|
+
options.log.warn(
|
|
16012
|
+
"[Render] Capture stopped before memory ran out; retrying missing frames with fewer workers.",
|
|
16013
|
+
{
|
|
16014
|
+
fromWorkers: currentWorkers,
|
|
16015
|
+
toWorkers: nextWorkers2,
|
|
16016
|
+
missingFrames: remainingCount,
|
|
16017
|
+
error: failure.message
|
|
16018
|
+
}
|
|
16019
|
+
);
|
|
16020
|
+
currentWorkers = nextWorkers2;
|
|
16021
|
+
missingRanges = remaining;
|
|
16022
|
+
attempt++;
|
|
16023
|
+
continue;
|
|
16024
|
+
}
|
|
15938
16025
|
if (!madeProgress) {
|
|
15939
16026
|
options.log.warn(
|
|
15940
16027
|
"[Render] Capture attempt made no forward progress; composition is likely structurally broken, not retrying.",
|
|
@@ -17044,7 +17131,7 @@ async function executeRenderPipeline(input) {
|
|
|
17044
17131
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
17045
17132
|
code: "start_browsers"
|
|
17046
17133
|
});
|
|
17047
|
-
let resolvedBrowserGpuMode = await
|
|
17134
|
+
let resolvedBrowserGpuMode = await resolveBrowserGpuMode2(cfg.browserGpuMode, {
|
|
17048
17135
|
chromePath: resolveHeadlessShellPath(cfg),
|
|
17049
17136
|
browserTimeout: cfg.browserTimeout
|
|
17050
17137
|
});
|
|
@@ -18264,6 +18351,7 @@ async function executeRenderPipeline(input) {
|
|
|
18264
18351
|
const isParallelStall = isParallelCaptureStallError(err);
|
|
18265
18352
|
const isEncoderDeath = isRetryableEncoderDeath(err);
|
|
18266
18353
|
const isCancellation = err instanceof RenderCancelledError || executionSignal.aborted === true;
|
|
18354
|
+
if (err instanceof CaptureStageError && err.memoryRetryUsed) throw err;
|
|
18267
18355
|
if (!shouldRetryViaPinnedFallback({
|
|
18268
18356
|
isVerifyError,
|
|
18269
18357
|
isDeCaptureError,
|
|
@@ -18407,10 +18495,7 @@ async function executeRenderPipeline(input) {
|
|
|
18407
18495
|
assertNotAborted,
|
|
18408
18496
|
onProgress
|
|
18409
18497
|
};
|
|
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;
|
|
18498
|
+
const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames) : null;
|
|
18414
18499
|
const captureFrameStart = Date.now();
|
|
18415
18500
|
const invokeDiskCapture = (diskPlan) => observeRenderStage(
|
|
18416
18501
|
observability,
|
|
@@ -21462,7 +21547,7 @@ import { join as join49 } from "node:path";
|
|
|
21462
21547
|
import {
|
|
21463
21548
|
assertSwiftShader,
|
|
21464
21549
|
BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
|
|
21465
|
-
classifyCaptureFailure as
|
|
21550
|
+
classifyCaptureFailure as classifyCaptureFailure5,
|
|
21466
21551
|
computeWorkerSizing as computeWorkerSizing2,
|
|
21467
21552
|
closeCaptureSession as closeCaptureSession11,
|
|
21468
21553
|
createCaptureSession as createCaptureSession11,
|
|
@@ -22468,7 +22553,7 @@ function observedChunkCaptureMode(perfs) {
|
|
|
22468
22553
|
}
|
|
22469
22554
|
var PROBE_SELECTED_SCREENSHOT = "[renderChunk] probe selected screenshot capture";
|
|
22470
22555
|
function shouldRetryChunkCaptureWithScreenshot(error) {
|
|
22471
|
-
const failure =
|
|
22556
|
+
const failure = classifyCaptureFailure5(error);
|
|
22472
22557
|
if (failure.kind === "cancelled" || failure.kind === "memory_exhaustion") return false;
|
|
22473
22558
|
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
22559
|
}
|
|
@@ -22959,10 +23044,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22959
23044
|
const captureSession = session;
|
|
22960
23045
|
session = null;
|
|
22961
23046
|
verifyStarted = Date.now();
|
|
22962
|
-
overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, cpuBudget2()) ? encodeWhileCapturing(encodeInput, framesInChunk
|
|
22963
|
-
workerCount: chunkWorkerCount,
|
|
22964
|
-
cpuCount: cpuBudget2()
|
|
22965
|
-
}) : null;
|
|
23047
|
+
overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, cpuBudget2()) ? encodeWhileCapturing(encodeInput, framesInChunk) : null;
|
|
22966
23048
|
await observeRenderStage(
|
|
22967
23049
|
new RenderObservabilityRecorder({ pipelineStartMs: start, log }),
|
|
22968
23050
|
"capture_chunk",
|
|
@@ -23237,7 +23319,8 @@ var SAFE_RENDER_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
23237
23319
|
"VARIABLES_INVALID",
|
|
23238
23320
|
"OUTPUT_DIMENSIONS_MISMATCH",
|
|
23239
23321
|
"COMPOSITION_TOO_LARGE",
|
|
23240
|
-
"COMPILE_TIMEOUT"
|
|
23322
|
+
"COMPILE_TIMEOUT",
|
|
23323
|
+
"COMPOSITION_SCRIPT_FAILED"
|
|
23241
23324
|
]);
|
|
23242
23325
|
function extractSafeRenderErrorCode(error) {
|
|
23243
23326
|
if (typeof error !== "object" || error === null || !("code" in error)) return void 0;
|
|
@@ -24666,6 +24749,14 @@ function createSseProgressReporter(stream, requestId) {
|
|
|
24666
24749
|
});
|
|
24667
24750
|
};
|
|
24668
24751
|
}
|
|
24752
|
+
function renderFailureLogFields(job, safeError) {
|
|
24753
|
+
const failedPhase = job.errorDetails?.observability?.failedPhase;
|
|
24754
|
+
const errorCode = safeError?.errorCode;
|
|
24755
|
+
return {
|
|
24756
|
+
...failedPhase ? { failedPhase } : {},
|
|
24757
|
+
...errorCode ? { errorCode } : {}
|
|
24758
|
+
};
|
|
24759
|
+
}
|
|
24669
24760
|
async function writeRenderStreamFailure(input) {
|
|
24670
24761
|
const { error, job, stream, requestId, startedAtMs, log } = input;
|
|
24671
24762
|
if (error instanceof RenderCancelledError) {
|
|
@@ -24687,7 +24778,8 @@ async function writeRenderStreamFailure(input) {
|
|
|
24687
24778
|
requestId,
|
|
24688
24779
|
elapsedMs,
|
|
24689
24780
|
error: errorMsg,
|
|
24690
|
-
stage: job.currentStage
|
|
24781
|
+
stage: job.currentStage,
|
|
24782
|
+
...renderFailureLogFields(job, safeError)
|
|
24691
24783
|
});
|
|
24692
24784
|
await stream.writeSSE({
|
|
24693
24785
|
data: JSON.stringify({
|
|
@@ -24832,7 +24924,8 @@ function createRenderHandlers(options = {}) {
|
|
|
24832
24924
|
requestId,
|
|
24833
24925
|
durationMs,
|
|
24834
24926
|
error: errorMsg,
|
|
24835
|
-
stage: job.currentStage
|
|
24927
|
+
stage: job.currentStage,
|
|
24928
|
+
...renderFailureLogFields(job, safeError)
|
|
24836
24929
|
});
|
|
24837
24930
|
return c.json(
|
|
24838
24931
|
{
|