From 4bb837c960295478224e9879fcd94ac0a09db5ab Mon Sep 17 00:00:00 2001 From: David Brailovsky Date: Wed, 4 Nov 2026 23:15:05 +0100 Subject: [PATCH] fix(p2): name the TUI bundle with a sourceURL so stack traces stay small The sandbox imports the bundle from a data: URL, which put the whole base64 bundle (~1.4 MB) into every stack frame. Chord formats a released reference's error stack, so /agents -> subagent and /clone exhausted the worker's 96 MB heap. --- apps/p2/src/hosts/tui-bootstrap.mjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/p2/src/hosts/tui-bootstrap.mjs b/apps/p2/src/hosts/tui-bootstrap.mjs index 89361feb1..98e3c46cc 100644 --- a/apps/p2/src/hosts/tui-bootstrap.mjs +++ b/apps/p2/src/hosts/tui-bootstrap.mjs @@ -65,7 +65,11 @@ port.on("message", async (message) => { } }); // Owner-approved dynamic import: the single self-contained server bundle is evaluated only from memory. -const bundle = await import(`data:text/javascript;base64,${Buffer.from(source).toString("base64")}`); +// The sourceURL names its frames: a data: URL would put the whole base64 bundle (megabytes) into every stack frame, +// and formatting one stack (Chord makes a released reference's error stack text at once) exhausts the worker heap. +const bundle = await import( + `data:text/javascript;base64,${Buffer.from(`${source}\n//# sourceURL=p2-tui-bundle.mjs\n`).toString("base64")}` +); await bundle.default({ input, send,