@hyperframes/producer 0.9.97 → 0.9.98

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.
@@ -1832,6 +1832,19 @@ function captureModeLabel(mode) {
1832
1832
  if (mode === "beginframe") return "BeginFrame";
1833
1833
  return "screenshot";
1834
1834
  }
1835
+ var OPENING_CAPTURE_SESSION = {
1836
+ captureMode: "screenshot",
1837
+ captureStep: "opening the capture session"
1838
+ };
1839
+ async function openCaptureSessionWithinBudget(withinInitBudget, opening) {
1840
+ try {
1841
+ return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
1842
+ } catch (error) {
1843
+ void opening.then(closeCaptureSession).catch(() => {
1844
+ });
1845
+ throw error;
1846
+ }
1847
+ }
1835
1848
  var SequentialCaptureStallError = class extends Error {
1836
1849
  captureMode;
1837
1850
  constructor(session, stallTimeoutMs, frameIndex, totalFrames) {
@@ -1845,20 +1858,44 @@ var SequentialCaptureStallError = class extends Error {
1845
1858
  };
1846
1859
  function raceAgainstStall(promise, deadlineMs, input, signal) {
1847
1860
  return new Promise((resolve11, reject) => {
1848
- const clock = createStallClock();
1849
- const trip = () => reject(
1850
- signal?.aborted ? new Error(
1851
- `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
1852
- ) : new SequentialCaptureStallError(
1853
- input.session,
1854
- input.stallTimeoutMs,
1855
- input.frameIndex,
1856
- input.totalFrames
1857
- )
1861
+ const abortError3 = () => new Error(
1862
+ `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
1858
1863
  );
1864
+ if (signal?.aborted) {
1865
+ promise.catch(() => {
1866
+ });
1867
+ reject(abortError3());
1868
+ return;
1869
+ }
1870
+ const clock = createStallClock();
1871
+ let settled = false;
1872
+ let timer;
1873
+ const cleanup = () => {
1874
+ clearTimeout(timer);
1875
+ signal?.removeEventListener("abort", onAbort);
1876
+ };
1877
+ const onAbort = () => {
1878
+ if (settled) return;
1879
+ settled = true;
1880
+ cleanup();
1881
+ reject(abortError3());
1882
+ };
1883
+ const trip = () => {
1884
+ if (settled) return;
1885
+ settled = true;
1886
+ cleanup();
1887
+ reject(
1888
+ signal?.aborted ? abortError3() : new SequentialCaptureStallError(
1889
+ input.session,
1890
+ input.stallTimeoutMs,
1891
+ input.frameIndex,
1892
+ input.totalFrames
1893
+ )
1894
+ );
1895
+ };
1896
+ signal?.addEventListener("abort", onAbort, { once: true });
1859
1897
  const deadline = Math.max(0, deadlineMs);
1860
1898
  let wait = Math.min(deadline, DE_STALL_POLL_MS);
1861
- let timer;
1862
1899
  const look = () => {
1863
1900
  const idle = clock.idle(wait);
1864
1901
  if (idle >= deadline) return trip();
@@ -1868,11 +1905,15 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
1868
1905
  timer = setTimeout(look, wait);
1869
1906
  promise.then(
1870
1907
  (value) => {
1871
- clearTimeout(timer);
1908
+ if (settled) return;
1909
+ settled = true;
1910
+ cleanup();
1872
1911
  resolve11(value);
1873
1912
  },
1874
1913
  (error) => {
1875
- clearTimeout(timer);
1914
+ if (settled) return;
1915
+ settled = true;
1916
+ cleanup();
1876
1917
  reject(error);
1877
1918
  }
1878
1919
  );
@@ -8637,25 +8678,26 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
8637
8678
  assertNotAborted();
8638
8679
  attempt?.throwIfAborted();
8639
8680
  };
8681
+ const attemptSignal = combineAbortSignals(abortSignal, attempt);
8682
+ const initBudget = { frameIndex: resumeFrom, totalFrames, abortSignal: attemptSignal };
8640
8683
  const videoInjector = createRenderVideoFrameInjector();
8641
- const session = probeSession ?? await createCaptureSession5(
8642
- fileServer.url,
8684
+ const session = probeSession ?? await openSequentialDiskSession({
8685
+ assertAttemptActive,
8686
+ initBudget,
8687
+ fileServerUrl: fileServer.url,
8643
8688
  framesDir,
8644
8689
  captureOptions,
8645
8690
  videoInjector,
8646
- captureCfg
8647
- );
8691
+ captureCfg,
8692
+ attemptSignal
8693
+ });
8648
8694
  captureBeyondViewport = session.options.captureBeyondViewport;
8649
8695
  try {
8650
8696
  if (probeSession) {
8651
8697
  await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
8652
8698
  probeSession = null;
8653
8699
  }
8654
- await ensureSessionReady(session, {
8655
- frameIndex: resumeFrom,
8656
- totalFrames,
8657
- abortSignal: input.abortSignal
8658
- });
8700
+ await ensureSessionReady(session, initBudget);
8659
8701
  assertAttemptActive();
8660
8702
  lastBrowserConsole = session.browserConsoleBuffer;
8661
8703
  await captureSessionFrames(session, {
@@ -8707,9 +8749,26 @@ function planTransientResume(error, ctx) {
8707
8749
  if (!firstMissing) return null;
8708
8750
  return isTransientCaptureRetryEligible(failure.kind, missing, ctx.retriesUsed) ? firstMissing.startFrame : null;
8709
8751
  }
8752
+ function combineAbortSignals(first, second) {
8753
+ if (first && second) return AbortSignal.any([first, second]);
8754
+ return second ?? first;
8755
+ }
8756
+ async function openSequentialDiskSession(args) {
8757
+ args.assertAttemptActive();
8758
+ return openCaptureSessionWithinBudget(
8759
+ createSessionInitBudget(args.initBudget),
8760
+ createCaptureSession5(
8761
+ args.fileServerUrl,
8762
+ args.framesDir,
8763
+ args.captureOptions,
8764
+ args.videoInjector,
8765
+ { ...args.captureCfg, signal: args.attemptSignal }
8766
+ )
8767
+ );
8768
+ }
8710
8769
  async function ensureSessionReady(session, budget) {
8711
8770
  if (!session.isInitialized) {
8712
- await initializeSession5(session);
8771
+ await createSessionInitBudget(budget)(initializeSession5(session), session);
8713
8772
  return;
8714
8773
  }
8715
8774
  if (process.env.PRODUCER_EXPERIMENTAL_FAST_CAPTURE === "true") {
package/dist/index.js CHANGED
@@ -4685,6 +4685,15 @@ var OPENING_CAPTURE_SESSION = {
4685
4685
  captureMode: "screenshot",
4686
4686
  captureStep: "opening the capture session"
4687
4687
  };
4688
+ async function openCaptureSessionWithinBudget(withinInitBudget, opening) {
4689
+ try {
4690
+ return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
4691
+ } catch (error) {
4692
+ void opening.then(closeCaptureSession).catch(() => {
4693
+ });
4694
+ throw error;
4695
+ }
4696
+ }
4688
4697
  var OPENING_RISK_SESSION = {
4689
4698
  captureMode: "screenshot",
4690
4699
  captureStep: "opening the screenshot session for effect frames"
@@ -4702,20 +4711,44 @@ var SequentialCaptureStallError = class extends Error {
4702
4711
  };
4703
4712
  function raceAgainstStall(promise, deadlineMs, input, signal) {
4704
4713
  return new Promise((resolve15, reject) => {
4705
- const clock = createStallClock();
4706
- const trip = () => reject(
4707
- signal?.aborted ? new Error(
4708
- `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4709
- ) : new SequentialCaptureStallError(
4710
- input.session,
4711
- input.stallTimeoutMs,
4712
- input.frameIndex,
4713
- input.totalFrames
4714
- )
4714
+ const abortError3 = () => new Error(
4715
+ `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4715
4716
  );
4717
+ if (signal?.aborted) {
4718
+ promise.catch(() => {
4719
+ });
4720
+ reject(abortError3());
4721
+ return;
4722
+ }
4723
+ const clock = createStallClock();
4724
+ let settled = false;
4725
+ let timer;
4726
+ const cleanup = () => {
4727
+ clearTimeout(timer);
4728
+ signal?.removeEventListener("abort", onAbort);
4729
+ };
4730
+ const onAbort = () => {
4731
+ if (settled) return;
4732
+ settled = true;
4733
+ cleanup();
4734
+ reject(abortError3());
4735
+ };
4736
+ const trip = () => {
4737
+ if (settled) return;
4738
+ settled = true;
4739
+ cleanup();
4740
+ reject(
4741
+ signal?.aborted ? abortError3() : new SequentialCaptureStallError(
4742
+ input.session,
4743
+ input.stallTimeoutMs,
4744
+ input.frameIndex,
4745
+ input.totalFrames
4746
+ )
4747
+ );
4748
+ };
4749
+ signal?.addEventListener("abort", onAbort, { once: true });
4716
4750
  const deadline = Math.max(0, deadlineMs);
4717
4751
  let wait = Math.min(deadline, DE_STALL_POLL_MS);
4718
- let timer;
4719
4752
  const look = () => {
4720
4753
  const idle = clock.idle(wait);
4721
4754
  if (idle >= deadline) return trip();
@@ -4725,11 +4758,15 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
4725
4758
  timer = setTimeout(look, wait);
4726
4759
  promise.then(
4727
4760
  (value) => {
4728
- clearTimeout(timer);
4761
+ if (settled) return;
4762
+ settled = true;
4763
+ cleanup();
4729
4764
  resolve15(value);
4730
4765
  },
4731
4766
  (error) => {
4732
- clearTimeout(timer);
4767
+ if (settled) return;
4768
+ settled = true;
4769
+ cleanup();
4733
4770
  reject(error);
4734
4771
  }
4735
4772
  );
@@ -5228,20 +5265,14 @@ async function runCaptureStreamingStage(input) {
5228
5265
  abortSignal
5229
5266
  });
5230
5267
  const openSession = async () => {
5231
- const opening = createCaptureSession(
5232
- fileServer.url,
5233
- framesDir,
5234
- buildCaptureOptions(),
5235
- videoInjector,
5236
- captureCfg
5268
+ assertNotAborted();
5269
+ return openCaptureSessionWithinBudget(
5270
+ withinInitBudget,
5271
+ createCaptureSession(fileServer.url, framesDir, buildCaptureOptions(), videoInjector, {
5272
+ ...captureCfg,
5273
+ signal: abortSignal
5274
+ })
5237
5275
  );
5238
- try {
5239
- return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
5240
- } catch (error) {
5241
- void opening.then(closeCaptureSession, () => {
5242
- });
5243
- throw error;
5244
- }
5245
5276
  };
5246
5277
  const session = probeSession ?? await openSession();
5247
5278
  captureBeyondViewport = session.options.captureBeyondViewport;
@@ -5261,7 +5292,8 @@ async function runCaptureStreamingStage(input) {
5261
5292
  ...captureCfg,
5262
5293
  useDrawElement: false,
5263
5294
  staticFrameDedup: false,
5264
- enableBrowserPool: false
5295
+ enableBrowserPool: false,
5296
+ signal: abortSignal
5265
5297
  }
5266
5298
  );
5267
5299
  if (attemptClosed) {
@@ -5424,17 +5456,23 @@ async function captureSegmentFrames(ctx, segment, encoder) {
5424
5456
  for (let i = segment.startFrame; i < segment.endFrame; i++) {
5425
5457
  ctx.assertNotAborted();
5426
5458
  const time = i * ctx.job.config.fps.den / ctx.job.config.fps.num;
5427
- const { buffer } = await raceAgainstStall(
5428
- ctx.captureFrame(ctx.session, i, time),
5429
- ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5430
- {
5431
- session: ctx.session,
5432
- frameIndex: i,
5433
- totalFrames: ctx.totalFrames,
5434
- stallTimeoutMs: ctx.stallTimeoutMs
5435
- },
5436
- ctx.abortSignal
5437
- );
5459
+ let buffer;
5460
+ try {
5461
+ ({ buffer } = await raceAgainstStall(
5462
+ ctx.captureFrame(ctx.session, i, time),
5463
+ ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5464
+ {
5465
+ session: ctx.session,
5466
+ frameIndex: i,
5467
+ totalFrames: ctx.totalFrames,
5468
+ stallTimeoutMs: ctx.stallTimeoutMs
5469
+ },
5470
+ ctx.abortSignal
5471
+ ));
5472
+ } catch (error) {
5473
+ if (ctx.abortSignal?.aborted) ctx.assertNotAborted();
5474
+ throw error;
5475
+ }
5438
5476
  await verifyDrawElementSample(ctx.session, i, buffer, {
5439
5477
  log: ctx.log,
5440
5478
  verifyMinDb: ctx.verifyMinDb
@@ -13523,25 +13561,26 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
13523
13561
  assertNotAborted();
13524
13562
  attempt?.throwIfAborted();
13525
13563
  };
13564
+ const attemptSignal = combineAbortSignals(abortSignal, attempt);
13565
+ const initBudget = { frameIndex: resumeFrom, totalFrames, abortSignal: attemptSignal };
13526
13566
  const videoInjector = createRenderVideoFrameInjector();
13527
- const session = probeSession ?? await createCaptureSession5(
13528
- fileServer.url,
13567
+ const session = probeSession ?? await openSequentialDiskSession({
13568
+ assertAttemptActive,
13569
+ initBudget,
13570
+ fileServerUrl: fileServer.url,
13529
13571
  framesDir,
13530
13572
  captureOptions,
13531
13573
  videoInjector,
13532
- captureCfg
13533
- );
13574
+ captureCfg,
13575
+ attemptSignal
13576
+ });
13534
13577
  captureBeyondViewport = session.options.captureBeyondViewport;
13535
13578
  try {
13536
13579
  if (probeSession) {
13537
13580
  await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
13538
13581
  probeSession = null;
13539
13582
  }
13540
- await ensureSessionReady(session, {
13541
- frameIndex: resumeFrom,
13542
- totalFrames,
13543
- abortSignal: input.abortSignal
13544
- });
13583
+ await ensureSessionReady(session, initBudget);
13545
13584
  assertAttemptActive();
13546
13585
  lastBrowserConsole = session.browserConsoleBuffer;
13547
13586
  await captureSessionFrames(session, {
@@ -13593,9 +13632,26 @@ function planTransientResume(error, ctx) {
13593
13632
  if (!firstMissing) return null;
13594
13633
  return isTransientCaptureRetryEligible(failure.kind, missing, ctx.retriesUsed) ? firstMissing.startFrame : null;
13595
13634
  }
13635
+ function combineAbortSignals(first, second) {
13636
+ if (first && second) return AbortSignal.any([first, second]);
13637
+ return second ?? first;
13638
+ }
13639
+ async function openSequentialDiskSession(args) {
13640
+ args.assertAttemptActive();
13641
+ return openCaptureSessionWithinBudget(
13642
+ createSessionInitBudget(args.initBudget),
13643
+ createCaptureSession5(
13644
+ args.fileServerUrl,
13645
+ args.framesDir,
13646
+ args.captureOptions,
13647
+ args.videoInjector,
13648
+ { ...args.captureCfg, signal: args.attemptSignal }
13649
+ )
13650
+ );
13651
+ }
13596
13652
  async function ensureSessionReady(session, budget) {
13597
13653
  if (!session.isInitialized) {
13598
- await initializeSession5(session);
13654
+ await createSessionInitBudget(budget)(initializeSession5(session), session);
13599
13655
  return;
13600
13656
  }
13601
13657
  if (process.env.PRODUCER_EXPERIMENTAL_FAST_CAPTURE === "true") {
@@ -14397,12 +14453,17 @@ async function runCaptureHdrStage(input) {
14397
14453
  projectDir,
14398
14454
  compiledDir
14399
14455
  });
14400
- const domSession = await createCaptureSession7(
14401
- fileServer.url,
14402
- framesDir,
14403
- buildCaptureOptions(),
14404
- createRenderVideoFrameInjector(),
14405
- hdrCfg
14456
+ assertNotAborted();
14457
+ const withinInitBudget = createSessionInitBudget({ frameIndex: 0, totalFrames, abortSignal });
14458
+ const domSession = await openCaptureSessionWithinBudget(
14459
+ withinInitBudget,
14460
+ createCaptureSession7(
14461
+ fileServer.url,
14462
+ framesDir,
14463
+ buildCaptureOptions(),
14464
+ createRenderVideoFrameInjector(),
14465
+ { ...hdrCfg, signal: abortSignal }
14466
+ )
14406
14467
  );
14407
14468
  let hdrEncoder = null;
14408
14469
  let hdrEncoderClosed = false;
@@ -14411,7 +14472,7 @@ async function runCaptureHdrStage(input) {
14411
14472
  let releaseHdrImageReservation = null;
14412
14473
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
14413
14474
  try {
14414
- await initializeSession7(domSession);
14475
+ await withinInitBudget(initializeSession7(domSession), domSession);
14415
14476
  assertNotAborted();
14416
14477
  lastBrowserConsole = domSession.browserConsoleBuffer;
14417
14478
  await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
@@ -16367,6 +16428,9 @@ async function executeRenderPipeline(input) {
16367
16428
  memSampler = createMemorySampler();
16368
16429
  const assertNotAborted = () => {
16369
16430
  execution.assertActive(() => new RenderCancelledError("render_cancelled"));
16431
+ if (executionSignal.aborted) {
16432
+ throw tooSlowError ?? audioFailure ?? new RenderCancelledError("render_cancelled");
16433
+ }
16370
16434
  };
16371
16435
  job.startedAt = /* @__PURE__ */ new Date();
16372
16436
  assertNotAborted();
@@ -4723,6 +4723,15 @@ var OPENING_CAPTURE_SESSION = {
4723
4723
  captureMode: "screenshot",
4724
4724
  captureStep: "opening the capture session"
4725
4725
  };
4726
+ async function openCaptureSessionWithinBudget(withinInitBudget, opening) {
4727
+ try {
4728
+ return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
4729
+ } catch (error) {
4730
+ void opening.then(closeCaptureSession).catch(() => {
4731
+ });
4732
+ throw error;
4733
+ }
4734
+ }
4726
4735
  var OPENING_RISK_SESSION = {
4727
4736
  captureMode: "screenshot",
4728
4737
  captureStep: "opening the screenshot session for effect frames"
@@ -4740,20 +4749,44 @@ var SequentialCaptureStallError = class extends Error {
4740
4749
  };
4741
4750
  function raceAgainstStall(promise, deadlineMs, input, signal) {
4742
4751
  return new Promise((resolve13, reject) => {
4743
- const clock = createStallClock();
4744
- const trip = () => reject(
4745
- signal?.aborted ? new Error(
4746
- `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4747
- ) : new SequentialCaptureStallError(
4748
- input.session,
4749
- input.stallTimeoutMs,
4750
- input.frameIndex,
4751
- input.totalFrames
4752
- )
4752
+ const abortError3 = () => new Error(
4753
+ `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4753
4754
  );
4755
+ if (signal?.aborted) {
4756
+ promise.catch(() => {
4757
+ });
4758
+ reject(abortError3());
4759
+ return;
4760
+ }
4761
+ const clock = createStallClock();
4762
+ let settled = false;
4763
+ let timer;
4764
+ const cleanup = () => {
4765
+ clearTimeout(timer);
4766
+ signal?.removeEventListener("abort", onAbort);
4767
+ };
4768
+ const onAbort = () => {
4769
+ if (settled) return;
4770
+ settled = true;
4771
+ cleanup();
4772
+ reject(abortError3());
4773
+ };
4774
+ const trip = () => {
4775
+ if (settled) return;
4776
+ settled = true;
4777
+ cleanup();
4778
+ reject(
4779
+ signal?.aborted ? abortError3() : new SequentialCaptureStallError(
4780
+ input.session,
4781
+ input.stallTimeoutMs,
4782
+ input.frameIndex,
4783
+ input.totalFrames
4784
+ )
4785
+ );
4786
+ };
4787
+ signal?.addEventListener("abort", onAbort, { once: true });
4754
4788
  const deadline = Math.max(0, deadlineMs);
4755
4789
  let wait = Math.min(deadline, DE_STALL_POLL_MS);
4756
- let timer;
4757
4790
  const look = () => {
4758
4791
  const idle = clock.idle(wait);
4759
4792
  if (idle >= deadline) return trip();
@@ -4763,11 +4796,15 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
4763
4796
  timer = setTimeout(look, wait);
4764
4797
  promise.then(
4765
4798
  (value) => {
4766
- clearTimeout(timer);
4799
+ if (settled) return;
4800
+ settled = true;
4801
+ cleanup();
4767
4802
  resolve13(value);
4768
4803
  },
4769
4804
  (error) => {
4770
- clearTimeout(timer);
4805
+ if (settled) return;
4806
+ settled = true;
4807
+ cleanup();
4771
4808
  reject(error);
4772
4809
  }
4773
4810
  );
@@ -5266,20 +5303,14 @@ async function runCaptureStreamingStage(input) {
5266
5303
  abortSignal
5267
5304
  });
5268
5305
  const openSession = async () => {
5269
- const opening = createCaptureSession(
5270
- fileServer.url,
5271
- framesDir,
5272
- buildCaptureOptions(),
5273
- videoInjector,
5274
- captureCfg
5306
+ assertNotAborted();
5307
+ return openCaptureSessionWithinBudget(
5308
+ withinInitBudget,
5309
+ createCaptureSession(fileServer.url, framesDir, buildCaptureOptions(), videoInjector, {
5310
+ ...captureCfg,
5311
+ signal: abortSignal
5312
+ })
5275
5313
  );
5276
- try {
5277
- return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
5278
- } catch (error) {
5279
- void opening.then(closeCaptureSession, () => {
5280
- });
5281
- throw error;
5282
- }
5283
5314
  };
5284
5315
  const session = probeSession ?? await openSession();
5285
5316
  captureBeyondViewport = session.options.captureBeyondViewport;
@@ -5299,7 +5330,8 @@ async function runCaptureStreamingStage(input) {
5299
5330
  ...captureCfg,
5300
5331
  useDrawElement: false,
5301
5332
  staticFrameDedup: false,
5302
- enableBrowserPool: false
5333
+ enableBrowserPool: false,
5334
+ signal: abortSignal
5303
5335
  }
5304
5336
  );
5305
5337
  if (attemptClosed) {
@@ -5462,17 +5494,23 @@ async function captureSegmentFrames(ctx, segment, encoder) {
5462
5494
  for (let i = segment.startFrame; i < segment.endFrame; i++) {
5463
5495
  ctx.assertNotAborted();
5464
5496
  const time = i * ctx.job.config.fps.den / ctx.job.config.fps.num;
5465
- const { buffer } = await raceAgainstStall(
5466
- ctx.captureFrame(ctx.session, i, time),
5467
- ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5468
- {
5469
- session: ctx.session,
5470
- frameIndex: i,
5471
- totalFrames: ctx.totalFrames,
5472
- stallTimeoutMs: ctx.stallTimeoutMs
5473
- },
5474
- ctx.abortSignal
5475
- );
5497
+ let buffer;
5498
+ try {
5499
+ ({ buffer } = await raceAgainstStall(
5500
+ ctx.captureFrame(ctx.session, i, time),
5501
+ ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5502
+ {
5503
+ session: ctx.session,
5504
+ frameIndex: i,
5505
+ totalFrames: ctx.totalFrames,
5506
+ stallTimeoutMs: ctx.stallTimeoutMs
5507
+ },
5508
+ ctx.abortSignal
5509
+ ));
5510
+ } catch (error) {
5511
+ if (ctx.abortSignal?.aborted) ctx.assertNotAborted();
5512
+ throw error;
5513
+ }
5476
5514
  await verifyDrawElementSample(ctx.session, i, buffer, {
5477
5515
  log: ctx.log,
5478
5516
  verifyMinDb: ctx.verifyMinDb
@@ -13505,25 +13543,26 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
13505
13543
  assertNotAborted();
13506
13544
  attempt?.throwIfAborted();
13507
13545
  };
13546
+ const attemptSignal = combineAbortSignals(abortSignal, attempt);
13547
+ const initBudget = { frameIndex: resumeFrom, totalFrames, abortSignal: attemptSignal };
13508
13548
  const videoInjector = createRenderVideoFrameInjector();
13509
- const session = probeSession ?? await createCaptureSession5(
13510
- fileServer.url,
13549
+ const session = probeSession ?? await openSequentialDiskSession({
13550
+ assertAttemptActive,
13551
+ initBudget,
13552
+ fileServerUrl: fileServer.url,
13511
13553
  framesDir,
13512
13554
  captureOptions,
13513
13555
  videoInjector,
13514
- captureCfg
13515
- );
13556
+ captureCfg,
13557
+ attemptSignal
13558
+ });
13516
13559
  captureBeyondViewport = session.options.captureBeyondViewport;
13517
13560
  try {
13518
13561
  if (probeSession) {
13519
13562
  await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
13520
13563
  probeSession = null;
13521
13564
  }
13522
- await ensureSessionReady(session, {
13523
- frameIndex: resumeFrom,
13524
- totalFrames,
13525
- abortSignal: input.abortSignal
13526
- });
13565
+ await ensureSessionReady(session, initBudget);
13527
13566
  assertAttemptActive();
13528
13567
  lastBrowserConsole = session.browserConsoleBuffer;
13529
13568
  await captureSessionFrames(session, {
@@ -13575,9 +13614,26 @@ function planTransientResume(error, ctx) {
13575
13614
  if (!firstMissing) return null;
13576
13615
  return isTransientCaptureRetryEligible(failure.kind, missing, ctx.retriesUsed) ? firstMissing.startFrame : null;
13577
13616
  }
13617
+ function combineAbortSignals(first, second) {
13618
+ if (first && second) return AbortSignal.any([first, second]);
13619
+ return second ?? first;
13620
+ }
13621
+ async function openSequentialDiskSession(args) {
13622
+ args.assertAttemptActive();
13623
+ return openCaptureSessionWithinBudget(
13624
+ createSessionInitBudget(args.initBudget),
13625
+ createCaptureSession5(
13626
+ args.fileServerUrl,
13627
+ args.framesDir,
13628
+ args.captureOptions,
13629
+ args.videoInjector,
13630
+ { ...args.captureCfg, signal: args.attemptSignal }
13631
+ )
13632
+ );
13633
+ }
13578
13634
  async function ensureSessionReady(session, budget) {
13579
13635
  if (!session.isInitialized) {
13580
- await initializeSession5(session);
13636
+ await createSessionInitBudget(budget)(initializeSession5(session), session);
13581
13637
  return;
13582
13638
  }
13583
13639
  if (process.env.PRODUCER_EXPERIMENTAL_FAST_CAPTURE === "true") {
@@ -14379,12 +14435,17 @@ async function runCaptureHdrStage(input) {
14379
14435
  projectDir,
14380
14436
  compiledDir
14381
14437
  });
14382
- const domSession = await createCaptureSession7(
14383
- fileServer.url,
14384
- framesDir,
14385
- buildCaptureOptions(),
14386
- createRenderVideoFrameInjector(),
14387
- hdrCfg
14438
+ assertNotAborted();
14439
+ const withinInitBudget = createSessionInitBudget({ frameIndex: 0, totalFrames, abortSignal });
14440
+ const domSession = await openCaptureSessionWithinBudget(
14441
+ withinInitBudget,
14442
+ createCaptureSession7(
14443
+ fileServer.url,
14444
+ framesDir,
14445
+ buildCaptureOptions(),
14446
+ createRenderVideoFrameInjector(),
14447
+ { ...hdrCfg, signal: abortSignal }
14448
+ )
14388
14449
  );
14389
14450
  let hdrEncoder = null;
14390
14451
  let hdrEncoderClosed = false;
@@ -14393,7 +14454,7 @@ async function runCaptureHdrStage(input) {
14393
14454
  let releaseHdrImageReservation = null;
14394
14455
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
14395
14456
  try {
14396
- await initializeSession7(domSession);
14457
+ await withinInitBudget(initializeSession7(domSession), domSession);
14397
14458
  assertNotAborted();
14398
14459
  lastBrowserConsole = domSession.browserConsoleBuffer;
14399
14460
  await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
@@ -16349,6 +16410,9 @@ async function executeRenderPipeline(input) {
16349
16410
  memSampler = createMemorySampler();
16350
16411
  const assertNotAborted = () => {
16351
16412
  execution.assertActive(() => new RenderCancelledError("render_cancelled"));
16413
+ if (executionSignal.aborted) {
16414
+ throw tooSlowError ?? audioFailure ?? new RenderCancelledError("render_cancelled");
16415
+ }
16352
16416
  };
16353
16417
  job.startedAt = /* @__PURE__ */ new Date();
16354
16418
  assertNotAborted();
@@ -49,6 +49,7 @@ export type StalledSession = {
49
49
  captureStep?: string;
50
50
  };
51
51
  export declare const OPENING_CAPTURE_SESSION: StalledSession;
52
+ export declare function openCaptureSessionWithinBudget(withinInitBudget: ReturnType<typeof createSessionInitBudget>, opening: Promise<CaptureSession>): Promise<CaptureSession>;
52
53
  export declare function raceAgainstStall<T>(promise: Promise<T>, deadlineMs: number, input: {
53
54
  session: StalledSession;
54
55
  frameIndex: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.97",
3
+ "version": "0.9.98",
4
4
  "description": "HTML-to-video rendering engine using Chrome's BeginFrame API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,11 +35,11 @@
35
35
  "postcss": "^8.4.0",
36
36
  "puppeteer": "~25.13.0",
37
37
  "puppeteer-core": "^25.13.0",
38
- "@hyperframes/engine": "0.9.97",
39
- "@hyperframes/parsers": "0.9.97",
40
- "@hyperframes/core": "0.9.97",
41
- "@hyperframes/studio-server": "0.9.97",
42
- "@hyperframes/lint": "0.9.97"
38
+ "@hyperframes/core": "0.9.98",
39
+ "@hyperframes/lint": "0.9.98",
40
+ "@hyperframes/parsers": "0.9.98",
41
+ "@hyperframes/studio-server": "0.9.98",
42
+ "@hyperframes/engine": "0.9.98"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^25.0.10",
@@ -48,7 +48,7 @@
48
48
  "tsx": "^4.21.0",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^4.1.12",
51
- "@hyperframes/aws-lambda": "0.9.97"
51
+ "@hyperframes/aws-lambda": "0.9.98"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"