Skip to content

Commit 8aa52db

Browse files
fix(producer): keep the bounded probe read the stall change dropped
1 parent b0ed2f3 commit 8aa52db

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

‎packages/producer/src/services/renderOrchestrator.ts‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,35 @@ function colorGradingValueHasLut(rawAttributeValue: string): boolean {
18341834
}
18351835
}
18361836

1837+
/** Longest a live probe-page read may hold the render; a busy page otherwise waits out the CDP timeout. */
1838+
export const PROBE_READ_TIMEOUT_MS = 5_000;
1839+
1840+
/** `page.evaluate` that rejects after `PROBE_READ_TIMEOUT_MS`, so callers fall back to their static answer. */
1841+
async function evaluateWithinBound<T>(
1842+
page: Pick<CaptureSession["page"], "evaluate">,
1843+
fn: () => T,
1844+
what: string,
1845+
log: Pick<ProducerLogger, "warn">,
1846+
): Promise<Awaited<T>> {
1847+
let timer: ReturnType<typeof setTimeout> | undefined;
1848+
const timedOut = new Promise<never>((_, reject) => {
1849+
timer = setTimeout(
1850+
() => reject(new Error(`no answer within ${PROBE_READ_TIMEOUT_MS} ms (page busy)`)),
1851+
PROBE_READ_TIMEOUT_MS,
1852+
);
1853+
});
1854+
try {
1855+
return await Promise.race([page.evaluate(fn) as Promise<Awaited<T>>, timedOut]);
1856+
} catch (err) {
1857+
log.warn(`[Render] live ${what} read skipped; using the static answer`, {
1858+
error: err instanceof Error ? err.message : String(err),
1859+
});
1860+
throw err;
1861+
} finally {
1862+
clearTimeout(timer);
1863+
}
1864+
}
1865+
18371866
/**
18381867
* Element count for the short-comp band's gate, WITH PROVENANCE.
18391868
*
@@ -1859,6 +1888,7 @@ function colorGradingValueHasLut(rawAttributeValue: string): boolean {
18591888
export async function resolveCompositionElementCount(
18601889
probeSession: Pick<CaptureSession, "isInitialized" | "page"> | null,
18611890
html: string,
1891+
log: Pick<ProducerLogger, "warn"> = defaultLogger,
18621892
): Promise<{
18631893
count: number;
18641894
source: "live" | "static";
@@ -1879,10 +1909,13 @@ export async function resolveCompositionElementCount(
18791909
}> {
18801910
if (probeSession?.isInitialized) {
18811911
try {
1882-
const liveCount = await probeSession.page.evaluate(
1912+
const liveCount = await evaluateWithinBound(
1913+
probeSession.page,
18831914
// Live HTMLCollection length — avoids materializing a static NodeList
18841915
// on the large-DOM comps this gate exists to catch (review nit).
18851916
() => document.getElementsByTagName("*").length,
1917+
"element count",
1918+
log,
18861919
);
18871920
if (typeof liveCount === "number" && Number.isFinite(liveCount)) {
18881921
return { count: liveCount, source: "live" };
@@ -2021,11 +2054,12 @@ function probeAdaptersUsed(): string[] {
20212054
export async function resolveAdaptersUsed(
20222055
probeSession: Pick<CaptureSession, "isInitialized" | "page"> | null,
20232056
html: string,
2057+
log: Pick<ProducerLogger, "warn"> = defaultLogger,
20242058
): Promise<readonly RuntimeAdapterName[]> {
20252059
const staticAdapters = detectAdaptersStatic(html);
20262060
if (!probeSession?.isInitialized) return staticAdapters;
20272061
try {
2028-
const live = await probeSession.page.evaluate(probeAdaptersUsed);
2062+
const live = await evaluateWithinBound(probeSession.page, probeAdaptersUsed, "adapters", log);
20292063
if (!Array.isArray(live)) return staticAdapters;
20302064
const detected = new Set<string>([...staticAdapters, ...live]);
20312065
return KNOWN_RUNTIME_ADAPTERS.filter((name) => detected.has(name));
@@ -3651,8 +3685,8 @@ async function executeRenderPipeline(input: {
36513685
vfxHostCount,
36523686
vfxCapture,
36533687
vfxTypes,
3654-
} = await resolveCompositionElementCount(probeSession, compiled.html);
3655-
const adaptersUsed = await resolveAdaptersUsed(probeSession, compiled.html);
3688+
} = await resolveCompositionElementCount(probeSession, compiled.html, log);
3689+
const adaptersUsed = await resolveAdaptersUsed(probeSession, compiled.html, log);
36563690
// HF_DE_SHORT_MAX_ELEMENTS=0 is the documented kill switch (symmetric
36573691
// with HF_DE_SHORT_MIN_FRAMES=0, which disables via the predicate's own
36583692
// minFrames > 0 guard). Gated explicitly here too — without it, a fired

0 commit comments

Comments
 (0)