Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(test): diagnose transcript E2E stalls in CI
v_wyxgwangd2df6dfc8a4e
diff --git a/crates/host-core/src/config_sync/domains.rs b/crates/host-core/src/config_sync/domains.rsindex 7538bedad..2336e23d2 100644--- a/crates/host-core/src/config_sync/domains.rs+++ b/crates/host-core/src/config_sync/domains.rs@@ -632,7 +632,9 @@ mod tests {assert!(PORTABLE_APPLICATION_FIELDS.contains(&"thinkingDisplayMode"));let application = adapter_for(DOMAIN_APPLICATION).expect("application adapter");assert!(application.exportable_fields.contains(&"showThinking"));- assert!(application.exportable_fields.contains(&"thinkingDisplayMode"));+ assert!(application+ .exportable_fields+ .contains(&"thinkingDisplayMode"));for domain in ALL_DOMAINS {let adapter = adapter_for(domain).expect("portable domain adapter");assert_eq!(adapter.schema_version, 1);diff --git a/scripts/e2e-transcript-render.mjs b/scripts/e2e-transcript-render.mjsindex b3bb69577..29ece4099 100644--- a/scripts/e2e-transcript-render.mjs+++ b/scripts/e2e-transcript-render.mjs@@ -144,21 +144,84 @@ try {const { app, BrowserWindow } = require("electron");const path = require("node:path");app.setPath("userData", path.join(__dirname, "profile"));++// Each scenario runs as its own bounded phase so a stalled renderer names the+// phase that stalled instead of dying at the harness kill with no output.+const PHASE_TIMEOUT_MS = 90000;++function describe(error) {+ if (!error) return "unknown error";+ if (typeof error === "string") return error;+ return error.stack || error.message || String(error);+}+app.whenReady().then(async () => {const window = new BrowserWindow({ show: false, webPreferences: { sandbox: true, contextIsolation: true, nodeIntegration: false, backgroundThrottling: false } });- window.webContents.on("console-message", (event) => console.error(event.message));+ const report = (line) => process.stderr.write(line + "\\n");+ // stdout is a pipe; app.exit() would truncate a buffered write, so the probe+ // line is flushed first and only then does the process exit.+ const finish = (payload) => {+ process.stdout.write("TRANSCRIPT_RENDER_PROBE " + JSON.stringify(payload) + "\\n", () => app.exit(0));+ };+ // Renderer console forwarding has to survive both the legacy (event, level,+ // message) and the modern (event.message) signatures, or a renderer error is+ // silently lost and the harness only sees a timeout.+ window.webContents.on("console-message", (event, level, message) => {+ const text = typeof message === "string" && message.length > 0+ ? message+ : event && typeof event === "object" && typeof event.message === "string" ? event.message : "";+ if (text) report("TRANSCRIPT_E2E_RENDERER " + text);+ });+ window.webContents.on("render-process-gone", (_event, details) => report("TRANSCRIPT_E2E_RENDER_GONE " + JSON.stringify(details)));+ window.webContents.on("unresponsive", () => report("TRANSCRIPT_E2E_UNRESPONSIVE"));+ window.webContents.on("did-fail-load", (_event, code, description) => report("TRANSCRIPT_E2E_LOAD_FAILED " + code + " " + description));++ const withTimeout = (promise, label) => new Promise((resolve, reject) => {+ const timer = setTimeout(() => reject(new Error("phase " + label + " timed out after " + PHASE_TIMEOUT_MS + "ms")), PHASE_TIMEOUT_MS);+ promise.then((value) => { clearTimeout(timer); resolve(value); }, (error) => { clearTimeout(timer); reject(error); });+ });++ const phases = [+ ["render", "globalThis.transcriptRenderProbe()"],+ ["runtimeSlot", "globalThis.transcriptRuntimeSlotProbe()"],+ ["smoothText", "globalThis.smoothTextThrottleProbe()"],+ ["longHistory", "globalThis.transcriptLongHistoryProbe()"],+ ];+ const outcomes = { render: null, runtimeSlot: null, smoothText: null, longHistory: null };+ const phaseStatus = () => Object.fromEntries(Object.entries(outcomes).map(([name, value]) => [name, value ? value.ok === true : null]));+ const phaseErrors = () => Object.fromEntries(Object.entries(outcomes).filter(([, value]) => value && value.ok !== true).map(([name, value]) => [name, value.error]));++ const runPhase = async (name, expression) => {+ report("TRANSCRIPT_E2E_PHASE " + name + " start");+ const outcome = await withTimeout(window.webContents.executeJavaScript(+ "(async () => { try { return { ok: true, value: await (" + expression + ") }; } catch (error) { return { ok: false, error: (error && (error.stack || error.message)) || String(error) }; } })()"+ ), name);+ report("TRANSCRIPT_E2E_PHASE " + name + (outcome && outcome.ok === true ? " done" : " failed: " + JSON.stringify(outcome)));+ return outcome;+ };+try {await window.loadFile(path.join(__dirname, "index.html"));await window.webContents.executeJavaScript("window.addEventListener('error', event => console.error(event.error?.stack ?? event.message)); window.addEventListener('unhandledrejection', event => console.error(event.reason?.stack ?? String(event.reason)));");- const result = await window.webContents.executeJavaScript("(async () => { const render = await globalThis.transcriptRenderProbe(); const slot = await globalThis.transcriptRuntimeSlotProbe(); const smoothText = await globalThis.smoothTextThrottleProbe(); const longHistory = await globalThis.transcriptLongHistoryProbe(); return { ...render, runtimeSlot: slot, smoothText, longHistory, ok: render.ok && slot.ok && smoothText.ok && longHistory.ok }; })()");- const contextOverflowRecovery = await require(${JSON.stringify(join(root, "scripts/e2e/context-overflow-recovery.cjs"))})(window);- result.contextOverflowRecovery = contextOverflowRecovery;- result.ok = result.ok && contextOverflowRecovery.ok;- console.log("TRANSCRIPT_RENDER_PROBE " + JSON.stringify(result));- app.quit();+ for (const [name, expression] of phases) {+ outcomes[name] = await runPhase(name, expression);+ if (!outcomes[name] || outcomes[name].ok !== true) break;+ }+ const render = outcomes.render && outcomes.render.ok === true ? outcomes.render.value : {};+ const runtimeSlot = outcomes.runtimeSlot && outcomes.runtimeSlot.ok === true ? outcomes.runtimeSlot.value : undefined;+ const smoothText = outcomes.smoothText && outcomes.smoothText.ok === true ? outcomes.smoothText.value : undefined;+ const longHistory = outcomes.longHistory && outcomes.longHistory.ok === true ? outcomes.longHistory.value : undefined;+ let contextOverflowRecovery;+ if (render.ok === true && runtimeSlot?.ok === true && smoothText?.ok === true && longHistory?.ok === true) {+ contextOverflowRecovery = await require(${JSON.stringify(join(root, "scripts/e2e/context-overflow-recovery.cjs"))})(window);+ }+ finish({+ ...render, runtimeSlot, smoothText, longHistory, contextOverflowRecovery,+ phases: phaseStatus(), phaseErrors: phaseErrors(),+ ok: Boolean(render.ok && runtimeSlot?.ok && smoothText?.ok && longHistory?.ok && contextOverflowRecovery?.ok),+ });} catch (error) {- console.error("TRANSCRIPT_RENDER_PROBE " + JSON.stringify({ ok: false, error: error?.stack ?? String(error) }));- app.exit(1);+ finish({ ok: false, error: describe(error), phases: phaseStatus(), phaseErrors: phaseErrors() });}});`,@@ -174,7 +237,12 @@ app.whenReady().then(async () => {stream.on("data", (data) => {output += data;});- const timeout = setTimeout(() => child.kill("SIGKILL"), 45_000);+ // Each phase is bounded inside main.cjs (90s), so this cap only has to cover+ // four phases plus the recovery scenario.+ const timeout = setTimeout(() => {+ console.error("TRANSCRIPT_E2E_HARNESS_TIMEOUT");+ child.kill("SIGKILL");+ }, 240_000);let code;try {code = await new Promise((resolve, reject) => {@@ -184,17 +252,21 @@ app.whenReady().then(async () => {} finally {clearTimeout(timeout);}- const line = output- .split(/\r?\n/)- .find((line) => line.startsWith("TRANSCRIPT_RENDER_PROBE "));+ const lines = output.split(/\r?\n/);+ const line = lines.find((entry) => entry.startsWith("TRANSCRIPT_RENDER_PROBE "));+ const markers = lines.filter((entry) => entry.includes("TRANSCRIPT_E2E_"));assert(line,- `renderer returned no probe result (exit=${code}): ${output.slice(-2000)}`,+ `renderer returned no probe result (exit=${code}).\n${markers.slice(-40).join("\n")}\n${output.slice(-4000)}`,);const result = JSON.parse(line.slice("TRANSCRIPT_RENDER_PROBE ".length));console.log("TRANSCRIPT_RENDER_PROBE " + JSON.stringify(result));- assert.equal(code, 0, output.slice(-6000));- assert.equal(result.ok, true);+ assert.equal(code, 0, `${markers.slice(-40).join("\n")}\n${output.slice(-6000)}`);+ assert.equal(+ result.ok,+ true,+ `transcript scenario failed; phases=${JSON.stringify(result.phases)} phaseErrors=${JSON.stringify(result.phaseErrors)}`,+ );// The merged result above already carries the geometry snapshots; this turns// a failed scenario into a message that names the checks that failed.// check can be read from the scenario output alone.diff --git a/scripts/e2e/transcript-long-history.tsx b/scripts/e2e/transcript-long-history.tsxindex 0a5d6d74d..df557c765 100644--- a/scripts/e2e/transcript-long-history.tsx+++ b/scripts/e2e/transcript-long-history.tsx@@ -14,13 +14,24 @@ const createdAt = "2026-09-01T00:00:00.000Z";function assert(value: unknown, label: string): asserts value {if (!value) throw new Error(`Long history: ${label}`);}-const frame = () => new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));+// A hidden CI window can starve rAF; race it with a timer so every bounded wait+// advances and a real stall reports its predicate instead of hanging until the+// harness phase cap.+const frame = () => new Promise<void>((resolve) => {+ let settled = false;+ const finish = () => { if (!settled) { settled = true; resolve(); } };+ requestAnimationFrame(finish);+ window.setTimeout(finish, 50);+});async function until(predicate: () => boolean, label: string, diagnostic?: () => unknown) {- for (let attempt = 0; attempt < 180; attempt++) {+ const deadline = performance.now() + 60_000;+ for (;;) {if (predicate()) return;+ if (performance.now() >= deadline) {+ throw new Error(`Long history did not settle: ${label}${diagnostic ? ` ${JSON.stringify(diagnostic())}` : ""}`);+ }await frame();}- throw new Error(`Long history did not settle: ${label}${diagnostic ? ` ${JSON.stringify(diagnostic())}` : ""}`);}type FixtureSession = { summary: SessionSummary; messages: UiMessage[]; reads: { count: number }; tail: string };