Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(embed-doctor): tell a page too busy to answer apart from a page that went away
nirholasc124790b4dd9
diff --git a/api/_lib/embed-doctor.js b/api/_lib/embed-doctor.jsindex bb2085cf4..f7356b2ce 100644--- a/api/_lib/embed-doctor.js+++ b/api/_lib/embed-doctor.js@@ -285,10 +285,10 @@ export function analyze(obs) {unknown('page_not_inspected','The page could not be inspected in the time available',- obs.timedOut+ obs.probeTimedOut? 'The page was still busy when the time budget ran out, so its contents were never read. A page that keeps the browser occupied this long usually has heavy scripts of its own running ahead of the embed.': 'The browser closed the page before its contents could be read, so nothing below the loader is knowable.',- { timedOut: !!obs.timedOut },+ { timedOut: !!obs.probeTimedOut },),);return { verdict: verdictFor(findings), findings: rank(findings), summary: summarize(findings, obs) };@@ -1001,10 +1001,14 @@ async function harvest(page, { recorders, response, bootMs, platformOrigin, scre// `page.evaluate` has no deadline of its own. Giving up on it is "we could// not look", not "there is nothing there", and the difference has to survive// into the report: honesty rule 1.+ let probeTimedOut = false;const probed = await withDeadline(page.evaluate(inPageProbe, EMBED_SELECTOR, SOURCE_ATTRIBUTES),left(PROBE_MAX_MS),null,+ () => {+ probeTimedOut = true;+ },);const probeFailed = probed === null;const probe = probed || {@@ -1062,6 +1066,7 @@ async function harvest(page, { recorders, response, bootMs, platformOrigin, screagent,screenshot: shot,probeFailed,+ probeTimedOut,};}@@ -1100,11 +1105,18 @@ function pageDeadline(budgetMs) {* when the deadline passes or the call rejects. The abandoned call is cancelled* for real when the caller closes the page in its `finally`, so nothing is left* running behind the response.+ *+ * `onTimeout` separates the two ways a step gives up: a page too busy to answer+ * in time, and a page that went away. The report words them differently, so the+ * distinction has to be recorded here rather than inferred later from a clock.*/-function withDeadline(promise, ms, fallback) {+function withDeadline(promise, ms, fallback, onTimeout) {let timer = null;const timeout = new Promise((resolve) => {- timer = setTimeout(() => resolve(fallback), ms);+ timer = setTimeout(() => {+ if (onTimeout) onTimeout();+ resolve(fallback);+ }, ms);if (typeof timer.unref === 'function') timer.unref();});return Promise.race([Promise.resolve(promise).catch(() => fallback), timeout]).finally(() => {@@ -1187,7 +1199,7 @@ export async function collectFromUrl({screenshot,deadlineAt,});- return { target, ...obs, timedOut: obs.probeFailed || watchdog.firedAt !== null };+ return { target, ...obs, timedOut: obs.probeTimedOut || watchdog.firedAt !== null };} finally {watchdog.clear();await page.close().catch(() => {});@@ -1254,7 +1266,7 @@ export async function collectFromSnippet({screenshot,deadlineAt,});- return { target, ...obs, timedOut: obs.probeFailed || watchdog.firedAt !== null };+ return { target, ...obs, timedOut: obs.probeTimedOut || watchdog.firedAt !== null };} finally {watchdog.clear();await page.close().catch(() => {});diff --git a/tests/embed-doctor.test.js b/tests/embed-doctor.test.jsindex 2e3c38634..588af37be 100644--- a/tests/embed-doctor.test.js+++ b/tests/embed-doctor.test.js@@ -303,7 +303,7 @@ describe('analyze: the v1 loader element aliases', () => {describe('analyze: a page that could not be inspected', () => {it('reports inconclusive rather than inventing a missing element', () => {const report = analyze(- healthyObservations({ element: null, probeFailed: true, timedOut: true }),+ healthyObservations({ element: null, probeFailed: true, probeTimedOut: true }),);expect(report.verdict).toBe('inconclusive');expect(idsOf(report)).not.toContain('element_missing');@@ -316,7 +316,7 @@ describe('analyze: a page that could not be inspected', () => {it('distinguishes a closed page from an expired budget in the wording', () => {const report = analyze(- healthyObservations({ element: null, probeFailed: true, timedOut: false }),+ healthyObservations({ element: null, probeFailed: true, probeTimedOut: false }),);expect(byId(report, 'page_not_inspected').detail).toMatch(/closed the page/i);});