@hyperframes/producer 0.10.2 → 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/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
- classifyCaptureFailure as classifyCaptureFailure3,
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
@@ -2912,6 +2912,9 @@ function buildRenderPerfSummary(input) {
2912
2912
  tmpPeakBytes: input.tmpPeakBytes,
2913
2913
  captureCalibration: input.captureCalibration ? {
2914
2914
  sampledFrames: input.captureCalibration.samples.map((sample) => sample.frameIndex),
2915
+ sampleMs: input.captureCalibration.samples.map(
2916
+ (sample) => Math.round(sample.captureTimeMs)
2917
+ ),
2915
2918
  p95Ms: input.captureCalibration.estimate.p95Ms,
2916
2919
  multiplier: input.captureCalibration.estimate.multiplier,
2917
2920
  reasons: input.captureCalibration.estimate.reasons
@@ -2957,6 +2960,7 @@ function buildRenderPerfSummary(input) {
2957
2960
  // src/services/render/captureStageError.ts
2958
2961
  var CaptureStageError = class extends CaptureFailure {
2959
2962
  browserConsole;
2963
+ memoryRetryUsed = false;
2960
2964
  constructor(input) {
2961
2965
  const classified = classifyCaptureFailure(input.cause);
2962
2966
  super({
@@ -4544,6 +4548,8 @@ import {
4544
4548
  captureFrameToBuffer,
4545
4549
  captureFrameToBufferPipelined,
4546
4550
  captureFramesBatchPipelined,
4551
+ captureMemoryRetryWorkers,
4552
+ classifyCaptureFailure as classifyCaptureFailure2,
4547
4553
  closeCaptureSession,
4548
4554
  createCaptureSession,
4549
4555
  createFrameReorderBuffer,
@@ -4557,8 +4563,7 @@ import {
4557
4563
  recaptureDrawElementFrameForVerify,
4558
4564
  completeDeferredDrawElementInit,
4559
4565
  initializeSession,
4560
- prepareCaptureSessionForReuse,
4561
- spawnStreamingEncoder
4566
+ prepareCaptureSessionForReuse
4562
4567
  } from "@hyperframes/engine";
4563
4568
 
4564
4569
  // src/services/render/stallClock.ts
@@ -4580,6 +4585,17 @@ function createStallClock(now = () => Date.now()) {
4580
4585
  };
4581
4586
  }
4582
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
+
4583
4599
  // src/services/render/stages/captureStreamingStage.ts
4584
4600
  var DEFAULT_CAPTURE_STALL_MS = 6e4;
4585
4601
  var SESSION_INIT_STALL_MS = 3e5;
@@ -4979,7 +4995,7 @@ async function runCaptureStreamingStage(input) {
4979
4995
  let streamingEncoder = null;
4980
4996
  let streamingEncoderClosed = false;
4981
4997
  try {
4982
- streamingEncoder = await spawnStreamingEncoder(
4998
+ streamingEncoder = await spawnCaptureEncoder(
4983
4999
  videoOnlyPath,
4984
5000
  streamingEncoderOptions,
4985
5001
  abortSignal,
@@ -5023,6 +5039,7 @@ async function runCaptureStreamingStage(input) {
5023
5039
  let writtenFrames = 0;
5024
5040
  let resumeFrom = 0;
5025
5041
  let resumes = 0;
5042
+ let memoryRetryUsed = false;
5026
5043
  let workerResults;
5027
5044
  for (; ; ) {
5028
5045
  const parallelReorder = createFrameReorderBuffer(resumeFrom, totalFrames);
@@ -5154,6 +5171,25 @@ async function runCaptureStreamingStage(input) {
5154
5171
  resumes++;
5155
5172
  continue;
5156
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
+ }
5157
5193
  if (parallelDrainError) throw poolFailure(parallelDrainError, probeSession);
5158
5194
  if (stalled && abortSignal?.aborted !== true) {
5159
5195
  throw new ParallelCaptureStallError({
@@ -5484,7 +5520,7 @@ async function captureSegmentToEncoder(ctx, segment) {
5484
5520
  }
5485
5521
  }
5486
5522
  var DEFAULT_DEPS = {
5487
- spawnEncoder: spawnStreamingEncoder2,
5523
+ spawnEncoder: spawnCaptureEncoder,
5488
5524
  captureFrame: captureFrameToBuffer2,
5489
5525
  concat: concatVideoFiles,
5490
5526
  // Through the import binding, not captured: a value captured at module load
@@ -5869,10 +5905,13 @@ import { fpsToNumber as fpsToNumber4 } from "@hyperframes/core";
5869
5905
  import {
5870
5906
  calculateOptimalWorkers,
5871
5907
  captureFrameToBuffer as captureFrameToBuffer3,
5908
+ clearStaticDedupAnchor,
5872
5909
  closeCaptureSession as closeCaptureSession3,
5873
5910
  computeWorkerSizing,
5874
5911
  createCaptureSession as createCaptureSession3,
5875
- initializeSession as initializeSession3
5912
+ initializeSession as initializeSession3,
5913
+ readChromeCpuSeconds,
5914
+ resolveBrowserGpuMode
5876
5915
  } from "@hyperframes/engine";
5877
5916
  var CAPTURE_CALIBRATION_TARGET_MS = 600;
5878
5917
  var MAX_MEASURED_CAPTURE_COST_MULTIPLIER = 8;
@@ -5912,13 +5951,20 @@ function combineCaptureCostEstimates(staticCost, measuredCost) {
5912
5951
  multiplier: measuredCost.multiplier,
5913
5952
  reasons: [...measuredCost.reasons, ...staticCost.reasons],
5914
5953
  p95Ms: measuredCost.p95Ms,
5915
- 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
5916
5958
  };
5917
5959
  }
5918
5960
  function buildHeapAdvisoryWarning(sizing, requestedWorkers) {
5919
5961
  if (requestedWorkers !== void 0 || !sizing.exceedsHeapAdvisory) return void 0;
5920
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}.`;
5921
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
+ }
5922
5968
  function resolveRenderWorkerCount(totalFrames, requestedWorkers, cfg, compiled, log = defaultLogger, measuredCaptureCost, onSizing) {
5923
5969
  const reasonCodes = new Set(compiled.renderModeHints.reasons.map((r) => r.code));
5924
5970
  if (reasonCodes.has("htmlInCanvas")) {
@@ -5940,7 +5986,9 @@ function resolveRenderWorkerCount(totalFrames, requestedWorkers, cfg, compiled,
5940
5986
  );
5941
5987
  const sizing = computeWorkerSizing(totalFrames, requestedWorkers, {
5942
5988
  ...cfg,
5943
- captureCostMultiplier: captureCost.multiplier
5989
+ captureCostMultiplier: captureCost.multiplier,
5990
+ measuredCoresPerWorker: coresToSizeBy(captureCost, cfg.protocolTimeout),
5991
+ measuredBrowserRssMb: captureCost.browserRssMb
5944
5992
  });
5945
5993
  onSizing?.(sizing);
5946
5994
  const workerCount = sizing.workers;
@@ -6039,7 +6087,7 @@ async function measureCaptureCostFromSession(session, totalFrames, fps, log, fir
6039
6087
  }
6040
6088
  } finally {
6041
6089
  session.staticFrames = savedStaticFrames;
6042
- session.lastFrameBuffer = void 0;
6090
+ clearStaticDedupAnchor(session);
6043
6091
  }
6044
6092
  const estimate = estimateMeasuredCaptureCostMultiplier(samples);
6045
6093
  if (estimate.p95Ms !== void 0) {
@@ -6050,17 +6098,28 @@ async function measureCaptureCostFromSession(session, totalFrames, fps, log, fir
6050
6098
  samples
6051
6099
  };
6052
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
+ }
6053
6108
  function logCaptureCalibrationResult(calibration, log) {
6054
6109
  if (calibration.estimate.multiplier > 1) {
6055
6110
  log.warn("[Render] Measured slow frame capture during auto-worker calibration.", {
6056
6111
  multiplier: calibration.estimate.multiplier,
6057
6112
  p95Ms: calibration.estimate.p95Ms,
6058
- sampledFrames: calibration.samples.map((sample) => sample.frameIndex)
6113
+ coresPerWorker: calibration.estimate.coresPerWorker,
6114
+ browserRssMb: calibration.estimate.browserRssMb,
6115
+ sampledFrames: calibration.samples.map((sample) => sample.frameIndex),
6116
+ sampleMs: calibration.samples.map((sample) => Math.round(sample.captureTimeMs))
6059
6117
  });
6060
6118
  } else {
6061
6119
  log.debug("[Render] Auto-worker calibration kept baseline capture cost.", {
6062
6120
  p95Ms: calibration.estimate.p95Ms,
6063
- sampledFrames: calibration.samples.map((sample) => sample.frameIndex)
6121
+ sampledFrames: calibration.samples.map((sample) => sample.frameIndex),
6122
+ sampleMs: calibration.samples.map((sample) => Math.round(sample.captureTimeMs))
6064
6123
  });
6065
6124
  }
6066
6125
  }
@@ -6116,6 +6175,12 @@ async function runCaptureCalibration(input) {
6116
6175
  }
6117
6176
  assertNotAborted();
6118
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();
6119
6184
  const result = await measureCaptureCostFromSession(
6120
6185
  session,
6121
6186
  totalFrames,
@@ -6123,6 +6188,15 @@ async function runCaptureCalibration(input) {
6123
6188
  log,
6124
6189
  job.frameWindow?.startFrame
6125
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
+ }
6126
6200
  logCaptureCalibrationResult(result, log);
6127
6201
  return result;
6128
6202
  };
@@ -13504,7 +13578,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
13504
13578
  import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
13505
13579
  import { join as join30 } from "node:path";
13506
13580
  import {
13507
- classifyCaptureFailure as classifyCaptureFailure2,
13581
+ classifyCaptureFailure as classifyCaptureFailure3,
13508
13582
  frameFileExtension,
13509
13583
  captureFrame,
13510
13584
  captureFrameToBufferPipelined as captureFrameToBufferPipelined2,
@@ -13811,7 +13885,7 @@ function resolveCaptureRange(frameRange, totalFrames) {
13811
13885
  return { rangeStart: frameRange?.startFrame ?? 0, rangeEnd: frameRange?.endFrame ?? totalFrames };
13812
13886
  }
13813
13887
  function planTransientResume(error, ctx) {
13814
- const failure = classifyCaptureFailure2(error, { signal: ctx.abortSignal });
13888
+ const failure = classifyCaptureFailure3(error, { signal: ctx.abortSignal });
13815
13889
  const missing = findMissingFrameRanges(ctx.rangeFrames, ctx.framesDir, ctx.frameExt);
13816
13890
  const [firstMissing] = missing;
13817
13891
  if (!firstMissing) return null;
@@ -13907,8 +13981,7 @@ import {
13907
13981
  cloneCaptureWarnings as cloneCaptureWarnings2,
13908
13982
  createCaptureSession as createCaptureSession7,
13909
13983
  initTransparentBackground as initTransparentBackground2,
13910
- initializeSession as initializeSession7,
13911
- spawnStreamingEncoder as spawnStreamingEncoder3
13984
+ initializeSession as initializeSession7
13912
13985
  } from "@hyperframes/engine";
13913
13986
  import { fpsToNumber as fpsToNumber7 } from "@hyperframes/core";
13914
13987
 
@@ -14699,7 +14772,7 @@ async function runCaptureHdrStage(input) {
14699
14772
  }))
14700
14773
  });
14701
14774
  }
14702
- hdrEncoder = await spawnStreamingEncoder3(
14775
+ hdrEncoder = await spawnCaptureEncoder(
14703
14776
  videoOnlyPath,
14704
14777
  {
14705
14778
  fps: job.config.fps,
@@ -14938,8 +15011,7 @@ import {
14938
15011
  formatFfmpegError,
14939
15012
  MIXED_AUDIO_FILENAME as MIXED_AUDIO_FILENAME2,
14940
15013
  resolveConfig,
14941
- runFfmpeg as runFfmpeg6,
14942
- spawnStreamingEncoder as spawnStreamingEncoder4
15014
+ runFfmpeg as runFfmpeg6
14943
15015
  } from "@hyperframes/engine";
14944
15016
  import {
14945
15017
  clearGifFramesBeforeNext,
@@ -15079,10 +15151,7 @@ function startEncodeProgress(job, stage, onProgress) {
15079
15151
  function resolveEngineConfig(input) {
15080
15152
  return input.engineConfig ?? input.job.config.producerConfig ?? resolveConfig();
15081
15153
  }
15082
- function overlapEncoderThreads(workerCount, cpuCount) {
15083
- return Math.max(1, Math.floor(cpuCount) - Math.floor(workerCount));
15084
- }
15085
- function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
15154
+ function videoEncoderOptions(input, engineCfg) {
15086
15155
  const { job, preset } = input;
15087
15156
  return {
15088
15157
  fps: job.config.fps,
@@ -15102,8 +15171,7 @@ function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
15102
15171
  // keyframes that survive `-f concat -c copy` at assemble time. In-process
15103
15172
  // renders leave both undefined → preserves the existing open-GOP output.
15104
15173
  lockGopForChunkConcat: input.lockGopForChunkConcat === true,
15105
- gopSize: input.gopSize,
15106
- softwareEncoderThreads
15174
+ gopSize: input.gopSize
15107
15175
  };
15108
15176
  }
15109
15177
  function canEncodeWhileCapturing(input, workerCount, cpuCount) {
@@ -15119,9 +15187,8 @@ async function readLandedFrame(workerPath, mergedPath) {
15119
15187
  }
15120
15188
  return readFile2(mergedPath);
15121
15189
  }
15122
- function encodeWhileCapturing(input, totalFrames, captureBudget) {
15190
+ function encodeWhileCapturing(input, totalFrames) {
15123
15191
  const engineCfg = resolveEngineConfig(input);
15124
- const softwareEncoderThreads = captureBudget ? overlapEncoderThreads(captureBudget.workerCount, captureBudget.cpuCount) : void 0;
15125
15192
  const stop = new AbortController();
15126
15193
  const signal = input.abortSignal ? AbortSignal.any([input.abortSignal, stop.signal]) : stop.signal;
15127
15194
  const landed = /* @__PURE__ */ new Map();
@@ -15134,10 +15201,10 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
15134
15201
  };
15135
15202
  signal.addEventListener("abort", nudge, { once: true });
15136
15203
  let reportFed = null;
15137
- const encoder = spawnStreamingEncoder4(
15204
+ const encoder = spawnCaptureEncoder(
15138
15205
  input.videoOnlyPath,
15139
15206
  {
15140
- ...videoEncoderOptions(input, engineCfg, softwareEncoderThreads),
15207
+ ...videoEncoderOptions(input, engineCfg),
15141
15208
  imageFormat: "jpeg"
15142
15209
  },
15143
15210
  signal,
@@ -15518,8 +15585,14 @@ var RenderQualityError = class extends Error {
15518
15585
  );
15519
15586
  this.warnings = warnings;
15520
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
+ }
15521
15592
  }
15522
15593
  warnings;
15594
+ /** Set only when the composition's own script threw: rendering it again fails the same way. */
15595
+ code;
15523
15596
  };
15524
15597
  var MIN_CPUS_TO_CAPTURE_DURING_MIX = 4;
15525
15598
  function applyRenderWarningPolicy(job, captureWarnings, log = defaultLogger) {
@@ -15749,7 +15822,7 @@ function isRecoverableParallelCaptureError(error) {
15749
15822
  if (error instanceof RenderStageStalledError) return true;
15750
15823
  const message = normalizeErrorMessage(error);
15751
15824
  if (!message.includes("[Parallel] Capture failed")) return false;
15752
- const kind = classifyCaptureFailure3(error).kind;
15825
+ const kind = classifyCaptureFailure4(error).kind;
15753
15826
  return kind === "transient_browser" || kind === "protocol_timeout";
15754
15827
  }
15755
15828
  function describeMemoryExhaustion(error, ctx) {
@@ -15781,6 +15854,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
15781
15854
  let attempt = 0;
15782
15855
  let transientRetriesUsed = 0;
15783
15856
  let initializationRetriesUsed = 0;
15857
+ let memoryRetriesUsed = 0;
15784
15858
  let pendingTransientRetry = false;
15785
15859
  const rangeStart = options.frameRangeStart ?? 0;
15786
15860
  while (true) {
@@ -15880,7 +15954,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
15880
15954
  attempt++;
15881
15955
  } catch (caught) {
15882
15956
  const error = attemptSignal?.aborted && !options.abortSignal?.aborted ? attemptSignal.reason : caught;
15883
- const failure = classifyCaptureFailure3(error, { signal: options.abortSignal });
15957
+ const failure = classifyCaptureFailure4(error, { signal: options.abortSignal });
15884
15958
  if (failure.kind === "cancelled") {
15885
15959
  throw error;
15886
15960
  }
@@ -15930,6 +16004,24 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
15930
16004
  pendingTransientRetry = true;
15931
16005
  continue;
15932
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
+ }
15933
16025
  if (!madeProgress) {
15934
16026
  options.log.warn(
15935
16027
  "[Render] Capture attempt made no forward progress; composition is likely structurally broken, not retrying.",
@@ -17039,7 +17131,7 @@ async function executeRenderPipeline(input) {
17039
17131
  updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
17040
17132
  code: "start_browsers"
17041
17133
  });
17042
- let resolvedBrowserGpuMode = await resolveBrowserGpuMode(cfg.browserGpuMode, {
17134
+ let resolvedBrowserGpuMode = await resolveBrowserGpuMode2(cfg.browserGpuMode, {
17043
17135
  chromePath: resolveHeadlessShellPath(cfg),
17044
17136
  browserTimeout: cfg.browserTimeout
17045
17137
  });
@@ -18259,6 +18351,7 @@ async function executeRenderPipeline(input) {
18259
18351
  const isParallelStall = isParallelCaptureStallError(err);
18260
18352
  const isEncoderDeath = isRetryableEncoderDeath(err);
18261
18353
  const isCancellation = err instanceof RenderCancelledError || executionSignal.aborted === true;
18354
+ if (err instanceof CaptureStageError && err.memoryRetryUsed) throw err;
18262
18355
  if (!shouldRetryViaPinnedFallback({
18263
18356
  isVerifyError,
18264
18357
  isDeCaptureError,
@@ -18402,10 +18495,7 @@ async function executeRenderPipeline(input) {
18402
18495
  assertNotAborted,
18403
18496
  onProgress
18404
18497
  };
18405
- const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames, {
18406
- workerCount: capturePlan.workerCount,
18407
- cpuCount: cpuBudget()
18408
- }) : null;
18498
+ const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames) : null;
18409
18499
  const captureFrameStart = Date.now();
18410
18500
  const invokeDiskCapture = (diskPlan) => observeRenderStage(
18411
18501
  observability,
@@ -21457,7 +21547,7 @@ import { join as join49 } from "node:path";
21457
21547
  import {
21458
21548
  assertSwiftShader,
21459
21549
  BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
21460
- classifyCaptureFailure as classifyCaptureFailure4,
21550
+ classifyCaptureFailure as classifyCaptureFailure5,
21461
21551
  computeWorkerSizing as computeWorkerSizing2,
21462
21552
  closeCaptureSession as closeCaptureSession11,
21463
21553
  createCaptureSession as createCaptureSession11,
@@ -22463,7 +22553,7 @@ function observedChunkCaptureMode(perfs) {
22463
22553
  }
22464
22554
  var PROBE_SELECTED_SCREENSHOT = "[renderChunk] probe selected screenshot capture";
22465
22555
  function shouldRetryChunkCaptureWithScreenshot(error) {
22466
- const failure = classifyCaptureFailure4(error);
22556
+ const failure = classifyCaptureFailure5(error);
22467
22557
  if (failure.kind === "cancelled" || failure.kind === "memory_exhaustion") return false;
22468
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);
22469
22559
  }
@@ -22954,10 +23044,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
22954
23044
  const captureSession = session;
22955
23045
  session = null;
22956
23046
  verifyStarted = Date.now();
22957
- overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, cpuBudget2()) ? encodeWhileCapturing(encodeInput, framesInChunk, {
22958
- workerCount: chunkWorkerCount,
22959
- cpuCount: cpuBudget2()
22960
- }) : null;
23047
+ overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, cpuBudget2()) ? encodeWhileCapturing(encodeInput, framesInChunk) : null;
22961
23048
  await observeRenderStage(
22962
23049
  new RenderObservabilityRecorder({ pipelineStartMs: start, log }),
22963
23050
  "capture_chunk",
@@ -23232,7 +23319,8 @@ var SAFE_RENDER_ERROR_CODES = /* @__PURE__ */ new Set([
23232
23319
  "VARIABLES_INVALID",
23233
23320
  "OUTPUT_DIMENSIONS_MISMATCH",
23234
23321
  "COMPOSITION_TOO_LARGE",
23235
- "COMPILE_TIMEOUT"
23322
+ "COMPILE_TIMEOUT",
23323
+ "COMPOSITION_SCRIPT_FAILED"
23236
23324
  ]);
23237
23325
  function extractSafeRenderErrorCode(error) {
23238
23326
  if (typeof error !== "object" || error === null || !("code" in error)) return void 0;
@@ -24661,6 +24749,14 @@ function createSseProgressReporter(stream, requestId) {
24661
24749
  });
24662
24750
  };
24663
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
+ }
24664
24760
  async function writeRenderStreamFailure(input) {
24665
24761
  const { error, job, stream, requestId, startedAtMs, log } = input;
24666
24762
  if (error instanceof RenderCancelledError) {
@@ -24682,7 +24778,8 @@ async function writeRenderStreamFailure(input) {
24682
24778
  requestId,
24683
24779
  elapsedMs,
24684
24780
  error: errorMsg,
24685
- stage: job.currentStage
24781
+ stage: job.currentStage,
24782
+ ...renderFailureLogFields(job, safeError)
24686
24783
  });
24687
24784
  await stream.writeSSE({
24688
24785
  data: JSON.stringify({
@@ -24827,7 +24924,8 @@ function createRenderHandlers(options = {}) {
24827
24924
  requestId,
24828
24925
  durationMs,
24829
24926
  error: errorMsg,
24830
- stage: job.currentStage
24927
+ stage: job.currentStage,
24928
+ ...renderFailureLogFields(job, safeError)
24831
24929
  });
24832
24930
  return c.json(
24833
24931
  {